/// <summary> /// Reports someone /// </summary> /// <param name="reportType">What you're reporting them for <see cref="ReportType"/></param> /// <param name="otherReason">If your reason is "Other", say why you're reporting them</param> /// <param name="agent"><see cref="IWebAgent"/> used to send post</param> /// <param name="fullname">FullName of thing to act on. eg. t1_66666</param> public static Task ReportAsync(IWebAgent agent, string fullname, ReportType reportType, string otherReason = null) { string reportReason; switch (reportType) { case ReportType.Spam: reportReason = "spam"; break; case ReportType.VoteManipulation: reportReason = "vote manipulation"; break; case ReportType.PersonalInformation: reportReason = "personal information"; break; case ReportType.BreakingReddit: reportReason = "breaking reddit"; break; case ReportType.SexualizingMinors: reportReason = "sexualizing minors"; break; default: reportReason = "other"; break; } return(agent.Post(ReportUrl, new { api_type = "json", reason = reportReason, other_reason = otherReason ?? "", thing_id = fullname })); }
/// <summary> /// Post a reply to a specific comment /// </summary> /// <param name="webAgent"></param> /// <param name="commentFullName">e.g. "t1_12345"</param> /// <param name="message"></param> /// <returns></returns> public static async Task Reply(IWebAgent webAgent, string commentFullName, string message) { // TODO actual error handling. This just hides the error and returns null //try //{ var json = await webAgent.Post(CommentUrl, new { text = message, thing_id = commentFullName, api_type = "json" //r = Subreddit }).ConfigureAwait(false); if (json["json"]["ratelimit"] != null) { throw new RateLimitException(TimeSpan.FromSeconds(json["json"]["ratelimit"].ValueOrDefault <double>())); } //} //catch (HttpRequestException ex) //{ // var error = new StreamReader(ex..GetResponseStream()).ReadToEnd(); // return null; //} }
/// <summary> /// Execute a simple POST request against the reddit api. /// Supports endpoints that require only id as parameter. /// </summary> /// <param name="agent"><see cref="IWebAgent"/> used to execute post</param> /// <param name="fullname">FullName of thing to act on. eg. t1_66666</param> /// <param name="endpoint">URL to post to</param> /// <returns></returns> protected static Task <JToken> SimpleActionAsync(IWebAgent agent, string fullname, string endpoint) { return(agent.Post(endpoint, new { id = fullname })); }
/// <summary> /// Spams the <see cref="Thing"/> /// </summary> /// <param name="agent"><see cref="IWebAgent"/> used to send post</param> /// <param name="fullname">FullName of thing to act on. eg. t1_66666</param> /// <returns></returns> public static Task SpamAsync(IWebAgent agent, string fullname) { return(agent.Post(RemoveUrl, new { id = fullname, spam = true })); }
/// <summary> /// Sets flair of given post by <paramref name="fullname"/> /// </summary> /// <param name="agent"><see cref="IWebAgent"/> used to send post</param> /// <param name="fullname">FullName of thing to act on. eg. t1_66666</param> /// <param name="subreddit">Subreddit name of post</param> /// <param name="flairText">Text of flair to set</param> /// <param name="flairClass">Css class name of flair to set</param> /// <returns></returns> public static Task SetFlairAsync(IWebAgent agent, string subreddit, string fullname, string flairText, string flairClass) { //TODO unit test return(agent.Post(string.Format(SetFlairUrl, subreddit), new { api_type = "json", css_class = flairClass, link = fullname, text = flairText })); }