protected internal T GetThing <T>(string url) where T : Thing { var request = _webAgent.CreateGet(url); var response = request.GetResponse(); var data = _webAgent.GetResponseString(response.GetResponseStream()); var json = JToken.Parse(data); return((T)Thing.Parse(this, json, _webAgent)); }
public Thing GetThingByFullname(string fullname) { var request = _webAgent.CreateGet(string.Format(GetThingUrl, fullname)); var response = request.GetResponse(); var data = _webAgent.GetResponseString(response.GetResponseStream()); var json = JToken.Parse(data); return(Thing.Parse(this, json["data"]["children"][0], _webAgent)); }
protected internal Thing GetThing(string url, bool prependDomain = true) { var request = CreateGet(url, prependDomain); var response = request.GetResponse(); var data = GetResponseString(response.GetResponseStream()); var json = JToken.Parse(data); return(Thing.Parse(this, json)); }
private void Parse(JToken json) { var children = json["data"]["children"] as JArray; var things = new List <T>(); for (int i = 0; i < children.Count; i++) { if (!stream) { things.Add(Thing.Parse <T>(Listing.WebAgent, children[i])); } else { var kind = children[i]["kind"].ValueOrDefault <string>(); var id = children[i]["data"]["id"].ValueOrDefault <string>(); // check for new replies to pm / modmail if (kind == "t4" && children[i]["data"]["replies"].HasValues) { var replies = children[i]["data"]["replies"]["data"]["children"] as JArray; foreach (var reply in replies) { var replyId = reply["data"]["id"].ValueOrDefault <string>(); if (done.Contains(replyId)) { continue; } things.Add(Thing.Parse <T>(Listing.WebAgent, reply)); done.Add(replyId); } } if (String.IsNullOrEmpty(id) || done.Contains(id)) { continue; } things.Add(Thing.Parse <T>(Listing.WebAgent, children[i])); done.Add(id); } } // this doesn't really work when we're processing messages with replies. if (stream) { things.Reverse(); } CurrentPage = new ReadOnlyCollection <T>(things); // Increase the total count of items returned After = json["data"]["after"].Value <string>(); Before = json["data"]["before"].Value <string>(); }
private void Parse(JToken json) { var children = json["data"]["children"] as JArray; CurrentPage = new Thing[children.Count]; for (int i = 0; i < CurrentPage.Length; i++) { CurrentPage[i] = Thing.Parse(Listing.Reddit, children[i]); } After = json["data"]["after"].Value <string>(); Before = json["data"]["before"].Value <string>(); }
private void Parse(JToken json) { var children = json["data"]["children"] as JArray; CurrentPage = new Thing[children.Count]; for (int i = 0; i < CurrentPage.Length; i++) { CurrentPage[i] = Thing.Parse <T>(Listing.Reddit, children[i], Listing.WebAgent); } // Increase the total count of items returned Count += CurrentPage.Length; After = json["data"]["after"].Value <string>(); Before = json["data"]["before"].Value <string>(); }
public Comment GetComment(string subreddit, string name, string linkName) { try { if (linkName.StartsWith("t3_")) { linkName = linkName.Substring(3); } if (name.StartsWith("t1_")) { name = name.Substring(3); } var json = _webAgent.CreateAndExecuteRequest(string.Format(GetCommentUrl, subreddit, linkName, name)); return(Thing.Parse(this, json[1]["data"]["children"][0], _webAgent) as Comment); } catch (WebException) { return(null); } }
public Comment GetComment(string subreddit, string name, string linkName) { try { if (linkName.StartsWith("t3_")) { linkName = linkName.Substring(3); } if (name.StartsWith("t1_")) { name = name.Substring(3); } var request = _webAgent.CreateGet(string.Format(GetCommentUrl, subreddit, linkName, name)); var response = request.GetResponse(); var data = _webAgent.GetResponseString(response.GetResponseStream()); var json = JToken.Parse(data); return(Thing.Parse(this, json[1]["data"]["children"][0], _webAgent) as Comment); } catch (WebException) { return(null); } }
private void Parse(JToken json) { var children = json["data"]["children"] as JArray; var things = new List <Thing>(); for (int i = 0; i < children.Count; i++) { if (!stream) { things.Add(Thing.Parse <T>(Listing.Reddit, children[i], Listing.WebAgent)); } else { // we only want to see new items. var id = children[i]["data"]["id"].ValueOrDefault <string>(); if (String.IsNullOrEmpty(id) || done.Contains(id)) { continue; } things.Add(Thing.Parse <T>(Listing.Reddit, children[i], Listing.WebAgent)); done.Add(id); } } if (stream) { things.Reverse(); } CurrentPage = things.ToArray(); // Increase the total count of items returned Count += CurrentPage.Length; After = json["data"]["after"].Value <string>(); Before = json["data"]["before"].Value <string>(); }
/// <summary> /// Get a <see cref="Thing"/> by full name. /// </summary> /// <param name="agent">IWebAgent to use to make request</param> /// <param name="fullname">fullname including kind + underscore. EG ("t1_######")</param> /// <returns></returns> public static async Task <Thing> GetThingByFullnameAsync(IWebAgent agent, string fullname) { var json = await agent.Get(string.Format(GetThingUrl, fullname)).ConfigureAwait(false); return(Thing.Parse(agent, json["data"]["children"][0])); }
protected internal T GetThing <T>(string url) where T : Thing { var json = _webAgent.CreateAndExecuteRequest(url); return((T)Thing.Parse(this, json, _webAgent)); }
public Thing GetThingByFullname(string fullname) { var json = _webAgent.CreateAndExecuteRequest(string.Format(GetThingUrl, fullname)); return(Thing.Parse(this, json["data"]["children"][0], _webAgent)); }