public string SendGist(string fileName, string content, string description, bool isPublic, GitHubCredentials credentials) { var gistAsJson = new CreatesGistMessages().CreateMessage(fileName, content, description, isPublic); using (var stream = new MemoryStream()) { var request = new FluentHttpRequest() .BaseUrl("https://api.github.com") .ResourcePath("/gists") .Method("POST") .Headers(h => h.Add("User-Agent", "Gister")) .Headers(h => h.Add("Content-Type", "application/json")) .Body(x => x.Append(gistAsJson)) .OnResponseHeadersReceived((o, e) => e.SaveResponseIn(stream)); AppliesGitHubCredentialsToFluentHttpRequest.ApplyCredentials(credentials, request); var response = request .Execute(); if (response.Response.HttpWebResponse.StatusCode != HttpStatusCode.Created) throw new GitHubUnauthorizedException(response.Response.HttpWebResponse.StatusDescription); return PeelOutGistHtmlUrl(response); } }
public string SendGist(string fileName, string content, string description, bool isPublic, GitHubCredentials credentials) { var gistAsJson = new CreatesGistMessages().CreateMessage(fileName, content, description, isPublic); using (var stream = new MemoryStream()) { var request = new FluentHttpRequest() .BaseUrl("https://api.github.com") .ResourcePath("/gists") .Method("POST") .Headers(h => h.Add("User-Agent", "Gister")) .Headers(h => h.Add("Content-Type", "application/json")) .Body(x => x.Append(gistAsJson)) .OnResponseHeadersReceived((o, e) => e.SaveResponseIn(stream)); AppliesGitHubCredentialsToFluentHttpRequest.ApplyCredentials(credentials, request); var response = request .Execute(); if (response.Response.HttpWebResponse.StatusCode != HttpStatusCode.Created) { throw new GitHubUnauthorizedException(response.Response.HttpWebResponse.StatusDescription); } return(PeelOutGistHtmlUrl(response)); } }