示例#1
0
        /// <summary>
        /// Submits a link post in the current subreddit using the logged-in user
        /// </summary>
        /// <param name="title">The title of the submission</param>
        /// <param name="url">The url of the submission link</param>
        public async Task <Post> SubmitPost(string title, string url)
        {
            if (Reddit.User == null)
            {
                throw new Exception("No user logged in.");
            }
            HttpClient    client  = Reddit.CreateClient();
            StringContent content = Reddit.StringForPost(new
            {
                api_type  = "json",
                extension = "json",
                kind      = "link",
                sr        = Title,
                title     = title,
                uh        = Reddit.User.Modhash,
                url       = url
            });
            var response = await client.PostAsync(SubmitLinkUrl, content);

            var responseContent = await response.Content.ReadAsStringAsync();

            var json = JToken.Parse(responseContent);

            return(new Post(Reddit, json["json"]));
            // TODO: Error
        }
示例#2
0
        /// <summary>
        /// Resets the subreddit's header image to the Reddit logo
        /// </summary>
        public async Task ResetHeaderImage()
        {
            HttpClient    client  = Reddit.CreateClient();
            StringContent content = Reddit.StringForPost(new
            {
                uh = Reddit.User.Modhash,
                r  = Subreddit.Name
            });
            var response = await client.PostAsync(DeleteHeaderImageUrl, content);

            var responseContent = await response.Content.ReadAsStringAsync();
        }
示例#3
0
        public async Task SetAsRead()
        {
            HttpClient    client  = Reddit.CreateClient();
            StringContent content = Reddit.StringForPost(new
            {
                id       = this.FullName,
                uh       = Reddit.User.Modhash,
                api_type = "json"
            });
            var response = await client.PostAsync(SetAsReadUrl, content);

            var responseContent = await response.Content.ReadAsStringAsync();
        }
示例#4
0
        public async Task AcceptModeratorInvite()
        {
            HttpClient    client  = Reddit.CreateClient();
            StringContent content = Reddit.StringForPost(new
            {
                api_type = "json",
                uh       = Reddit.User.Modhash,
                r        = Name
            });
            var response = await client.PostAsync(AcceptModeratorInviteUrl, content);

            var responseContent = await response.Content.ReadAsStringAsync();
        }
示例#5
0
        public async Task ClearFlairTemplates(FlairType flairType)
        {
            HttpClient    client  = Reddit.CreateClient();
            StringContent content = Reddit.StringForPost(new
            {
                flair_type = flairType == FlairType.Link ? "LINK_FLAIR" : "USER_FLAIR",
                uh         = Reddit.User.Modhash,
                r          = Name
            });
            var response = await client.PostAsync(ClearFlairTemplatesUrl, content);

            var responseContent = await response.Content.ReadAsStringAsync();
        }
示例#6
0
        public async Task ClearVote()
        {
            HttpClient    client  = Reddit.CreateClient();
            StringContent content = Reddit.StringForPost(new
            {
                dir = 0,
                id  = FullName,
                uh  = Reddit.User.Modhash
            });
            var response = await client.PostAsync(VoteUrl, content);

            var responseContent = await response.Content.ReadAsStringAsync();
        }
示例#7
0
        public async Task Unsave()
        {
            HttpClient    client  = Reddit.CreateClient();
            StringContent content = Reddit.StringForPost(new
            {
                id = FullName,
                uh = Reddit.User.Modhash
            });
            var response = await client.PostAsync(UnsaveUrl, content);

            var responseContent = await response.Content.ReadAsStringAsync();

            Saved = false;
        }
示例#8
0
        public async Task RemoveModerator(string id)
        {
            HttpClient    client  = Reddit.CreateClient();
            StringContent content = Reddit.StringForPost(new
            {
                api_type = "json",
                uh       = Reddit.User.Modhash,
                r        = Name,
                type     = "moderator",
                id
            });
            var response = await client.PostAsync(LeaveModerationUrl, content);

            var responseContent = await response.Content.ReadAsStringAsync();
        }
