From fcb249cf6000b1d666bae38c7f7a53dcb4c1885f Mon Sep 17 00:00:00 2001 From: Zac Brown Date: Tue, 21 Jun 2016 21:26:16 -0700 Subject: [PATCH 1/2] - Fix compiler warning. - Add GetSaved() function for RedditUser to get saved posts/comments. Signed-off-by: Zac Brown --- RedditSharp/Things/Post.cs | 2 +- RedditSharp/Things/RedditUser.cs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/RedditSharp/Things/Post.cs b/RedditSharp/Things/Post.cs index 8051dcd..65a7e2a 100644 --- a/RedditSharp/Things/Post.cs +++ b/RedditSharp/Things/Post.cs @@ -108,7 +108,7 @@ public Comment[] Comments public Uri Permalink { get; set; } [JsonProperty("score")] - public int Score { get; set; } + public new int Score { get; set; } [JsonProperty("selftext")] public string SelfText { get; set; } diff --git a/RedditSharp/Things/RedditUser.cs b/RedditSharp/Things/RedditUser.cs index 74a2c53..c706b46 100644 --- a/RedditSharp/Things/RedditUser.cs +++ b/RedditSharp/Things/RedditUser.cs @@ -13,6 +13,7 @@ public class RedditUser : Thing private const string SubscribedSubredditsUrl = "/subreddits/mine.json"; private const string LikedUrl = "/user/{0}/liked.json"; private const string DislikedUrl = "/user/{0}/disliked.json"; + private const string SavedUrl = "/user/{0}/saved.json"; private const int MAX_LIMIT = 100; @@ -165,6 +166,24 @@ public Listing GetPosts(Sort sorting = Sort.New, int limit = 25, FromTime return new Listing(Reddit, linksUrl, WebAgent); } + /// + /// Get a listing of comments and posts saved by the user sorted by , from time + /// and limited to . + /// + /// How to sort the comments (hot, new, top, controversial). + /// How many comments to fetch per request. Max is 100. + /// What time frame of comments to show (hour, day, week, month, year, all). + /// The listing of posts and/or comments requested that the user saved. + public Listing GetSaved(Sort sorting = Sort.New, int limit = 25, FromTime fromTime = FromTime.All) + { + if ((limit < 1) || (limit > MAX_LIMIT)) + throw new ArgumentOutOfRangeException("limit", "Valid range: [1," + MAX_LIMIT + "]"); + string savedUrl = string.Format(SavedUrl, Name); + savedUrl += string.Format("?sort={0}&limit={1}&t={2}", Enum.GetName(typeof(Sort), sorting), limit, Enum.GetName(typeof(FromTime), fromTime)); + + return new Listing(Reddit, savedUrl, WebAgent); + } + public override string ToString() { return Name; From 3b34d3849b622e6e14dc4a149f4b83c20a3df0af Mon Sep 17 00:00:00 2001 From: Zac Brown Date: Wed, 13 Jul 2016 12:04:24 -0700 Subject: [PATCH 2/2] Remove Score from derived class. Signed-off-by: Zac Brown --- RedditSharp/Things/Post.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/RedditSharp/Things/Post.cs b/RedditSharp/Things/Post.cs index 65a7e2a..8212468 100644 --- a/RedditSharp/Things/Post.cs +++ b/RedditSharp/Things/Post.cs @@ -107,9 +107,6 @@ public Comment[] Comments [JsonConverter(typeof(UrlParser))] public Uri Permalink { get; set; } - [JsonProperty("score")] - public new int Score { get; set; } - [JsonProperty("selftext")] public string SelfText { get; set; }