public GithubResponse GetGithubResponseFromWebResponse(System.Net.HttpWebResponse response) { var responseString = new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd(); var responseToReturn = new GithubResponse { RateLimitLimit = int.Parse(response.Headers["X-RateLimit-Limit"]), RateLimitRemaining = int.Parse(response.Headers["X-RateLimit-Remaining"]), Response = responseString, StatusCode = (int)response.StatusCode, StatusText = response.StatusDescription }; if (!string.IsNullOrEmpty(response.Headers.Get("Link"))) { responseToReturn = ParsePagingLinks( responseToReturn, response.Headers.Get("Link")); } return(responseToReturn); }
public virtual GithubResponse ParsePagingLinks(GithubResponse response, string linkHeader) { foreach (var header in linkHeader.Split(new[] { ',' })) { var splitted = header.Split(new[] { ';' }); var link = splitted[0].Trim(); var what = splitted[1].Trim(); what = what.Substring(5); what = what.Substring(0, what.Length - 1); link = link.Substring(1); link = link.Substring(0, link.Length - 1); switch (what) { case "next": response.LinkNext = link; break; case "prev": response.LinkPrevious = link; break; case "first": response.LinkFirst = link; break; default: response.LinkLast = link; break; } } return(response); }