Skip to content

Commit 9678b97

Browse files
authored
Merge pull request #10 from zacbrown/master
Add ability to get user's saved posts. Remove Score property to fix warning.
2 parents 5b2a2b6 + 7d70cc9 commit 9678b97

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

RedditSharp/Things/Post.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ public Comment[] Comments
120120
[JsonConverter(typeof(UrlParser))]
121121
public Uri Permalink { get; set; }
122122

123-
[JsonProperty("score")]
124-
public new int Score { get; set; }
125-
126123
[JsonProperty("selftext")]
127124
public string SelfText { get; set; }
128125

RedditSharp/Things/RedditUser.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class RedditUser : Thing
1313
private const string SubscribedSubredditsUrl = "/subreddits/mine.json";
1414
private const string LikedUrl = "/user/{0}/liked.json";
1515
private const string DislikedUrl = "/user/{0}/disliked.json";
16+
private const string SavedUrl = "/user/{0}/saved.json";
1617

1718
private const int MAX_LIMIT = 100;
1819

@@ -164,6 +165,24 @@ public Listing<Post> GetPosts(Sort sorting = Sort.New, int limit = 25, FromTime
164165
return new Listing<Post>(Reddit, linksUrl, WebAgent);
165166
}
166167

168+
/// <summary>
169+
/// Get a listing of comments and posts saved by the user sorted by <paramref name="sorting"/>, from time <paramref name="fromTime"/>
170+
/// and limited to <paramref name="limit"/>.
171+
/// </summary>
172+
/// <param name="sorting">How to sort the comments (hot, new, top, controversial).</param>
173+
/// <param name="limit">How many comments to fetch per request. Max is 100.</param>
174+
/// <param name="fromTime">What time frame of comments to show (hour, day, week, month, year, all).</param>
175+
/// <returns>The listing of posts and/or comments requested that the user saved.</returns>
176+
public Listing<VotableThing> GetSaved(Sort sorting = Sort.New, int limit = 25, FromTime fromTime = FromTime.All)
177+
{
178+
if ((limit < 1) || (limit > MAX_LIMIT))
179+
throw new ArgumentOutOfRangeException("limit", "Valid range: [1," + MAX_LIMIT + "]");
180+
string savedUrl = string.Format(SavedUrl, Name);
181+
savedUrl += string.Format("?sort={0}&limit={1}&t={2}", Enum.GetName(typeof(Sort), sorting), limit, Enum.GetName(typeof(FromTime), fromTime));
182+
183+
return new Listing<VotableThing>(Reddit, savedUrl, WebAgent);
184+
}
185+
167186
public override string ToString()
168187
{
169188
return Name;

0 commit comments

Comments
 (0)