public static GitHubFollowingResponse ParseResponse(SocialHttpResponse response) { switch (response.StatusCode) { case HttpStatusCode.NoContent: return new GitHubFollowingResponse(response) { IsFollowing = true }; case HttpStatusCode.NotFound: return new GitHubFollowingResponse(response) { IsFollowing = false }; default: // Parse the raw JSON response JsonObject obj = response.GetBodyAsJsonObject(); string message = obj.GetString("message"); string url = obj.GetString("documentation_url"); throw new GitHubHttpException(response, message, url); } }
/// <summary> /// Validates the specified <code>response</code>. /// </summary> /// <param name="response">The response to be validated.</param> public static void ValidateResponse(SocialHttpResponse response) { // Skip error checking if the server responds with an OK status code if (response.StatusCode == HttpStatusCode.OK) return; throw new Exception("WTF?\n\n" + response.Body); }
/// <summary> /// Validates the specified <code>response</code>. /// </summary> /// <param name="response">The response to be validated.</param> public static void ValidateResponse(SocialHttpResponse response) { // Skip error checking if the server responds with an OK status code if (response.StatusCode == HttpStatusCode.OK) return; // Otherwise throw an exception throw new BitBucketException(response); }
/// <summary> /// Validates the specified <code>response</code>. /// </summary> /// <param name="response">The response to be validated.</param> public static void ValidateResponse(SocialHttpResponse response) { // Skip error checking if the server responds with an OK status code if (response.StatusCode == HttpStatusCode.OK) return; // Parse the JSON response PinterestError error = SocialUtils.ParseJsonObject(response.Body, PinterestError.Parse); // Throw the exception throw new PinterestException(response, error); }
/// <summary> /// Validates the specified <code>response</code>. /// </summary> /// <param name="response">The response to be validated.</param> /// <param name="obj">The object representing the response object.</param> public static void ValidateResponse(SocialHttpResponse response, JsonObject obj) { // Skip error checking if the server responds with an OK status code if (response.StatusCode == HttpStatusCode.OK) return; // Throw an exception based on the error message from the API JsonObject error = obj.GetObject("error"); int code = error.GetInt32("code"); string type = error.GetString("type"); string message = error.GetString("message"); int subcode = error.HasValue("error_subcode") ? error.GetInt32("error_subcode") : 0; throw new FacebookException(response, code, type, message, subcode); }
public static void ValidateResponse(SocialHttpResponse response) { // Skip error checking if the server responds with an OK status code if (response.StatusCode == HttpStatusCode.OK) return; // Get the "meta" object JsonObject obj = response.GetBodyAsJsonObject(); // Now throw some exceptions string message = obj.GetString("message"); string url = obj.GetString("documentation_url"); throw new GitHubHttpException(response, message, url); }
/// <summary> /// Validates the specified <code>response</code>. /// </summary> /// <param name="response">The response to be validated.</param> /// <param name="obj">The object representing the response object.</param> public static void ValidateResponse(SocialHttpResponse response, JsonObject obj) { // Skip error checking if the server responds with an OK status code if (response.StatusCode == HttpStatusCode.OK) return; JsonObject error = obj.GetObject("error"); int code = error.GetInt32("code"); string message = error.GetString("message"); // TODO: Parse "errors" throw new AnalyticsException(response, code, message); }
/// <summary> /// Validates the specified <code>response</code>. /// </summary> /// <param name="response">The response to be validated.</param> public static void ValidateResponse(SocialHttpResponse response) { // The Slack API will always return a "200 OK" status even when an error is returned, so we need to check // the "ok" property in the boolean instead // Get root object JsonObject obj = response.GetBodyAsJsonObject(); // Is the request/response successful? bool isOk = obj.GetBoolean("ok"); // Now throw some exceptions if (!isOk) throw new SlackException(response, obj.GetString("error")); }
/// <summary> /// Validates the specified <code>response</code>. /// </summary> /// <param name="response">The response to be validated.</param> public static void ValidateResponse(SocialHttpResponse response) { // Skip error checking if the server responds with an OK status code if (response.StatusCode == HttpStatusCode.OK) return; // Get the "meta" object JsonObject obj = response.GetBodyAsJsonObject(); // Now throw some exceptions throw new Exception("WTF?"); //int code = obj.GetInt32("code"); //string type = obj.GetString("error_type"); //string message = obj.GetString("error_message") ?? obj.GetString("error"); //throw new BasecampException(response, code, type, message); }
public static TwitterRateLimiting GetFromResponse(SocialHttpResponse response) { int limit; int remaining; int reset; if (!Int32.TryParse(response.Headers["x-rate-limit-limit"] ?? "", out limit)) { limit = -1; } if (!Int32.TryParse(response.Headers["x-rate-limit-remaining"] ?? "", out remaining)) { remaining = -1; } if (!Int32.TryParse(response.Headers["x-rate-limit-reset"] ?? "", out reset)) { reset = 0; } return new TwitterRateLimiting(limit, remaining, reset); }
public static void ValidateResponse(SocialHttpResponse response) { // Skip error checking if the server responds with an OK status code if (response.StatusCode == HttpStatusCode.OK) return; JsonObject obj = response.GetBodyAsJsonObject(); // For some types of errors, Twitter will only respond with an error message if (obj.HasValue("error")) { throw new TwitterException(response, obj.GetString("error"), 0); } // However in most cases, Twitter responds with an array of errors JsonArray errors = obj.GetArray("errors"); // Get the first error (don't remember ever seeing multiple errors in the same response) JsonObject error = errors.GetObject(0); // Throw the exception throw new TwitterException(response, error.GetString("message"), error.GetInt32("code")); }
internal AnalyticsException(SocialHttpResponse response, int code, string message) : base(message) { Response = response; Code = code; }
protected SocialResponse(SocialHttpResponse response) { Response = response; }
protected FacebookResponse(SocialHttpResponse response) : base(response) { }
public FacebookException(SocialHttpResponse response, int code, string type, string message, int subcode = 0) : base(message) { Response = response; Code = code; Type = type; Subcode = subcode; }
protected DropboxResponse(SocialHttpResponse response) : base(response) { }
public BitBucketException(SocialHttpResponse response) : base("Invalid response received from the BitBucket API (Status: " + ((int) response.StatusCode) + ")") { Response = response; StatusCode = response.StatusCode; }
internal InstagramException(SocialHttpResponse response, InstagramMetaData meta) : base(meta.ErrorMessage) { Response = response; RateLimiting = InstagramRateLimiting.GetFromResponse(response); Meta = meta; }
/// <summary> /// Executes the request and returns the corresponding response as an instance of <see cref="SocialHttpResponse"/>. /// </summary> /// <param name="callback">Lets you specify a callback method for modifying the underlying <see cref="HttpWebRequest"/>.</param> /// <returns>Returns an instance of <see cref="SocialHttpResponse"/> representing the response.</returns> public SocialHttpResponse GetResponse(Action <HttpWebRequest> callback) { // Build the URL string url = Url; if (QueryString != null && !QueryString.IsEmpty) { url += (url.Contains("?") ? "&" : "?") + QueryString; } // Initialize the request HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); // Misc request.Method = Method.ToString().ToUpper(); request.Credentials = Credentials; request.Headers = Headers.Headers; request.Accept = Accept; request.Referer = Referer; request.UserAgent = UserAgent; request.Timeout = (int)Timeout.TotalMilliseconds; if (!String.IsNullOrWhiteSpace(Host)) { request.Host = Host; } // Add the request body (if a POST request) if (Method == SocialHttpMethod.Post) { if (IsMultipart) { string boundary = Guid.NewGuid().ToString().Replace("-", ""); request.ContentType = "multipart/form-data; boundary=" + boundary; using (Stream stream = request.GetRequestStream()) { PostData.WriteMultipartFormData(stream, boundary); } } else { string dataString = PostData.ToString(); request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = dataString.Length; using (Stream stream = request.GetRequestStream()) { stream.Write(Encoding.UTF8.GetBytes(dataString), 0, dataString.Length); } } } // Call the callback if (callback != null) { callback(request); } // Get the response try { return(SocialHttpResponse.GetFromWebResponse(request.GetResponse() as HttpWebResponse, this)); } catch (WebException ex) { if (ex.Status != WebExceptionStatus.ProtocolError) { throw; } return(SocialHttpResponse.GetFromWebResponse(ex.Response as HttpWebResponse, this)); } }
protected YouTubeResponse(SocialHttpResponse response) { Response = response; }
/// <summary> /// Initializes a new instance from the specified <code>response</code> and <code>body</code>. /// </summary> /// <param name="response">The raw response.</param> /// <param name="body">The object representing the response body.</param> protected SocialOAuthAccessTokenResponse(SocialHttpResponse response, SocialOAuthAccessToken body) : base(response) { Body = body; }
public GitHubHttpException(SocialHttpResponse response, string message) : base(message) { Response = response; }
protected GitHubResponse(SocialHttpResponse response) { RateLimit = Int32.Parse(response.Headers["X-RateLimit-Limit"]); RateLimitRemaining = Int32.Parse(response.Headers["X-RateLimit-Remaining"]); RateLimitReset = SocialUtils.GetDateTimeFromUnixTime(response.Headers["X-RateLimit-Reset"]); Response = response; }
/// <summary> /// Initializes a new instance from the specified <code>response</code> and <code>body</code>. /// </summary> /// <param name="response">The raw response.</param> /// <param name="body">The object representing the response body.</param> protected SocialOAuthRequestTokenResponse(SocialHttpResponse response, SocialOAuthRequestToken body) : base(response) { Body = body; }
public InstagramOAuthException(SocialHttpResponse response, InstagramMetaData meta) : base(response, meta) { }
/// <summary> /// Initializes a new instance from the specified <code>response</code> and <code>body</code>. /// </summary> /// <param name="response">The raw response.</param> /// <param name="body">The object representing the response body.</param> /// <returns>Returns an instance of <see cref="SocialOAuthRequestTokenResponse"/>.</returns> public static SocialOAuthRequestTokenResponse ParseResponse(SocialHttpResponse response, SocialOAuthRequestToken body) { return response == null ? null : new SocialOAuthRequestTokenResponse(response, body); }
protected AnalyticsResponse(SocialHttpResponse response) : base(response) { }
private GitHubFollowingResponse(SocialHttpResponse response) : base(response) { }
public GitHubHttpException(SocialHttpResponse response) : base("Invalid response received from the GitHub API (Status: " + ((int) response.StatusCode) + ")") { Response = response; }
internal TwitterException(SocialHttpResponse response, string message, int code) : base(message) { Response = response; Code = code; }
public GitHubHttpException(SocialHttpResponse response, string message, string documentationUrl) : base(message) { Response = response; DocumentationUrl = documentationUrl; }