Skip to content

Commit 0cff99f

Browse files
authored
#217 Adding Crosspost _list (#225)
* Adding Crosspost _list can still add is_crosspostable crosspost_parent num_crossposts * adding more crosspost properties
1 parent 7463d86 commit 0cff99f

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

RedditSharp/RedditSharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<ItemGroup>
1515
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="1.1.2" />
1616
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
17+
<PackageReference Include="System.Collections.Immutable" Version="1.7.0" />
1718
<PackageReference Include="System.Net.Http" Version="4.3.3" />
1819
<PackageReference Include="System.Net.Security" Version="4.3.2" />
1920
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.0" />

RedditSharp/Things/Post.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Reactive.Linq;
88
using System.Threading.Tasks;
99
using System.Text.RegularExpressions;
10+
using System.Collections.Immutable;
1011

1112
namespace RedditSharp.Things
1213
{
@@ -54,6 +55,30 @@ public Post(IWebAgent agent, JToken json) : base(agent, json)
5455
[JsonProperty("is_self")]
5556
public bool IsSelfPost { get; private set; }
5657

58+
public IReadOnlyList<Post> CrossPostParents
59+
{
60+
get
61+
{
62+
if(_crossPostParents == null)
63+
{
64+
var builder = ImmutableList.CreateBuilder<Post>();
65+
if (RawJson["crosspost_parent_list"] != null)
66+
{
67+
foreach (JToken token in RawJson["crosspost_parent_list"])
68+
{
69+
Post post = new Post(WebAgent, token);
70+
builder.Add(post);
71+
}
72+
}
73+
_crossPostParents = builder.ToImmutable();
74+
}
75+
return _crossPostParents;
76+
}
77+
78+
}
79+
80+
private ImmutableList<Post> _crossPostParents;
81+
5782
/// <summary>
5883
/// Css class of the link flair.
5984
/// </summary>
@@ -128,6 +153,15 @@ public Post(IWebAgent agent, JToken json) : base(agent, json)
128153
[JsonConverter(typeof(UrlParser))]
129154
public Uri Url { get; private set; }
130155

156+
[JsonProperty("is_crosspostable")]
157+
public bool IsCrossPostable { get; private set; }
158+
159+
[JsonProperty("num_crossposts")]
160+
public int NumberOfCrossposts { get; private set; }
161+
162+
[JsonProperty("crosspost_parent")]
163+
public string CrosspostParent { get; private set; }
164+
131165
/// <summary>
132166
/// Returns the parent <see cref="Subreddit"/> for this post
133167
/// </summary>

RedditSharpTests/Things/PostTests.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,19 @@ public async Task EnumerateAllComments()
7575
Assert.Equal(25, commentsList.Count);
7676

7777
}
78+
[Fact]
79+
public async Task CrosspostParentList()
80+
{
81+
RedditSharp.WebAgent agent = new RedditSharp.WebAgent(authFixture.AccessToken);
82+
RedditSharp.Reddit reddit = new RedditSharp.Reddit(agent);
83+
var post = (Post)await reddit.GetThingByFullnameAsync("t3_f1e0jg");
84+
85+
86+
Assert.NotNull(post.CrossPostParents);
87+
Assert.True(post.CrossPostParents.Count > 0);
88+
Assert.True(post.CrossPostParents[0].CrossPostParents.Count == 0);
89+
90+
}
7891

79-
8092
}
8193
}

0 commit comments

Comments
 (0)