public WritePostBody ( Stream stream, object data ) : void | ||
stream | Stream | |
data | object | |
return | void |
public void ClearFlairTemplates(FlairType flairType) { var request = WebAgent.CreatePost(ClearFlairTemplatesUrl); var stream = request.GetRequestStream(); WebAgent.WritePostBody(stream, new { flair_type = flairType == FlairType.Link ? "LINK_FLAIR" : "USER_FLAIR", uh = Reddit.User.Modhash, r = Name }); stream.Close(); var response = request.GetResponse(); var data = WebAgent.GetResponseString(response.GetResponseStream()); }
public void RemoveContributor(string id) { var request = WebAgent.CreatePost(LeaveModerationUrl); WebAgent.WritePostBody(request.GetRequestStream(), new { api_type = "json", uh = Reddit.User.Modhash, r = Name, type = "contributor", id }); var response = request.GetResponse(); var result = WebAgent.GetResponseString(response.GetResponseStream()); }
public void AddContributor(string user) { var request = WebAgent.CreatePost(AddContributorUrl); WebAgent.WritePostBody(request.GetRequestStream(), new { api_type = "json", uh = Reddit.User.Modhash, r = Name, type = "contributor", name = user }); var response = request.GetResponse(); var result = WebAgent.GetResponseString(response.GetResponseStream()); }
public void UpdateCss() { var request = WebAgent.CreatePost(UpdateCssUrl); var stream = request.GetRequestStream(); WebAgent.WritePostBody(stream, new { op = "save", stylesheet_contents = CSS, uh = Reddit.User.Modhash, api_type = "json", r = Subreddit.Name }); stream.Close(); WebAgent.ExecuteRequest(request); }
public void SetUserFlair(string user, string cssClass, string text) { var request = WebAgent.CreatePost(SetUserFlairUrl); var stream = request.GetRequestStream(); WebAgent.WritePostBody(stream, new { css_class = cssClass, text = text, uh = Reddit.User.Modhash, r = Name, name = user }); stream.Close(); WebAgent.ExecuteRequest(request); }
public void Save() { var request = WebAgent.CreatePost(SaveUrl); var stream = request.GetRequestStream(); WebAgent.WritePostBody(stream, new { id = FullName, uh = Reddit.User.Modhash }); stream.Close(); var response = request.GetResponse(); var data = WebAgent.GetResponseString(response.GetResponseStream()); Saved = true; }
public void Vote(VoteType type) { var request = WebAgent.CreatePost(VoteUrl); var stream = request.GetRequestStream(); WebAgent.WritePostBody(stream, new { dir = (int)type, id = FullName, uh = Reddit.User.Modhash }); stream.Close(); var response = request.GetResponse(); var data = WebAgent.GetResponseString(response.GetResponseStream()); Liked = null; }
public void Unhide() { if (Reddit.User == null) { throw new AuthenticationException("No user logged in."); } var request = WebAgent.CreatePost(UnhideUrl); var stream = request.GetRequestStream(); WebAgent.WritePostBody(stream, new { id = FullName, uh = Reddit.User.Modhash }); stream.Close(); WebAgent.ExecuteRequest(request); }
public void Delete() { var request = WebAgent.CreatePost(DeleteImageUrl); var stream = request.GetRequestStream(); WebAgent.WritePostBody(stream, new { img_name = Name, uh = Reddit.User.Modhash, r = SubredditStyle.Subreddit.Name }); stream.Close(); var response = request.GetResponse(); var data = WebAgent.GetResponseString(response.GetResponseStream()); SubredditStyle.Images.Remove(this); }
public void Downvote() { var request = WebAgent.CreatePost(VoteUrl); var stream = request.GetRequestStream(); WebAgent.WritePostBody(stream, new { dir = -1, id = FullName, uh = Reddit.User.Modhash }); stream.Close(); var response = request.GetResponse(); var data = WebAgent.GetResponseString(response.GetResponseStream()); Liked = false; }
public void UpdateCss() { var request = WebAgent.CreatePost(UpdateCssUrl); var stream = request.GetRequestStream(); WebAgent.WritePostBody(stream, new { op = "save", stylesheet_contents = CSS, uh = Reddit.User.Modhash, api_type = "json", r = Subreddit.Name }); stream.Close(); var response = request.GetResponse(); var data = WebAgent.GetResponseString(response.GetResponseStream()); var json = JToken.Parse(data); }
public void Hide() { if (Reddit.User == null) { throw new AuthenticationException("No user logged in."); } var request = WebAgent.CreatePost(HideUrl); var stream = request.GetRequestStream(); WebAgent.WritePostBody(stream, new { id = FullName, uh = Reddit.User.Modhash }); stream.Close(); var response = request.GetResponse(); var data = WebAgent.GetResponseString(response.GetResponseStream()); }
public void Reply(string message) { if (Reddit.User == null) { throw new AuthenticationException("No user logged in."); } var request = WebAgent.CreatePost(CommentUrl); var stream = request.GetRequestStream(); WebAgent.WritePostBody(stream, new { text = message, thing_id = FullName, uh = Reddit.User.Modhash }); stream.Close(); WebAgent.ExecuteRequest(request); }
public void BanUser(string user, string reason) { var request = WebAgent.CreatePost(BanUserUrl); WebAgent.WritePostBody(request.GetRequestStream(), new { api_type = "json", uh = Reddit.User.Modhash, r = Name, type = "banned", id = "#banned", name = user, note = reason, action = "add", container = FullName }); WebAgent.ExecuteRequest(request); }
public void AddFlairTemplate(string cssClass, FlairType flairType, string text, bool userEditable) { var request = WebAgent.CreatePost(FlairTemplateUrl); var stream = request.GetRequestStream(); WebAgent.WritePostBody(stream, new { css_class = cssClass, flair_type = flairType == FlairType.Link ? "LINK_FLAIR" : "USER_FLAIR", text = text, text_editable = userEditable, uh = Reddit.User.Modhash, r = Name, api_type = "json" }); stream.Close(); var json = WebAgent.ExecuteRequest(request); }
public void Distinguish(DistinguishType distinguishType) { if (Reddit.User == null) { throw new AuthenticationException("No user logged in."); } var request = WebAgent.CreatePost(DistinguishUrl); var stream = request.GetRequestStream(); string how; switch (distinguishType) { case DistinguishType.Admin: how = "admin"; break; case DistinguishType.Moderator: how = "yes"; break; case DistinguishType.None: how = "no"; break; default: how = "special"; break; } WebAgent.WritePostBody(stream, new { how, id = Id, uh = Reddit.User.Modhash }); stream.Close(); var response = request.GetResponse(); var data = WebAgent.GetResponseString(response.GetResponseStream()); var json = JObject.Parse(data); if (json["jquery"].Count(i => i[0].Value <int>() == 11 && i[1].Value <int>() == 12) == 0) { throw new AuthenticationException("You are not permitted to distinguish this comment."); } }
/// <summary> /// Registers a new Reddit user /// </summary> /// <param name="userName">The username for the new account.</param> /// <param name="passwd">The password for the new account.</param> /// <param name="email">The optional recovery email for the new account.</param> /// <returns>The newly created user account</returns> public AuthenticatedUser RegisterAccount(string userName, string passwd, string email = "") { var request = WebAgent.CreatePost(RegisterAccountUrl); WebAgent.WritePostBody(request.GetRequestStream(), new { api_type = "json", email = email, passwd = passwd, passwd2 = passwd, user = userName }); var response = request.GetResponse(); var result = WebAgent.GetResponseString(response.GetResponseStream()); var json = JObject.Parse(result); return(new AuthenticatedUser().Init(this, json, WebAgent)); // TODO: Error }
public void Unsubscribe() { if (Reddit.User == null) { throw new AuthenticationException("No user logged in."); } var request = WebAgent.CreatePost(SubscribeUrl); var stream = request.GetRequestStream(); WebAgent.WritePostBody(stream, new { action = "unsub", sr = FullName, uh = Reddit.User.Modhash }); stream.Close(); WebAgent.ExecuteRequest(request); // Discard results }
private Post Submit(SubmitData data) { if (Reddit.User == null) { throw new RedditException("No user logged in."); } var request = WebAgent.CreatePost(SubmitLinkUrl); WebAgent.WritePostBody(request.GetRequestStream(), data); var response = request.GetResponse(); var result = WebAgent.GetResponseString(response.GetResponseStream()); var json = JToken.Parse(result); ICaptchaSolver solver = Reddit.CaptchaSolver; if (json["json"]["errors"].Any() && json["json"]["errors"][0][0].ToString() == "BAD_CAPTCHA" && solver != null) { data.Iden = json["json"]["captcha"].ToString(); CaptchaResponse captchaResponse = solver.HandleCaptcha(new Captcha(data.Iden)); // We throw exception due to this method being expected to return a valid Post object, but we cannot // if we got a Captcha error. if (captchaResponse.Cancel) { throw new CaptchaFailedException("Captcha verification failed when submitting " + data.Kind + " post"); } data.Captcha = captchaResponse.Answer; return(Submit(data)); } else if (json["json"]["errors"].Any() && json["json"]["errors"][0][0].ToString() == "ALREADY_SUB") { throw new DuplicateLinkException(String.Format("Post failed when submitting. The following link has already been submitted: {0}", SubmitLinkUrl)); } return(new Post(Reddit, json["json"], WebAgent)); }
public void SetFlair(string flairText, string flairClass) { if (Reddit.User == null) { throw new Exception("No user logged in."); } var request = WebAgent.CreatePost(SetFlairUrl); WebAgent.WritePostBody(request.GetRequestStream(), new { api_type = "json", r = Subreddit, css_class = flairClass, link = FullName, //name = Name, text = flairText, uh = Reddit.User.Modhash }); WebAgent.ExecuteRequest(request); LinkFlairText = flairText; }
public void SetVote(VoteType type) { if (this.Vote == type) { return; } var request = WebAgent.CreatePost(VoteUrl); var stream = request.GetRequestStream(); WebAgent.WritePostBody(stream, new { dir = (int)type, id = FullName, uh = Reddit.User.Modhash }); stream.Close(); var response = request.GetResponse(); var data = WebAgent.GetResponseString(response.GetResponseStream()); if (Liked == true) { Upvotes--; } if (Liked == false) { Downvotes--; } switch (type) { case VoteType.Upvote: Liked = true; Upvotes++; return; case VoteType.None: Liked = null; return; case VoteType.Downvote: Liked = false; Downvotes++; return; } }
public Comment Comment(string message) { if (Reddit.User == null) { throw new AuthenticationException("No user logged in."); } var request = WebAgent.CreatePost(CommentUrl); var stream = request.GetRequestStream(); WebAgent.WritePostBody(stream, new { text = message, thing_id = FullName, uh = Reddit.User.Modhash }); stream.Close(); var response = request.GetResponse(); var data = WebAgent.GetResponseString(response.GetResponseStream()); var json = JObject.Parse(data); var comment = json["jquery"].FirstOrDefault(i => i[0].Value <int>() == 18 && i[1].Value <int>() == 19); return(new Comment(Reddit, comment[3][0][0], WebAgent)); }
public void ComposePrivateMessage(string subject, string body, string to, string captchaId = "", string captchaAnswer = "") { if (User == null) { throw new Exception("User can not be null."); } var request = WebAgent.CreatePost(ComposeMessageUrl); request.InitWebReqProxy(); WebAgent.WritePostBody(request.GetRequestStream(), new { api_type = "json", subject, text = body, to, uh = User.Modhash, iden = captchaId, captcha = captchaAnswer }); var response = request.GetResponse(); var result = WebAgent.GetResponseString(response.GetResponseStream()); var json = JObject.Parse(result); ICaptchaSolver solver = CaptchaSolver; // Prevent race condition if (json["json"]["errors"].Any() && json["json"]["errors"][0][0].ToString() == "BAD_CAPTCHA" && solver != null) { captchaId = json["json"]["captcha"].ToString(); CaptchaResponse captchaResponse = solver.HandleCaptcha(new Captcha(captchaId)); if (!captchaResponse.Cancel) // Keep trying until we are told to cancel { ComposePrivateMessage(subject, body, to, captchaId, captchaResponse.Answer); } } }
public void EditPage(string page, string content, string previous = null, string reason = null) { var request = WebAgent.CreatePost(string.Format(WikiPageEditUrl, Subreddit.Name)); dynamic param = new { content = content, page = page, uh = Reddit.User.Modhash }; List <string> addParams = new List <string>(); if (previous != null) { addParams.Add("previous"); addParams.Add(previous); } if (reason != null) { addParams.Add("reason"); addParams.Add(reason); } WebAgent.WritePostBody(request.GetRequestStream(), param, addParams.ToArray()); var response = request.GetResponse(); }
/// <summary> /// Submits a text post in the current subreddit using the logged-in user /// </summary> /// <param name="title">The title of the submission</param> /// <param name="text">The raw markdown text of the submission</param> public Post SubmitTextPost(string title, string text) { if (Reddit.User == null) { throw new Exception("No user logged in."); } var request = WebAgent.CreatePost(SubmitLinkUrl); WebAgent.WritePostBody(request.GetRequestStream(), new { api_type = "json", kind = "self", sr = Name, text = text, title = title, uh = Reddit.User.Modhash }); var response = request.GetResponse(); var result = WebAgent.GetResponseString(response.GetResponseStream()); var json = JToken.Parse(result); return(new Post(Reddit, json["json"], WebAgent)); // TODO: Error }
/// <summary> /// Update the subreddit settings. /// </summary> public void UpdateSettings() { var request = WebAgent.CreatePost(SiteAdminUrl); var stream = request.GetRequestStream(); string link_type; string type; string wikimode; switch (ContentOptions) { case ContentOptions.All: link_type = "any"; break; case ContentOptions.LinkOnly: link_type = "link"; break; default: link_type = "self"; break; } switch (SubredditType) { case SubredditType.Public: type = "public"; break; case SubredditType.Private: type = "private"; break; default: type = "restricted"; break; } switch (WikiEditMode) { case WikiEditMode.All: wikimode = "anyone"; break; case WikiEditMode.Moderators: wikimode = "modonly"; break; default: wikimode = "disabled"; break; } WebAgent.WritePostBody(stream, new { allow_top = AllowAsDefault, allow_images = AllowImages, description = Sidebar, domain = Domain, lang = Language, link_type, over_18 = NSFW, public_description = PublicDescription, show_media = ShowThumbnails, sr = Subreddit.FullName, title = Title, type, uh = Reddit.User.Modhash, wiki_edit_age = WikiEditAge, wiki_edit_karma = WikiEditKarma, wikimode, spam_links = SpamFilter?.LinkPostStrength.ToString().ToLowerInvariant(), spam_selfposts = SpamFilter?.SelfPostStrength.ToString().ToLowerInvariant(), spam_comments = SpamFilter?.CommentStrength.ToString().ToLowerInvariant(), api_type = "json" }, "header-title", HeaderHoverText); stream.Close(); var response = request.GetResponse(); var data = WebAgent.GetResponseString(response.GetResponseStream()); }
public void UpdateSettings() { var request = WebAgent.CreatePost(SiteAdminUrl); var stream = request.GetRequestStream(); string link_type; string type; string wikimode; string suggested_comment_sort; switch (ContentOptions) { case ContentOptions.All: link_type = "any"; break; case ContentOptions.LinkOnly: link_type = "link"; break; default: link_type = "self"; break; } switch (SubredditType) { case SubredditType.Public: type = "public"; break; case SubredditType.Private: type = "private"; break; case SubredditType.GoldRestricted: type = "gold_restricted"; break; case SubredditType.Archived: type = "archived"; break; case SubredditType.GoldOnly: type = "gold_only"; break; case SubredditType.EmployeesOnly: type = "employees_only"; break; default: type = "restricted"; break; } switch (WikiEditMode) { case WikiEditMode.All: wikimode = "anyone"; break; case WikiEditMode.Moderators: wikimode = "modonly"; break; default: wikimode = "disabled"; break; } switch (SuggestedCommentSort) { case CommentSorts.Confidence: suggested_comment_sort = "confidence"; break; case CommentSorts.Top: suggested_comment_sort = "top"; break; case CommentSorts.New: suggested_comment_sort = "new"; break; case CommentSorts.Controversial: suggested_comment_sort = "controversial"; break; case CommentSorts.Old: suggested_comment_sort = "old"; break; case CommentSorts.Random: suggested_comment_sort = "random"; break; case CommentSorts.Qa: suggested_comment_sort = "qa"; break; default: suggested_comment_sort = string.Empty; break; } WebAgent.WritePostBody(stream, new { allow_top = AllowAsDefault, allow_images = AllowImages, collapse_deleted_comments = CollapseDeletedComments, comment_score_hide_mins = MinutesToHideCommentScores, description = Sidebar, exclude_banned_modqueue = ExcludeBannedModqueue, domain = Domain, hide_ads = HideAds, lang = Language, link_type, over_18 = NSFW, public_description = PublicDescription, public_traffic = IsTrafficPublic, show_media = ShowThumbnails, show_media_preview = ShowMediaPreviews, sr = Subreddit.FullName, submit_link_label = SubmitLinkLabel, submit_text = SubmitText, submit_text_label = SubmitTextLabel, suggested_comment_sort, title = Title, type, uh = Reddit.User.Modhash, wiki_edit_age = WikiEditAge, wiki_edit_karma = WikiEditKarma, wikimode, spam_links = SpamFilter == null ? null : SpamFilter.LinkPostStrength.ToString().ToLowerInvariant(), spam_selfposts = SpamFilter == null ? null : SpamFilter.SelfPostStrength.ToString().ToLowerInvariant(), spam_comments = SpamFilter == null ? null : SpamFilter.CommentStrength.ToString().ToLowerInvariant(), api_type = "json" }, "header-title", HeaderHoverText); stream.Close(); var response = request.GetResponse(); var data = WebAgent.GetResponseString(response.GetResponseStream()); }