Skip to content

Commit 3624b49

Browse files
committed
Merge pull request #174 from Stepepper/master
Search and Post's subreddit function.
2 parents 81179d0 + d52f841 commit 3624b49

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

RedditSharp/Listing.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@
55

66
namespace RedditSharp
77
{
8+
public enum Sorting
9+
{
10+
Relevance,
11+
New,
12+
Top,
13+
Comments
14+
}
15+
16+
public enum TimeSorting
17+
{
18+
All,
19+
Hour,
20+
Day,
21+
Week,
22+
Month,
23+
Year
24+
}
25+
826
public class Listing<T> : IEnumerable<T> where T : Thing
927
{
1028
/// <summary>

RedditSharp/Reddit.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,11 @@ public Listing<T> SearchByUrl<T>(string url) where T : Thing
356356
return Search<T>(urlSearchQuery);
357357
}
358358

359-
public Listing<T> Search<T>(string query) where T : Thing
359+
public Listing<T> Search<T>(string query, Sorting sortE = Sorting.Relevance, TimeSorting timeE = TimeSorting.All) where T : Thing
360360
{
361-
return new Listing<T>(this, string.Format(SearchUrl, query, "relevance", "all"), _webAgent);
361+
string sort = sortE.ToString().ToLower();
362+
string time = timeE.ToString().ToLower();
363+
return new Listing<T>(this, string.Format(SearchUrl, query, sort, time), _webAgent);
362364
}
363365

364366
#region Helpers

RedditSharp/Things/Post.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ public Comment[] Comments
123123
[JsonProperty("title")]
124124
public string Title { get; set; }
125125

126+
[JsonProperty("subreddit")]
127+
public string SubredditName { get; set; }
128+
129+
[JsonIgnore]
130+
public Subreddit Subreddit
131+
{
132+
get
133+
{
134+
return Reddit.GetSubreddit("/r/" + SubredditName);
135+
}
136+
}
137+
126138
[JsonProperty("url")]
127139
[JsonConverter(typeof(UrlParser))]
128140
public Uri Url { get; set; }

0 commit comments

Comments
 (0)