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, bool?parse_links = null) { 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 + "/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.entities = new EntitiesWithoutAllProperty(entities); //postCreateContent.annotations = annotations; /*if (postCreateContent.entities != null) * { * postCreateContent.entities.parse_links = parse_links; * }*/ 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)); }
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); }