/// <summary> /// Makes a HTTP request based on the specified parameters. /// </summary> /// <param name="method">The HTTP method of the request.</param> /// <param name="url">The base URL of the request (no query string).</param> /// <param name="queryString">The query string.</param> /// <param name="body">The body of the request.</param> /// <param name="options">The options to be used when serializing <paramref name="body"/>.</param> /// <returns>An instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns> public virtual SocialHttpResponse DoHttpRequest(SocialHttpMethod method, string url, NameValueCollection queryString, XNode body, SaveOptions options) { if (body == null) { throw new ArgumentNullException(nameof(body)); } return(DoHttpRequest(method, url, queryString, "text/xml", body.ToString(options))); }
/// <summary> /// Makes a HTTP request based on the specified parameters. /// </summary> /// <param name="method">The HTTP method of the request.</param> /// <param name="url">The base URL of the request (no query string).</param> /// <param name="queryString">The query string.</param> /// <param name="body">The body of the request.</param> /// <param name="formatting">The formatting to be used when serializing <paramref name="body"/>.</param> /// <returns>An instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns> public virtual SocialHttpResponse DoHttpRequest(SocialHttpMethod method, string url, NameValueCollection queryString, JToken body, Formatting formatting) { if (body == null) { throw new ArgumentNullException(nameof(body)); } return(DoHttpRequest(method, url, queryString, "application/json", body.ToString(formatting))); }
/// <summary> /// Generates the string value used for making the signature. /// </summary> /// <param name="method">The method for the HTTP request.</param> /// <param name="url">The URL of the request.</param> /// <param name="queryString">The query string.</param> /// <param name="body">The POST data.</param> /// <returns>The generated signature value.</returns> public virtual string GenerateSignatureValue(SocialHttpMethod method, string url, IHttpQueryString queryString, IHttpPostData body) { return(String.Format( "{0}&{1}&{2}", method.ToString().ToUpper(), Uri.EscapeDataString(url.Split('#')[0].Split('?')[0]), Uri.EscapeDataString(GenerateParameterString(queryString, body)) )); }
/// <summary> /// Makes a HTTP request using the specified <paramref name="url"/> and <paramref name="method"/>. /// </summary> /// <param name="url">The URL of the request.</param> /// <param name="method">The HTTP method of the request.</param> /// <param name="queryString">The query string of the request.</param> /// <param name="postData">The POST data of the request.</param> /// <returns>An instance of <see cref="SocialHttpResponse"/> representing the response.</returns> private static SocialHttpResponse DoHttpRequest(SocialHttpMethod method, string url, IHttpQueryString queryString, IHttpPostData postData) { // Initialize the request SocialHttpRequest request = new SocialHttpRequest { Url = url, Method = method, QueryString = queryString, PostData = postData }; // Make the call to the URL return(request.GetResponse()); }
/// <summary> /// Generate the signature. /// </summary> /// <param name="method">The method for the HTTP request.</param> /// <param name="url">The URL of the request.</param> /// <param name="queryString">The query string.</param> /// <param name="body">The POST data.</param> /// <returns>Returns the generated signature.</returns> public virtual string GenerateSignature(SocialHttpMethod method, string url, IHttpQueryString queryString, IHttpPostData body) { HMACSHA1 hasher = new HMACSHA1(new ASCIIEncoding().GetBytes(GenerateSignatureKey())); return Convert.ToBase64String(hasher.ComputeHash(new ASCIIEncoding().GetBytes(GenerateSignatureValue(method, url, queryString, body)))); }
/// <summary> /// Generates the string value used for making the signature. /// </summary> /// <param name="method">The method for the HTTP request.</param> /// <param name="url">The URL of the request.</param> /// <param name="queryString">The query string.</param> /// <param name="body">The POST data.</param> /// <returns>Returns the generated signature value.</returns> public virtual string GenerateSignatureValue(SocialHttpMethod method, string url, IHttpQueryString queryString, IHttpPostData body) { return String.Format( "{0}&{1}&{2}", method.ToString().ToUpper(), Uri.EscapeDataString(url.Split('#')[0].Split('?')[0]), Uri.EscapeDataString(GenerateParameterString(queryString, body)) ); }
/// <summary> /// Makes a HTTP request using the specified <code>url</code> and <code>method</code>. /// </summary> /// <param name="url">The URL of the request.</param> /// <param name="method">The HTTP method of the request.</param> /// <param name="queryString">The query string of the request.</param> /// <param name="postData">The POST data of the request.</param> /// <returns>Returns an instance of <see cref="SocialHttpResponse"/> representing the response.</returns> private static SocialHttpResponse DoHttpRequest(SocialHttpMethod method, string url, IHttpQueryString queryString, IHttpPostData postData) { // Initialize the request SocialHttpRequest request = new SocialHttpRequest { Url = url, Method = method, QueryString = queryString, PostData = postData }; // Make the call to the URL return request.GetResponse(); }
/// <summary> /// Makes a HTTP request to the underlying API based on the specified parameters. /// </summary> /// <param name="method">The HTTP method of the request.</param> /// <param name="url">The base URL of the request (no query string).</param> /// <param name="postData">The POST data.</param> /// <returns>Returns an instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns> public virtual SocialHttpResponse DoHttpRequest(SocialHttpMethod method, string url, IHttpPostData postData) { return DoHttpRequest(method, url, null, postData); }
/// <summary> /// Makes a HTTP request to the underlying API based on the specified parameters. /// </summary> /// <param name="method">The HTTP method of the request.</param> /// <param name="url">The base URL of the request (no query string).</param> /// <param name="options">The options for the call to the API.</param> /// <returns>Returns an instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns> public virtual SocialHttpResponse DoHttpRequest(SocialHttpMethod method, string url, IHttpGetOptions options) { IHttpQueryString queryString = options == null ? null : options.GetQueryString(); return DoHttpRequest(method, url, queryString); }
/// <summary> /// Makes a HTTP request to the underlying API based on the specified parameters. /// </summary> /// <param name="method">The HTTP method of the request.</param> /// <param name="url">The base URL of the request (no query string).</param> /// <returns>Returns an instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns> public virtual SocialHttpResponse DoHttpRequest(SocialHttpMethod method, string url) { return DoHttpRequest(method, url, default(IHttpQueryString), default(IHttpPostData)); }
/// <summary> /// Makes a HTTP request to the underlying API based on the specified parameters. /// </summary> /// <param name="method">The HTTP method of the request.</param> /// <param name="url">The base URL of the request (no query string).</param> /// <param name="queryString">The query string.</param> /// <param name="contentType">The content type of the request - eg. <c>application/json</c>.</param> /// <param name="body">The body of the request.</param> /// <returns>An instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns> public virtual SocialHttpResponse DoHttpRequest(SocialHttpMethod method, string url, NameValueCollection queryString, string contentType, string body) { return(DoHttpRequest(method, url, queryString == null ? null : new SocialHttpQueryString(queryString), contentType, body)); }
/// <summary> /// Makes a HTTP request to the underlying API based on the specified parameters. /// </summary> /// <param name="method">The HTTP method of the request.</param> /// <param name="url">The base URL of the request (no query string).</param> /// <param name="queryString">The query string.</param> /// <param name="postData">The POST data.</param> /// <returns>An instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns> public virtual SocialHttpResponse DoHttpRequest(SocialHttpMethod method, string url, NameValueCollection queryString, NameValueCollection postData) { return(DoHttpRequest(method, url, queryString == null ? null : new SocialHttpQueryString(queryString), postData == null ? null : new SocialHttpPostData(postData))); }
/// <summary> /// Makes a HTTP request to the underlying API based on the specified parameters. /// </summary> /// <param name="method">The HTTP method of the request.</param> /// <param name="url">The base URL of the request (no query string).</param> /// <param name="queryString">The query string.</param> /// <param name="postData">The POST data.</param> /// <returns>An instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns> public static SocialHttpResponse DoHttpRequest(SocialHttpMethod method, string url, NameValueCollection queryString, NameValueCollection postData) { return(DoHttpRequest(method, url, new SocialHttpQueryString(queryString), new SocialHttpPostData(postData))); }
/// <summary> /// Makes a HTTP request to the underlying API based on the specified parameters. /// </summary> /// <param name="method">The HTTP method of the request.</param> /// <param name="url">The base URL of the request (no query string).</param> /// <param name="queryString">The query string.</param> /// <returns>An instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns> public static SocialHttpResponse DoHttpRequest(SocialHttpMethod method, string url, NameValueCollection queryString) { return(DoHttpRequest(method, url, queryString == null ? null : new SocialHttpQueryString(queryString), null)); }
/// <summary> /// Makes a HTTP request to the underlying API based on the specified parameters. /// </summary> /// <param name="method">The HTTP method of the request.</param> /// <param name="url">The base URL of the request (no query string).</param> /// <returns>An instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns> public static SocialHttpResponse DoHttpRequest(SocialHttpMethod method, string url) { return(DoHttpRequest(method, url, default(IHttpQueryString), default(IHttpPostData))); }
/// <summary> /// Generates the signature. /// </summary> /// <param name="method">The method for the HTTP request.</param> /// <param name="url">The URL of the request.</param> /// <param name="queryString">The query string.</param> /// <param name="body">The POST data.</param> /// <returns>Returns the generated signature.</returns> public virtual string GenerateSignature(SocialHttpMethod method, string url, IHttpQueryString queryString, IHttpPostData body) { HMACSHA1 hasher = new HMACSHA1(new ASCIIEncoding().GetBytes(GenerateSignatureKey())); return(Convert.ToBase64String(hasher.ComputeHash(new ASCIIEncoding().GetBytes(GenerateSignatureValue(method, url, queryString, body))))); }
/// <summary> /// Makes a HTTP request to the underlying API based on the specified parameters. /// </summary> /// <param name="method">The HTTP method of the request.</param> /// <param name="url">The base URL of the request (no query string).</param> /// <param name="options">The options for the call to the API.</param> /// <returns>An instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns> public static SocialHttpResponse DoHttpRequest(SocialHttpMethod method, string url, IHttpGetOptions options) { IHttpQueryString queryString = options?.GetQueryString(); return(DoHttpRequest(method, url, queryString)); }
/// <summary> /// Makes a HTTP request to the underlying API based on the specified parameters. /// </summary> /// <param name="method">The HTTP method of the request.</param> /// <param name="url">The base URL of the request (no query string).</param> /// <param name="queryString">The query string.</param> /// <param name="postData">The POST data.</param> /// <returns>Returns an instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns> public virtual SocialHttpResponse DoHttpRequest(SocialHttpMethod method, string url, NameValueCollection queryString, NameValueCollection postData) { return DoHttpRequest(method, url, new SocialHttpQueryString(queryString), new SocialHttpPostData(postData)); }
/// <summary> /// Makes a HTTP request to the underlying API based on the specified parameters. /// </summary> /// <param name="method">The HTTP method of the request.</param> /// <param name="url">The base URL of the request (no query string).</param> /// <param name="queryString">The query string.</param> /// <returns>An instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns> public static SocialHttpResponse DoHttpRequest(SocialHttpMethod method, string url, IHttpQueryString queryString) { return(DoHttpRequest(method, url, queryString, null)); }
/// <summary> /// Makes a HTTP request to the underlying API based on the specified parameters. /// </summary> /// <param name="method">The HTTP method of the request.</param> /// <param name="url">The base URL of the request (no query string).</param> /// <param name="queryString">The query string.</param> /// <returns>Returns an instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns> public virtual SocialHttpResponse DoHttpRequest(SocialHttpMethod method, string url, IHttpQueryString queryString) { return DoHttpRequest(method, url, queryString, null); }
/// <summary> /// Makes a HTTP request to the underlying API based on the specified parameters. /// </summary> /// <param name="method">The HTTP method of the request.</param> /// <param name="url">The base URL of the request (no query string).</param> /// <param name="postData">The POST data.</param> /// <returns>An instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns> public static SocialHttpResponse DoHttpRequest(SocialHttpMethod method, string url, IHttpPostData postData) { return(DoHttpRequest(method, url, null, postData)); }
/// <summary> /// Makes a HTTP request to the underlying API based on the specified parameters. /// </summary> /// <param name="method">The HTTP method of the request.</param> /// <param name="url">The base URL of the request (no query string).</param> /// <param name="queryString">The query string.</param> /// <param name="postData">The POST data.</param> /// <returns>Returns an instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns> public virtual SocialHttpResponse DoHttpRequest(SocialHttpMethod method, string url, IHttpQueryString queryString, IHttpPostData postData) { // Some input validation if (String.IsNullOrWhiteSpace(url)) throw new ArgumentNullException("url"); if (queryString == null) queryString = new SocialHttpQueryString(); if (postData == null) postData = new SocialHttpPostData(); // Initialize the request SocialHttpRequest request = new SocialHttpRequest { Method = method, Url = url, QueryString = queryString, PostData = postData }; PrepareHttpRequest(request); // Make the call to the URL return request.GetResponse(); }
/// <summary> /// Makes a HTTP request to the underlying API based on the specified parameters. /// </summary> /// <param name="method">The HTTP method of the request.</param> /// <param name="url">The base URL of the request (no query string).</param> /// <param name="queryString">The query string.</param> /// <returns>Returns an instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns> public static SocialHttpResponse DoHttpRequest(SocialHttpMethod method, string url, NameValueCollection queryString) { return DoHttpRequest(method, url, new SocialHttpQueryString(queryString), null); }