Example #1
0
        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();
        }
Example #2
0
        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,
                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 == 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());
        }