Skip to content

Commit 08e90f6

Browse files
committed
Merge pull request #221 from CrustyJew/master
Add Contributors listing to Subreddit
2 parents 9de946b + 65f0fda commit 08e90f6

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

RedditSharp/RedditSharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
</ItemGroup>
5353
<ItemGroup>
5454
<Compile Include="ModActionType.cs" />
55+
<Compile Include="Things\Contributor.cs" />
5556
<Compile Include="Things\ModAction.cs" />
5657
<Compile Include="Utils\DateTimeExtensions.cs" />
5758
<Compile Include="SpamFilterSettings.cs" />

RedditSharp/Things/Contributor.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
using Newtonsoft.Json.Linq;
4+
5+
namespace RedditSharp.Things
6+
{
7+
public class Contributor : Thing
8+
{
9+
[JsonProperty("name")]
10+
public string Name { get; set; }
11+
12+
[JsonProperty("date")]
13+
[JsonConverter(typeof(UnixTimestampConverter))]
14+
public DateTime DateAdded { get; set; }
15+
16+
public Contributor Init(Reddit reddit, JToken json, IWebAgent webAgent)
17+
{
18+
CommonInit(json);
19+
JsonConvert.PopulateObject(json.ToString(), this, reddit.JsonSerializerSettings);
20+
return this;
21+
}
22+
23+
private void CommonInit(JToken json)
24+
{
25+
base.Init(json);
26+
}
27+
}
28+
}

RedditSharp/Things/Subreddit.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class Subreddit : Thing
4141
private const string SearchUrl = "/r/{0}/search.json?q={1}&restrict_sr=on&sort={2}&t={3}";
4242
private const string SearchUrlDate = "/r/{0}/search.json?q=timestamp:{1}..{2}&restrict_sr=on&sort={3}&syntax=cloudsearch";
4343
private const string ModLogUrl = "/r/{0}/about/log.json";
44+
private const string ContributorsUrl = "/r/{0}/about/contributors.json";
4445

4546
[JsonIgnore]
4647
private Reddit Reddit { get; set; }
@@ -302,6 +303,14 @@ public IEnumerable<TBUserNote> UserNotes
302303
}
303304
}
304305

306+
public Listing<Contributor> Contributors
307+
{
308+
get
309+
{
310+
return new Listing<Contributor>( Reddit, string.Format( ContributorsUrl, Name ), WebAgent );
311+
}
312+
}
313+
305314
public Subreddit Init(Reddit reddit, JToken json, IWebAgent webAgent)
306315
{
307316
CommonInit(reddit, json, webAgent);

RedditSharp/Things/Thing.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public static Thing Parse<T>(Reddit reddit, JToken json, IWebAgent webAgent) whe
4242
{
4343
return new ModAction().Init(reddit, json, webAgent);
4444
}
45+
else if (typeof(T) == typeof(Contributor))
46+
{
47+
return new Contributor().Init(reddit, json, webAgent);
48+
}
4549
}
4650
return result;
4751
}

0 commit comments

Comments
 (0)