Skip to content

Commit

Permalink
Merge pull request #10 from zacbrown/master
Browse files Browse the repository at this point in the history
Add ability to get user's saved posts. Remove Score property to fix warning.
  • Loading branch information
CrustyJew authored Sep 10, 2016
2 parents 5b2a2b6 + 7d70cc9 commit 9678b97
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
3 changes: 0 additions & 3 deletions RedditSharp/Things/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,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; }

Expand Down
19 changes: 19 additions & 0 deletions RedditSharp/Things/RedditUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

/// <summary>
/// Get a listing of comments and posts saved by the user sorted by <paramref name="sorting"/>, from time <paramref name="fromTime"/>
/// and limited to <paramref name="limit"/>.
/// </summary>
/// <param name="sorting">How to sort the comments (hot, new, top, controversial).</param>
/// <param name="limit">How many comments to fetch per request. Max is 100.</param>
/// <param name="fromTime">What time frame of comments to show (hour, day, week, month, year, all).</param>
/// <returns>The listing of posts and/or comments requested that the user saved.</returns>
public Listing<VotableThing> 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<VotableThing>(Reddit, savedUrl, WebAgent);
}

public override string ToString()
{
return Name;
Expand Down

0 comments on commit 9678b97

Please sign in to comment.