Skip to content

Commit 2e1fd10

Browse files
CSedar21CrustyJew
authored andcommitted
Adding the preview property from the Reddit API post response to the post class (#216)
* Adding the preview property from the Reddit API post response to the post class * Changing Image class Width and Height properties from int to int?
1 parent d25ae76 commit 2e1fd10

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed

RedditSharp/Things/Image.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Linq;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace RedditSharp.Things
10+
{
11+
/// <summary>
12+
/// Single image for a post.
13+
/// </summary>
14+
public class Image
15+
{
16+
public Image(IWebAgent agent, JToken json)
17+
{
18+
}
19+
20+
/// <summary>
21+
/// Url for the image.
22+
/// </summary>
23+
[JsonProperty("url")]
24+
public Uri Url { get; private set; }
25+
26+
/// <summary>
27+
/// Width of the image.
28+
/// </summary>
29+
[JsonProperty("width")]
30+
public int? Width { get; private set; }
31+
32+
/// <summary>
33+
/// Height of the image.
34+
/// </summary>
35+
[JsonProperty("height")]
36+
public int? Height { get; private set; }
37+
38+
}
39+
}

RedditSharp/Things/Images.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Linq;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace RedditSharp.Things
10+
{
11+
/// <summary>
12+
/// Post images provided for the post.
13+
/// </summary>
14+
public class Images
15+
{
16+
public Images(IWebAgent agent, JToken json)
17+
{
18+
}
19+
20+
/// <summary>
21+
/// Source image for the post.
22+
/// </summary>
23+
[JsonProperty("source")]
24+
public Image Source { get; private set; }
25+
26+
/// <summary>
27+
/// Different resolutions of the source image for the post.
28+
/// </summary>
29+
[JsonProperty("resolutions")]
30+
public List<Image> Resolutions { get; private set; }
31+
32+
/// <summary>
33+
/// Post preview id.
34+
/// </summary>
35+
[JsonProperty("id")]
36+
public string Id { get; private set; }
37+
}
38+
}

RedditSharp/Things/Post.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ public Post(IWebAgent agent, JToken json) : base(agent, json)
9797
[JsonConverter(typeof(UrlParser))]
9898
public Uri Thumbnail { get; private set; }
9999

100+
/// <summary>
101+
/// Preview image for the post.
102+
/// </summary>
103+
[JsonProperty("preview")]
104+
public Preview Preview { get; private set; }
105+
100106
/// <summary>
101107
/// Post title.
102108
/// </summary>

RedditSharp/Things/Preview.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Linq;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace RedditSharp.Things
10+
{
11+
/// <summary>
12+
/// Post preview images.
13+
/// </summary>
14+
public class Preview
15+
{
16+
public Preview(IWebAgent agent, JToken json)
17+
{
18+
}
19+
20+
/// <summary>
21+
/// List of post image in various resolutions.
22+
/// </summary>
23+
[JsonProperty("images")]
24+
public List<Images> Images { get; private set; }
25+
26+
/// <summary>
27+
/// Is there a preview enabled for this post.
28+
/// </summary>
29+
[JsonProperty("enabled")]
30+
public bool Enabled { get; private set; }
31+
}
32+
}

0 commit comments

Comments
 (0)