Exemplo n.º 1
0
        internal static PostListing FromJson(JToken token)
        {
            var list = new PostListing();

            list.ModHash = token["data"]["modhash"].ToString();
            list.Before  = token["data"]["before"].ToString();
            list.After   = token["data"]["after"].ToString();

            foreach (var child in token["data"]["children"].Children().Select(post => post["data"]))
            {
                list.Add(Post.FromJson(child));
            }

            return(list);
        }
Exemplo n.º 2
0
        public static PostListing GetPosts(Session session)
        {
            var request = new Request
            {
                Url    = "http://www.reddit.com/r/friends/.json",
                Method = "GET",
                Cookie = session.Cookie
            };

            var json = string.Empty;

            if (request.Execute(out json) != System.Net.HttpStatusCode.OK)
            {
                throw new RedditException(json);
            }

            var o = JObject.Parse(json);

            return(PostListing.FromJson(o));
        }
Exemplo n.º 3
0
        public static PostListing Query(Session session, string qry, string after, string before)
        {
            var request = new Request
            {
                Url    = "http://www.reddit.com/search.json?q=" + qry,
                Method = "GET",
                Cookie = session.Cookie
            };

            var json = string.Empty;

            if (request.Execute(out json) != System.Net.HttpStatusCode.OK)
            {
                throw new RedditException(json);
            }

            var o = JObject.Parse(json);

            return(PostListing.FromJson(o));
        }
Exemplo n.º 4
0
        public static PostListing GetDisliked(Session session, string username)
        {
            //
            var request = new Request
            {
                Url    = "http://www.reddit.com/user/" + username + "/disliked/.json",
                Method = "GET",
                Cookie = session.Cookie
            };

            var json = string.Empty;

            if (request.Execute(out json) != System.Net.HttpStatusCode.OK)
            {
                throw new RedditException(json);
            }

            var o = JObject.Parse(json);

            return(PostListing.FromJson(o));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get information about a URL or domain, find all the stories and comments
        /// associated within.
        /// </summary>
        /// <param name="session"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public static PostListing FromUrl(Session session, string url)
        {
            // build the request
            var request = new Request
            {
                Url    = "http://www.reddit.com/api/info.json?url=" + url,
                Method = "GET",
                Cookie = session.Cookie
            };

            // execute the request
            var json = string.Empty;

            if (request.Execute(out json) != System.Net.HttpStatusCode.OK)
            {
                throw new Exception(json);
            }

            // convert to a post listing
            var o = JObject.Parse(json);

            return(PostListing.FromJson(o));
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="session"></param>
        /// <returns></returns>
        public static PostListing List(Session session)
        {
            // GET
            // http://www.reddit.com/.json
            var request = new Request
            {
                Url    = "http://www.reddit.com/.json",
                Method = "GET",
                Cookie = session.Cookie
            };

            var json = string.Empty;

            if (request.Execute(out json) != System.Net.HttpStatusCode.OK)
            {
                throw new Exception(json);
            }

            // convert to a post listing
            var o = JObject.Parse(json);

            return(PostListing.FromJson(o));
        }
Exemplo n.º 7
0
 public static void GetSubmissionsAndComments(Session session, out PostListing posts, out CommentListing comments)
 {
     posts    = null;
     comments = null;
 }
Exemplo n.º 8
0
        public static PostListing GetListing(Session session, string sub, SubSortBy sort, string after, string before)
        {
            var url = "http://www.reddit.com/r/" + sub + "/";

            switch (sort)
            {
            case SubSortBy.Hot:
                url += ".json?limit=" + Limit;
                break;

            case SubSortBy.New:
                url += "new/.json?sort=new&limit=" + Limit;
                break;

            case SubSortBy.Rising:
                url += "new/.json?sort=rising&limit=" + Limit;
                break;

            case SubSortBy.TopAllTime:
                url += "top/.json?sort=top&t=all&limit=" + Limit;
                break;

            case SubSortBy.TopYear:
                url += "top/.json?sort=top&t=year&limit=" + Limit;
                break;

            case SubSortBy.TopMonth:
                url += "top/.json?sort=top&t=month&limit=" + Limit;
                break;

            case SubSortBy.TopWeek:
                url += "top/.json?sort=top&t=week&limit=" + Limit;
                break;

            case SubSortBy.TopToday:
                url += "top/.json?sort=top&t=day&limit=" + Limit;
                break;

            case SubSortBy.TopHour:
                url += "top/.json?sort=top&t=hour&limit=" + Limit;
                break;

            case SubSortBy.ControversalAllTime:
                url += "controversial/.json?sort=controversial&t=all&limit=" + Limit;
                break;

            case SubSortBy.ControversalYear:
                url += "controversial/.json?sort=controversial&t=year&limit=" + Limit;
                break;

            case SubSortBy.ControversalMonth:
                url += "controversial/.json?sort=controversial&t=month&limit=" + Limit;
                break;

            case SubSortBy.ControversalWeek:
                url += "controversial/.json?sort=controversial&t=week&limit=" + Limit;
                break;

            case SubSortBy.ControversalToday:
                url += "controversial/.json?sort=controversial&t=day&limit=" + Limit;
                break;

            case SubSortBy.ControversalHour:
                url += "controversial/.json?sort=controversial&t=hour&limit=" + Limit;
                break;
            }

            if (!string.IsNullOrEmpty(after))
            {
                url += "&after=" + after;
            }

            if (!string.IsNullOrEmpty(before))
            {
                url += "&before=" + before;
            }

            var request = new Request
            {
                Method = "GET",
                Cookie = session.Cookie,
                Url    = url
            };

            var json = string.Empty;

            if (request.Execute(out json) != System.Net.HttpStatusCode.OK)
            {
                throw new Exception(json);
            }

            var o = JObject.Parse(json);

            return(PostListing.FromJson(o));
        }