/// <summary> /// When a request is made to create a Post the provided body text is processed for entities. You can use this endpoint to test how App.net will parse text for entities as well as render text as html. /// Calls to this endpoint will not create or update any objects in App.net /// </summary> /// <param name="access_token"></param> /// <param name="text"></param> /// <returns></returns> public static Tuple<Post, ApiCallResponse> process(string access_token, string text) { 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/text/process"; Dictionary<string, string> headers = new Dictionary<string, string>(); headers.Add("Authorization", "Bearer " + access_token); Helper.Response response = Helper.SendPostRequestStringDataOnly( requestUrl, "text=" + System.Web.HttpUtility.UrlEncode(text), headers, true); 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); }
/// <summary> /// Report a post as spam. This will mute the author of the post and send a report to App.net. /// </summary> /// <param name="access_token">the user access token</param> /// <param name="id">the id of the post to be reported</param> /// <returns></returns> public static Tuple<Post, ApiCallResponse> report(string access_token, string id) { 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(id)) { apiCallResponse.success = false; apiCallResponse.errorMessage = "Missing parameter id"; return new Tuple<Post, ApiCallResponse>(post, apiCallResponse); } string requestUrl = Common.baseUrl + string.Format("/stream/0/posts/{0}/report",id); Dictionary<string, string> headers = new Dictionary<string, string>(); headers.Add("Authorization", "Bearer " + access_token); Helper.Response response = Helper.SendPostRequest( requestUrl, new Dictionary<string,string>(), headers); 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); }