-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from czf/feature-more-pt2
More comments
- Loading branch information
Showing
14 changed files
with
811 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Security.Authentication; | ||
using System.Threading.Tasks; | ||
using System.Web; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace RedditSharp.Things | ||
{ | ||
public class More : Thing | ||
{ | ||
private const string MoreUrl = "/api/morechildren.json?link_id={0}&children={1}&api_type=json"; | ||
|
||
[JsonIgnore] | ||
private Reddit Reddit { get; set; } | ||
|
||
[JsonIgnore] | ||
private IWebAgent WebAgent { get; set; } | ||
|
||
[JsonProperty("children")] | ||
public string[] Children { get; set; } | ||
|
||
[JsonProperty("parent_id")] | ||
public string ParentId { get; set; } | ||
|
||
public More Init(Reddit reddit, JToken more, IWebAgent webAgent) | ||
{ | ||
CommonInit(reddit, more, webAgent); | ||
JsonConvert.PopulateObject(more["data"].ToString(), this, reddit.JsonSerializerSettings); | ||
return this; | ||
} | ||
private void CommonInit(Reddit reddit, JToken more, IWebAgent webAgent) | ||
{ | ||
base.Init(more); | ||
Reddit = reddit; | ||
WebAgent = webAgent; | ||
} | ||
|
||
public IEnumerable<Thing> Things() | ||
{ | ||
var url = string.Format(MoreUrl, ParentId, string.Join(",", Children)); | ||
var request = WebAgent.CreateGet(url); | ||
var response = request.GetResponse(); | ||
var data = WebAgent.GetResponseString(response.GetResponseStream()); | ||
var json = JObject.Parse(data)["json"]; | ||
if (json["errors"].Count() != 0) | ||
throw new AuthenticationException("Incorrect login."); | ||
var moreJson = json["data"]["things"]; | ||
|
||
foreach (JToken token in moreJson) | ||
{ | ||
Thing parsed = Thing.Parse(Reddit, token, WebAgent); | ||
|
||
yield return parsed; | ||
} | ||
|
||
} | ||
|
||
internal async Task<Thing> InitAsync(Reddit reddit, JToken json, IWebAgent webAgent) | ||
{ | ||
CommonInit(reddit, json, webAgent); | ||
await JsonConvert.PopulateObjectAsync(json["data"].ToString(), this, reddit.JsonSerializerSettings); | ||
return this; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.