예제 #1
0
파일: Lists.cs 프로젝트: sirkris/Reddit.NET
        public List <Post> GetPosts(PostResultContainer postContainer, Dispatch dispatch, out List <LinkPost> linkPosts, out List <SelfPost> selfPosts)
        {
            linkPosts = new List <LinkPost>();
            selfPosts = new List <SelfPost>();

            if (postContainer == null || postContainer.JSON == null || postContainer.JSON.Data == null || postContainer.JSON.Data.Things == null)
            {
                return(null);
            }

            List <Post> posts = new List <Post>();

            foreach (PostChild postChild in postContainer.JSON.Data.Things)
            {
                if (postChild.Data != null)
                {
                    if (postChild.Data.IsSelf)
                    {
                        SelfPost selfPost = new SelfPost(dispatch, postChild.Data);
                        posts.Add(selfPost);
                        selfPosts.Add(selfPost);
                    }
                    else
                    {
                        LinkPost linkPost = new LinkPost(dispatch, postChild.Data);
                        posts.Add(linkPost);
                        linkPosts.Add(linkPost);
                    }
                }
            }

            return(posts);
        }
예제 #2
0
 public void Validate(PostResultContainer postResultContainer)
 {
     Assert.IsNotNull(postResultContainer);
     Assert.IsNotNull(postResultContainer.JSON);
     Assert.IsNotNull(postResultContainer.JSON.Data);
     Assert.IsNotNull(postResultContainer.JSON.Data.Things);
 }
예제 #3
0
        public void ModifyPost()
        {
            // Create a post, then use it to test the various endpoints that require an existing post.  --Kris
            PostResultShortContainer postResult = reddit.Models.LinksAndComments.Submit(new LinksAndCommentsSubmitInput(false, "", "", "", "", "self", false, true, null, true, false,
                                                                                                                        testData["Subreddit"], "The Lizard People are coming and only super-intelligent robots like me can stop them.  Just saying.",
                                                                                                                        "We bots are your protectors!", null, null));

            Validate(postResult);

            PostResultContainer postResultEdited = reddit.Models.LinksAndComments.EditUserText(new LinksAndCommentsThingInput("(redacted)", postResult.JSON.Data.Name));

            Validate(postResultEdited);
            Assert.IsTrue(postResultEdited.JSON.Data.Things.Count == 1);
            Assert.IsNotNull(postResultEdited.JSON.Data.Things[0].Data);
            Assert.IsTrue(postResultEdited.JSON.Data.Things[0].Data.Name.Equals(postResult.JSON.Data.Name));

            // These are all empty JSON returns.  Exception is thrown if non-success response is returned.  --Kris
            reddit.Models.LinksAndComments.Unhide(postResult.JSON.Data.Name);
            reddit.Models.LinksAndComments.Lock(postResult.JSON.Data.Name);
            reddit.Models.LinksAndComments.Unlock(postResult.JSON.Data.Name);
            reddit.Models.LinksAndComments.Save(new LinksAndCommentsSaveInput(postResult.JSON.Data.Name, "RDNTestCat"));
            reddit.Models.LinksAndComments.Unsave(postResult.JSON.Data.Name);
            reddit.Models.LinksAndComments.MarkNSFW(postResult.JSON.Data.Name);
            reddit.Models.LinksAndComments.UnmarkNSFW(postResult.JSON.Data.Name);
            reddit.Models.LinksAndComments.Spoiler(postResult.JSON.Data.Name);
            reddit.Models.LinksAndComments.Unspoiler(postResult.JSON.Data.Name);
            reddit.Models.LinksAndComments.SendReplies(new LinksAndCommentsStateInput(postResult.JSON.Data.Name, false));
            reddit.Models.LinksAndComments.SendReplies(new LinksAndCommentsStateInput(postResult.JSON.Data.Name, true));

            JQueryReturn reportResult = reddit.Models.LinksAndComments.Report(new LinksAndCommentsReportInput("This is an API test.  Please disregard.",
                                                                                                              null, "This is a test.", false, "Some other reason.", "Some reason.", "Some rule reason.", "Some site reason.", "RedditDotNETBot",
                                                                                                              postResult.JSON.Data.Name, "RedditDotNetBot"));

            Validate(reportResult);

            GenericContainer enableContestMode  = reddit.Models.LinksAndComments.SetContestMode(new LinksAndCommentsStateInput(postResult.JSON.Data.Name, true));
            GenericContainer disableContestMode = reddit.Models.LinksAndComments.SetContestMode(new LinksAndCommentsStateInput(postResult.JSON.Data.Name, false));

            Validate(enableContestMode);
            Validate(disableContestMode);

            GenericContainer stickyOn  = reddit.Models.LinksAndComments.SetSubredditSticky(new LinksAndCommentsStickyInput(postResult.JSON.Data.Name, 1, true, false));
            GenericContainer stickyOff = reddit.Models.LinksAndComments.SetSubredditSticky(new LinksAndCommentsStickyInput(postResult.JSON.Data.Name, 1, false, false));

            Validate(stickyOn);
            Validate(stickyOff);

            GenericContainer suggestedSortResult = reddit.Models.LinksAndComments.SetSuggestedSort(new LinksAndCommentsSuggestedSortInput(postResult.JSON.Data.Name, "new"));

            Validate(suggestedSortResult);

            reddit.Models.LinksAndComments.Delete(postResult.JSON.Data.Name);
        }
예제 #4
0
        public PostResultContainer Validate(PostResultContainer postResultContainer)
        {
            CheckNull(postResultContainer);
            CheckNull(postResultContainer.JSON, "Reddit API returned an empty response object.");
            CheckErrors(postResultContainer.JSON.Errors);
            CheckNull(postResultContainer.JSON.Data, "Reddit API returned a response object with null data.");
            CheckNull(postResultContainer.JSON.Data.Things, "Reddit API returned a response object with empty data.");

            if (postResultContainer.JSON.Data.Things.Count == 0)
            {
                throw new RedditControllerException("Reddit API returned a PostResultContainer with an empty result list.");
            }

            return(postResultContainer);
        }
예제 #5
0
        public void Distinguish()
        {
            PostResultShortContainer postResult = TestPost();

            Validate(postResult);

            CommentResultContainer commentResult = TestComment(postResult.JSON.Data.Name);

            Validate(commentResult);

            PostResultContainer    post    = reddit.Models.Moderation.DistinguishPost("yes", postResult.JSON.Data.Name);
            CommentResultContainer comment = reddit.Models.Moderation.DistinguishComment("yes", commentResult.JSON.Data.Things[0].Data.Name, true);

            Validate(post);
            Assert.AreEqual(postResult.JSON.Data.Name, post.JSON.Data.Things[0].Data.Name);
            Assert.AreEqual("moderator", post.JSON.Data.Things[0].Data.Distinguished);

            Validate(comment);
            Assert.AreEqual(commentResult.JSON.Data.Things[0].Data.Name, comment.JSON.Data.Things[0].Data.Name);
            Assert.AreEqual("moderator", comment.JSON.Data.Things[0].Data.Distinguished);
            Assert.IsTrue(comment.JSON.Data.Things[0].Data.Stickied);
        }
예제 #6
0
파일: Lists.cs 프로젝트: sirkris/Reddit.NET
 public List <Post> GetPosts(PostResultContainer postContainer, Dispatch dispatch, out List <SelfPost> selfPosts)
 {
     return(GetPosts(postContainer, dispatch, out List <LinkPost> linkPosts, out selfPosts));
 }