private void buttonSendPost_Click(object sender, RoutedEventArgs e) { if (!string.IsNullOrEmpty(autoCompeteTextbox_post.textBoxContent.Text)) { AccountAppDotNet account = comboBoxAccount.comboBoxAccounts.SelectedItem as AccountAppDotNet; if (account != null) { AppNetDotNet.Model.Entities entities = null; string toBePostedText = autoCompeteTextbox_post.textBoxContent.Text; if (autoCompeteTextbox_post.MarkdownLinksInText.Count() > 0) { entities = new AppNetDotNet.Model.Entities(); entities.links = new List <AppNetDotNet.Model.Entities.Link>(); entities.hashtags = null; entities.mentions = null; foreach (KeyValuePair <string, string> link in autoCompeteTextbox_post.MarkdownLinksInText) { AppNetDotNet.Model.Entities.Link linkEntity = new AppNetDotNet.Model.Entities.Link(); linkEntity.text = link.Value; linkEntity.url = link.Key; int startPosition = toBePostedText.IndexOf(string.Format("[{0}]({1})", linkEntity.text, linkEntity.url)); linkEntity.pos = startPosition; linkEntity.len = linkEntity.text.Length; toBePostedText = toBePostedText.Replace(string.Format("[{0}]({1})", linkEntity.text, linkEntity.url), linkEntity.text); entities.links.Add(linkEntity); } } List <AppNetDotNet.Model.File> toBeAddedFiles = null; if (!string.IsNullOrEmpty(path_to_be_uploaded_image)) { if (System.IO.File.Exists(path_to_be_uploaded_image)) { Tuple <AppNetDotNet.Model.File, ApiCallResponse> uploadedFile = AppNetDotNet.ApiCalls.Files.create(account.accessToken, local_file_path: path_to_be_uploaded_image, type: "de.li-ghun.nymphicus.image"); if (uploadedFile.Item2.success) { toBeAddedFiles = new List <File>(); toBeAddedFiles.Add(uploadedFile.Item1); } } } Tuple <Post, ApiCallResponse> response; if (inReplyToId == 0) { response = Posts.create(account.accessToken, toBePostedText, entities: entities, parse_links: true, toBeEmbeddedFiles: toBeAddedFiles); } else { response = Posts.create(account.accessToken, toBePostedText, inReplyToId.ToString(), entities: entities, parse_links: true, toBeEmbeddedFiles: toBeAddedFiles); } if (response.Item2.success) { Close(); } } } }
public bool send_post(string text, string local_file_to_embed = "", Entities entities = null) { if (!string.IsNullOrEmpty(text)) { List<AppNetDotNet.Model.File> toBeAddedFiles = null; if (!string.IsNullOrEmpty(local_file_to_embed)) { if (System.IO.File.Exists(local_file_to_embed)) { Tuple<AppNetDotNet.Model.File, ApiCallResponse> uploadedFile = AppNetDotNet.ApiCalls.Files.create(this.access_token, local_file_path:local_file_to_embed, type: "de.li-ghun.spinnaker.image"); if (uploadedFile.Item2.success) { toBeAddedFiles = new List<File>(); toBeAddedFiles.Add(uploadedFile.Item1); } } } Tuple<Post,ApiCallResponse> response = Posts.create(this.access_token, text, toBeEmbeddedFiles:toBeAddedFiles, entities:entities, parse_links:true); return response.Item2.success; } return false; }
public EntitiesWithoutAllProperty(Entities entities) { mentions = null; hashtags = null; links = null; if (entities != null) { if (entities.mentions != null) { if (entities.mentions.Count > 0) { mentions = entities.mentions; } } if (entities.hashtags != null) { if (entities.hashtags.Count > 0) { hashtags = entities.hashtags; } } if (entities.links != null) { if (entities.hashtags.Count > 0) { links = entities.links; } } } }
public static Tuple<Post,ApiCallResponse> create(string access_token, string text, string reply_to = null, List<File> toBeEmbeddedFiles = null, List<Annotation> annotations = null, Entities entities = null, int machine_only = 0) { ApiCallResponse apiCallResponse = new ApiCallResponse(); Post post = new Post(); try { if (string.IsNullOrEmpty(access_token)) { apiCallResponse.success = false; apiCallResponse.errorMessage = "Missing parameter access_token"; return new Tuple<Post, ApiCallResponse>(post, apiCallResponse); } if (string.IsNullOrEmpty(text)) { apiCallResponse.success = false; apiCallResponse.errorMessage = "Missing parameter text"; return new Tuple<Post, ApiCallResponse>(post, apiCallResponse); } string requestUrl = Common.baseUrl + "/stream/0/posts"; Dictionary<string, string> headers = new Dictionary<string, string>(); headers.Add("Authorization", "Bearer " + access_token); postCreateParameters postCreateContent = new postCreateParameters(); postCreateContent.text = text; postCreateContent.reply_to = reply_to; postCreateContent.machine_only = machine_only; postCreateContent.entities = new EntitiesWithoutAllProperty(entities); //postCreateContent.annotations = annotations; if (toBeEmbeddedFiles != null) { if (postCreateContent.annotations == null) { postCreateContent.annotations = new List<AppNetDotNet.Model.Annotations.AnnotationReplacement_File>(); } foreach (File file in toBeEmbeddedFiles) { AppNetDotNet.Model.Annotations.AnnotationReplacement_File fileReplacementAnnotation = new AppNetDotNet.Model.Annotations.AnnotationReplacement_File(file); postCreateContent.annotations.Add(fileReplacementAnnotation); } } JsonSerializerSettings settings = new JsonSerializerSettings(); settings.NullValueHandling = NullValueHandling.Ignore; string jsonString = JsonConvert.SerializeObject(postCreateContent, Formatting.None, settings); jsonString = jsonString.Replace("netAppCoreFile_dummy_for_replacement", "+net.app.core.file"); Helper.Response response; response = Helper.SendPostRequestStringDataOnly( requestUrl, jsonString, headers, true, contentType: "application/json"); return Helper.getData<Post>(response); } catch (Exception exp) { apiCallResponse.success = false; apiCallResponse.errorMessage = exp.Message; apiCallResponse.errorDescription = exp.StackTrace; } return new Tuple<Post, ApiCallResponse>(post, apiCallResponse); }
private void button_sendPost_Click_1(object sender, RoutedEventArgs e) { if (!string.IsNullOrEmpty(textbox_postText.Text)) { AppNetDotNet.Model.Entities entities = null; string toBePostedText = textbox_postText.textBoxContent.Text; if (textbox_postText.MarkdownLinksInText.Count() > 0) { entities = new AppNetDotNet.Model.Entities(); entities.links = new List <AppNetDotNet.Model.Entities.Link>(); entities.hashtags = null; entities.mentions = null; foreach (KeyValuePair <string, string> link in textbox_postText.MarkdownLinksInText) { AppNetDotNet.Model.Entities.Link linkEntity = new AppNetDotNet.Model.Entities.Link(); linkEntity.text = link.Value; linkEntity.url = link.Key; int startPosition = toBePostedText.IndexOf(string.Format("[{0}]({1})", linkEntity.text, linkEntity.url)); linkEntity.pos = startPosition; linkEntity.len = linkEntity.text.Length; toBePostedText = toBePostedText.Replace(string.Format("[{0}]({1})", linkEntity.text, linkEntity.url), linkEntity.text); entities.links.Add(linkEntity); } } //List<IAnnotation> annotations = null; if (!string.IsNullOrEmpty(Properties.Settings.Default.language_posts)) { /* annotations = new List<IAnnotation>(); * AppNetDotNet.Model.Annotations.Language language_annotation = new AppNetDotNet.Model.Annotations.Language(); * language_annotation.language = Properties.Settings.Default.language_posts; * annotations.Add(language_annotation); */ } if (currentPostTarget.pmToUser == null && currentPostTarget.channelName == null) { List <File> toBeAddedFiles = null; if (!string.IsNullOrEmpty(currentPostTarget.filePathOfToBeAddedFile)) { if (System.IO.File.Exists(currentPostTarget.filePathOfToBeAddedFile)) { Tuple <File, ApiCallResponse> uploadedFile = AppNetDotNet.ApiCalls.Files.create(AppController.Current.account.accessToken, currentPostTarget.filePathOfToBeAddedFile, type: "com.nymphicusapp.chapper.image"); if (uploadedFile.Item2.success) { toBeAddedFiles = new List <File>(); toBeAddedFiles.Add(uploadedFile.Item1); } } } Tuple <Post, ApiCallResponse> response; if (currentPostTarget.replyToItem != null) { if (currentPostTarget.replyToItem.apnPost == null) { currentPostTarget.replyToItem = null; } } if (currentPostTarget.replyToItem == null) { response = Posts.create(AppController.Current.account.accessToken, toBePostedText, toBeEmbeddedFiles: toBeAddedFiles, entities: entities, parse_links: true); } else { response = Posts.create(AppController.Current.account.accessToken, toBePostedText, currentPostTarget.replyToItem.id, toBeEmbeddedFiles: toBeAddedFiles, entities: entities, parse_links: true); } if (response.Item2.success) { AppController.Current.account.updateItems(); clear_postbox(); if (string.IsNullOrEmpty(currentPostTarget.channelName)) { textblock_composeOverlay.Text = ""; } } else { showErrorMessage(response.Item2); } } else { Tuple <Message, ApiCallResponse> response; List <string> receiver = new List <string>(); if (currentPostTarget.pmToUser != null) { receiver.Add("@" + currentPostTarget.pmToUser.username); } if (receiver.Count == 0 && currentPostTarget.replyToItem != null) { receiver.Add("@" + currentPostTarget.replyToItem.user.username); } if (currentPostTarget.replyToItem != null) { if (currentPostTarget.replyToItem.apnMessage == null) { currentPostTarget.replyToItem = null; } } if (currentPostTarget.replyToItem != null) { if (currentPostTarget.replyToItem.isPrivateMessage) { response = Messages.createPrivateMessage(AppController.Current.account.accessToken, toBePostedText, receiver, currentPostTarget.replyToItem.id, machineOnly: 0, entities: entities, parse_links: true); } else if (currentPostTarget.replyToItem.apnMessage != null) { { response = Messages.create(AppController.Current.account.accessToken, toBePostedText, currentPostTarget.replyToItem.apnMessage.channel_id, receiver, machineOnly: 0, reply_to: currentPostTarget.replyToItem.id, entities: entities, parse_links: true); } } else { response = Messages.createPrivateMessage(AppController.Current.account.accessToken, toBePostedText, receiver, currentPostTarget.replyToItem.id, machineOnly: 0, entities: entities, parse_links: true); } } else { if (currentPostTarget.channelId != null) { string channelId = currentPostTarget.channelId; response = Messages.create(AppController.Current.account.accessToken, textbox_postText.Text, channelId, receiver, machineOnly: 0, parse_links: true); } else { response = Messages.createPrivateMessage(AppController.Current.account.accessToken, textbox_postText.Text, receiver, machineOnly: 0, parse_links: true); } } if (response.Item2.success) { clear_postbox(); } else { showErrorMessage(response.Item2); } } } }
public static Tuple<Message, ApiCallResponse> create(string access_token, string text, string channelId, List<string> receipientUsersnameOrIds, string reply_to = null, List<Annotation> annotations = null, Entities entities = null, int machineOnly = 0) { ApiCallResponse apiCallResponse = new ApiCallResponse(); Message message = new Message(); try { if (string.IsNullOrEmpty(access_token)) { apiCallResponse.success = false; apiCallResponse.errorMessage = "Missing parameter access_token"; return new Tuple<Message, ApiCallResponse>(message, apiCallResponse); } if (string.IsNullOrEmpty(text)) { apiCallResponse.success = false; apiCallResponse.errorMessage = "Missing parameter text"; return new Tuple<Message, ApiCallResponse>(message, apiCallResponse); } if (channelId.ToLower() == "pm" && receipientUsersnameOrIds == null) { apiCallResponse.success = false; apiCallResponse.errorMessage = "Missing parameter destinations for PM"; return new Tuple<Message, ApiCallResponse>(message, apiCallResponse); } string requestUrl = Common.baseUrl; if (channelId.ToLower() == "pm") { requestUrl += "/stream/0/channels/pm/messages"; } else { requestUrl += "/stream/0/channels/" + channelId + "/messages"; } messageCreateParameters messageContent = new messageCreateParameters(); messageContent.text = text; messageContent.reply_to = reply_to; //messageContent.annotations = annotations; messageContent.entities = entities; messageContent.machine_only = machineOnly; messageContent.destinations = receipientUsersnameOrIds; JsonSerializerSettings settings = new JsonSerializerSettings(); settings.NullValueHandling = NullValueHandling.Ignore; string jsonString = JsonConvert.SerializeObject(messageContent, Formatting.None, settings); Dictionary<string, string> headers = new Dictionary<string, string>(); headers.Add("Authorization", "Bearer " + access_token); Helper.Response response = Helper.SendPostRequestStringDataOnly( requestUrl, jsonString, headers, true, contentType:"application/json"); return Helper.getData<Message>(response); } catch (Exception exp) { apiCallResponse.success = false; apiCallResponse.errorMessage = exp.Message; apiCallResponse.errorDescription = exp.StackTrace; } return new Tuple<Message, ApiCallResponse>(message, apiCallResponse); }
public static Tuple<Message, ApiCallResponse> createPrivateMessage(string access_token, string text, List<string> receipientUsersnameOrIds, string reply_to = null, List<Annotation> annotations = null, Entities entities = null, int machineOnly = 0) { return create(access_token, text, "pm", receipientUsersnameOrIds, reply_to, annotations, entities, machineOnly); }