示例#9
0
        public async Task SetUserFlair(string user, string cssClass, string text)
        {
            HttpClient    client  = Reddit.CreateClient();
            StringContent content = Reddit.StringForPost(new
            {
                css_class = cssClass,
                text      = text,
                uh        = Reddit.User.Modhash,
                r         = Name,
                name      = user
            });
            var response = await client.PostAsync(SetUserFlairUrl, content);

            var responseContent = await response.Content.ReadAsStringAsync();
        }
示例#10
0
        public async Task Delete()
        {
            HttpClient    client  = Reddit.CreateClient();
            StringContent content = Reddit.StringForPost(new
            {
                img_name = Name,
                uh       = Reddit.User.Modhash,
                r        = SubredditStyle.Subreddit.Name
            });
            var response = await client.PostAsync(DeleteImageUrl, content);

            var responseContent = await response.Content.ReadAsStringAsync();

            SubredditStyle.Images.Remove(this);
        }
示例#11
0
        public async Task Vote(VoteType type)
        {
            HttpClient    client  = Reddit.CreateClient();
            StringContent content = Reddit.StringForPost(new
            {
                dir = (int)type,
                id  = FullName,
                uh  = Reddit.User.Modhash
            });
            var response = await client.PostAsync(VoteUrl, content);

            var responseContent = await response.Content.ReadAsStringAsync();

            Liked = null;
        }
示例#12
0
        public async Task Downvote()
        {
            HttpClient    client  = Reddit.CreateClient();
            StringContent content = Reddit.StringForPost(new
            {
                dir = -1,
                id  = FullName,
                uh  = Reddit.User.Modhash
            });
            var response = await client.PostAsync(VoteUrl, content);

            var responseContent = await response.Content.ReadAsStringAsync();

            // TODO: check the data for success or failure
            Liked = false;
        }
示例#13
0
        public async Task UpdateCss()
        {
            HttpClient    client  = Reddit.CreateClient();
            StringContent content = Reddit.StringForPost(new
            {
                op = "save",
                stylesheet_content = CSS,
                uh       = Reddit.User.Modhash,
                api_type = "json",
                r        = Subreddit.Name
            });
            var response = await client.PostAsync(UpdateCssUrl, content);

            var responseContent = await response.Content.ReadAsStringAsync();

            var json = JToken.Parse(responseContent);
        }
示例#14
0
        public async Task Reply(string message)
        {
            if (Reddit.User == null)
            {
                throw new Exception("No user logged in.");
            }
            HttpClient    client  = Reddit.CreateClient();
            StringContent content = Reddit.StringForPost(new
            {
                text     = message,
                thing_id = FullName,
                uh       = Reddit.User.Modhash
            });
            var response = await client.PostAsync(CommentUrl, content);

            var responseContent = await response.Content.ReadAsStringAsync();

            var json = JObject.Parse(responseContent);
        }
示例#15
0
        public async Task Unsubscribe()
        {
            if (Reddit.User == null)
            {
                throw new Exception("No user logged in.");
            }
            HttpClient    client  = Reddit.CreateClient();
            StringContent content = Reddit.StringForPost(new
            {
                action = "unsub",
                sr     = FullName,
                uh     = Reddit.User.Modhash
            });
            var response = await client.PostAsync(SubscribeUrl, content);

            var responseContent = await response.Content.ReadAsStringAsync();

            // Do something with the results or discard them
        }
示例#16
0
        public async Task AddFlairTemplate(string cssClass, FlairType flairType, string text, bool userEditable)
        {
            HttpClient    client  = Reddit.CreateClient();
            StringContent content = Reddit.StringForPost(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"
            });
            var response = await client.PostAsync(FlairTemplateUrl, content);

            var responseContent = await response.Content.ReadAsStringAsync();

            var json = JToken.Parse(responseContent);
        }
示例#17
0
        public async Task UpdateSettings()
        {
            HttpClient client = Reddit.CreateClient();
            string     link_type;
            string     type;
            string     wikimode;

            switch (ContentOptions)
            {
            case RedditWP.ContentOptions.All:
                link_type = "any";
                break;

            case RedditWP.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;
            }
            StringContent content = Reddit.StringForPost(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,
                api_type = "json"
            }, "header-title", HeaderHoverText);
            var response = await client.PostAsync(SiteAdminUrl, content);

            var responseContent = await response.Content.ReadAsStringAsync();
        }