public override string MakeRequest(string uri, ResponseFormatType responseFormat, HttpMethodType httpMethodType, byte[] body, bool rawBody, bool isPhoto) { var rawResponse = string.Empty; if (this.AccessToken == null && string.IsNullOrEmpty(this.OAuthTokenKey) && string.IsNullOrEmpty(this.OAuthTokenSecret)) { throw new QzoneException("Can not make a request to a Protected Resource without a valid OAuth Access Token Key and Secret", QzoneExceptionType.TOKEN_REQUIRED); } if (this.AccessToken == null) { this.AccessToken = new AccessToken(this.OAuthConsumer, this.OAuthTokenKey, this.OAuthTokenSecret, this.OpenId); } this.OAuthConsumer.ResponseType = responseFormat; this.OAuthConsumer.Scheme = AuthorizationSchemeType.QueryString; switch (httpMethodType) { case HttpMethodType.POST: if (rawBody) { this.OAuthConsumer.ResponsePost(uri, body, rawBody, this.AccessToken.TokenKey, this.AccessToken.TokenSecret, this.AccessToken.Openid, isPhoto); } else { this.OAuthConsumer.ResponsePost(uri, body, this.AccessToken.TokenKey, this.AccessToken.TokenSecret, this.AccessToken.Openid); } break; case HttpMethodType.GET: this.OAuthConsumer.ResponseGet(uri, this.AccessToken.TokenKey, this.AccessToken.TokenSecret, this.AccessToken.Openid); break; default: break; } var httpResponse = this.OAuthConsumer.GetResponse() as HttpWebResponse; if (httpResponse != null) { var statusCode = (int)httpResponse.StatusCode; var streamReader = new StreamReader(httpResponse.GetResponseStream()); var responseBody = streamReader.ReadToEnd(); if (statusCode != 200 && statusCode != 201) { throw new QzoneException(string.Format("Your request received a response with status code {0}. {1}", statusCode, responseBody), QzoneExceptionType.REQUEST_FAILED, responseBody); } return(responseBody); } else { throw new QzoneException("Error making request.", QzoneExceptionType.REMOTE_ERROR); } }
public override string MakeRequest(string uri, ResponseFormatType responseFormat, HttpMethodType httpMethodType, string body) { byte[] bodyBytes; if (string.IsNullOrEmpty(body)) { body = string.Empty; } bodyBytes = !string.IsNullOrEmpty(body) ? Encoding.ASCII.GetBytes(body) : null; return(this.MakeRequest(uri, responseFormat, httpMethodType, bodyBytes, false)); }
private void AddFormat(ref string url, ResponseFormatType format) { switch (format) { case ResponseFormatType.Json: AddArgument(ref url, "format", "json"); break; case ResponseFormatType.Csv: AddArgument(ref url, "format", "csv"); break; case ResponseFormatType.Plain: AddArgument(ref url, "format", "psv"); break; default: throw new NotSupportedException($"{nameof(format)} is not supported."); } }
public abstract string MakeRequest(string uri, ResponseFormatType responseFormat, HttpMethodType httpMethodType, byte[] body, bool rawBody, bool isPhoto);
public override string MakeRequest(string uri, ResponseFormatType responseFormat, HttpMethodType httpMethodType, byte[] body, bool rawBody, bool isPhoto) { var rawResponse = string.Empty; this.OAuthConsumer.ResponseType = responseFormat; this.OAuthConsumer.Scheme = AuthorizationSchemeType.QueryString; switch (httpMethodType) { case HttpMethodType.POST: if (rawBody) { this.OAuthConsumer.ResponsePost(uri, body, true, null, null, isPhoto); } else { this.OAuthConsumer.ResponsePost(uri, body); } break; case HttpMethodType.GET: this.OAuthConsumer.ResponseGet(uri, null); break; case HttpMethodType.HEAD: break; case HttpMethodType.PUT: this.OAuthConsumer.ResponsePut(uri, body); break; case HttpMethodType.DELETE: this.OAuthConsumer.ResponseDelete(uri, null, null); break; default: break; } var dateTimeAppend = string.Format("dateFormat={0}&timeZone={1}&{2}={3}", Enum.GetName(typeof(DateFormat), this.DateFormat).ToLower(), this.TimeZone, Constants.MSID_SDK, Constants.API_VERSION); uri += (uri.Contains("?")) ? string.Format("&{0}", dateTimeAppend) : string.Format("?{0}", dateTimeAppend); var httpResponse = this.OAuthConsumer.GetResponse() as HttpWebResponse; if (httpResponse != null) { var statusCode = (int)httpResponse.StatusCode; var streamReader = new StreamReader(httpResponse.GetResponseStream()); var responseBody = streamReader.ReadToEnd(); if (statusCode != 200 && statusCode != 201) { throw new MySpaceException(string.Format("Your request received a response with status code {0}. {1}", statusCode, responseBody), MySpaceExceptionType.REQUEST_FAILED, responseBody); } return(responseBody); } else { throw new MySpaceException("Error making request.", MySpaceExceptionType.REMOTE_ERROR); } }
public abstract string MakeRequest(string uri, ResponseFormatType responseFormat, HttpMethodType httpMethodType, string body);
public ResponseTypeMapping(string mimeType, ResponseFormatType responseFormatType) { MimeType = mimeType; ResponseFormatType = responseFormatType; }
public override string MakeRequest(string uri, ResponseFormatType responseFormat, HttpMethodType httpMethodType, string body) { byte[] bodyBytes; if (string.IsNullOrEmpty(body)) { body = string.Empty; } bodyBytes = !string.IsNullOrEmpty(body) ? Encoding.ASCII.GetBytes(body) : null; return this.MakeRequest(uri, responseFormat, httpMethodType, bodyBytes, false); }
public override string MakeRequest(string uri, ResponseFormatType responseFormat, HttpMethodType httpMethodType, byte[] body, bool rawBody, bool isPhoto) { var rawResponse = string.Empty; if (this.AccessToken == null && string.IsNullOrEmpty(this.OAuthTokenKey) && string.IsNullOrEmpty(this.OAuthTokenSecret)) throw new QzoneException("Can not make a request to a Protected Resource without a valid OAuth Access Token Key and Secret", QzoneExceptionType.TOKEN_REQUIRED); if (this.AccessToken == null) this.AccessToken = new AccessToken(this.OAuthConsumer, this.OAuthTokenKey, this.OAuthTokenSecret,this.OpenId); this.OAuthConsumer.ResponseType = responseFormat; this.OAuthConsumer.Scheme = AuthorizationSchemeType.QueryString; switch (httpMethodType) { case HttpMethodType.POST: if (rawBody) this.OAuthConsumer.ResponsePost(uri, body, rawBody, this.AccessToken.TokenKey, this.AccessToken.TokenSecret,this.AccessToken.Openid, isPhoto); else this.OAuthConsumer.ResponsePost(uri, body, this.AccessToken.TokenKey, this.AccessToken.TokenSecret,this.AccessToken.Openid); break; case HttpMethodType.GET: this.OAuthConsumer.ResponseGet(uri, this.AccessToken.TokenKey, this.AccessToken.TokenSecret,this.AccessToken.Openid); break; default: break; } var httpResponse = this.OAuthConsumer.GetResponse() as HttpWebResponse; if (httpResponse != null) { var statusCode = (int)httpResponse.StatusCode; var streamReader = new StreamReader(httpResponse.GetResponseStream()); var responseBody = streamReader.ReadToEnd(); if (statusCode != 200 && statusCode != 201) throw new QzoneException(string.Format("Your request received a response with status code {0}. {1}", statusCode, responseBody), QzoneExceptionType.REQUEST_FAILED, responseBody); return responseBody; } else { throw new QzoneException("Error making request.", QzoneExceptionType.REMOTE_ERROR); } }