forked from CrustyJew/RedditSharp-DEPRECATED-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMore.cs
More file actions
54 lines (48 loc) · 1.65 KB
/
More.cs
File metadata and controls
54 lines (48 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System.Collections.Generic;
using System.Linq;
using System.Security.Authentication;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace RedditSharp.Things
{
/// <summary>
/// Represents more comments omitted from the base comment tree.
///
/// https://github.com/reddit/reddit/wiki/JSON#more
/// </summary>
public class More : Thing
{
#pragma warning disable 1591
public More(IWebAgent agent, JToken json) : base(agent, json)
{
}
#pragma warning restore 1591
private const string MoreUrl = "/api/morechildren.json?link_id={0}&children={1}&api_type=json";
/// <summary>
/// Bae36 Ids of children.
/// </summary>
[JsonProperty("children")]
public string[] Children { get; private set; }
/// <summary>
/// Parent base36 id.
/// </summary>
[JsonProperty("parent_id")]
public string ParentId { get; private set; }
/// <inheritdoc />
internal override JToken GetJsonData(JToken json) => json["data"];
/// <summary>
///
/// </summary>
/// <returns></returns>
public async Task<List<Thing>> GetThingsAsync()
{
var url = string.Format(MoreUrl, ParentId, string.Join(",", Children));
var json = await WebAgent.Get(url).ConfigureAwait(false);
if (json["errors"].Count() != 0)
throw new AuthenticationException("Incorrect login.");
var moreJson = json["data"]["things"];
return moreJson.Select(t => Thing.Parse(WebAgent, t)).ToList();
}
}
}