private static IEnumerable <PostmarkResponse> GetPostmarkResponsesImpl(RestResponseBase response) { var results = TryGetPostmarkResponses(response) ?? new List <PostmarkResponse> { new PostmarkResponse { Status = PostmarkStatus.Unknown, Message = response.StatusDescription } }; foreach (var result in results) { switch ((int)response.StatusCode) { case 200: result.Status = PostmarkStatus.Success; break; case 401: case 422: result.Status = PostmarkStatus.UserError; break; case 500: result.Status = PostmarkStatus.ServerError; break; } } return(results); }
private static PostmarkResponse GetPostmarkResponseImpl(RestResponseBase response) { var result = TryGetPostmarkResponse(response) ?? new PostmarkResponse { Status = PostmarkStatus.Unknown, Message = response.StatusDescription }; switch ((int)response.StatusCode) { case 200: result.Status = PostmarkStatus.Success; break; case 401: case 422: result.Status = PostmarkStatus.UserError; break; case 500: result.Status = PostmarkStatus.ServerError; break; } return(result); }
public override T Deserialize <T>(RestResponseBase response) { var token = JToken.FromObject(response.Content); return(token.Type == JTokenType.Array ? DeserializeCollection <T>(token) : DeserializeSingle <T>(response.Content)); }
public virtual object Deserialize(RestResponseBase response, Type type) { using (var stringReader = new StringReader(response.Content)) { using (var jsonTextReader = new JsonTextReader(stringReader)) { return(_serializer.Deserialize(jsonTextReader, type)); } } }
public virtual T Deserialize <T>(RestResponseBase response) { using (var stringReader = new StringReader(response.Content)) { using (var jsonTextReader = new JsonTextReader(stringReader)) { return(_serializer.Deserialize <T>(jsonTextReader)); } } }
public virtual object Deserialize(RestResponseBase response, Type type) { object instance; var serializer = CacheOrGetSerializerFor(type); using (var reader = new StringReader(response.Content)) { instance = serializer.Deserialize(reader); } return(instance); }
public virtual object Deserialize(RestResponseBase response, Type type) { object instance; using (var stream = new MemoryStream(ContentEncoding.GetBytes(response.Content))) { var serializer = CacheOrGetSerializerFor(type); instance = serializer.ReadObject(stream); } return(instance); }
public string Request(string resource, HttpMethod method, object requestBody = null, bool disableValidation = false) { InitializeRequest(resource, method, requestBody); resp = (RestResponse)clnt.Execute(req); if (!disableValidation) { validateResponse(); } return(resp.Content); }
public virtual T Deserialize <T>(RestResponseBase response) { T instance; var serializer = CacheOrGetSerializerFor(typeof(T)); using (var reader = new StringReader(response.Content)) { instance = (T)serializer.Deserialize(reader); } return(instance); }
public virtual T Deserialize <T>(RestResponseBase response) { var type = typeof(T); T instance; using (var stream = new MemoryStream(ContentEncoding.GetBytes(response.Content))) { var serializer = CacheOrGetSerializerFor(type); instance = (T)serializer.ReadObject(stream); } return(instance); }
public T Request <T>(string resource, HttpMethod method, object requestBody = null, bool disableValidation = false) where T : new() { InitializeRequest(resource, method, requestBody); resp = (RestResponse <T>)clnt.Execute <T>(req); if (!disableValidation) { validateResponse(); } return(((RestResponse <T>)resp).Data); }
public virtual T Deserialize <T>(RestResponseBase response) { using (var stringReader = new StringReader(response.Content)) { var xmlRoot = XElement.Load(stringReader); var serializer = CacheOrGetSerializerFor(typeof(T)); using (var reader = xmlRoot.CreateReader()) { return((T)serializer.ReadObject(reader)); } } }
public override T Deserialize <T>(RestResponseBase response) { if (response == null) { return(default(T)); } if ((int)response.StatusCode >= 500) { return(default(T)); } var content = response.Content; return(DeserializeContent <T>(content)); }
private static IEnumerable <PostmarkResponse> TryGetPostmarkResponses(RestResponseBase response) { IEnumerable <PostmarkResponse> result = null; var statusCode = (int)response.StatusCode; if (statusCode == 200 || statusCode == 401 || statusCode == 422 || statusCode == 500) { try { result = JsonConvert.DeserializeObject <IEnumerable <PostmarkResponse> >(response.Content, _settings); } catch (JsonReaderException) { result = null; } } return(result); }
public override T Deserialize <T>(RestResponseBase response) { if (response == null) { return(default(T)); } if ((int)response.StatusCode >= 500) { return(default(T)); } var content = response.Content; if (content.Equals("END STREAMING")) { return((T)(ITwitterModel) new TwitterUserStreamEnd()); } return((T)DeserializeContent(content, typeof(T))); }
public ServerRequestAsyncHandle RequestAsync(string resource, HttpMethod method, Action <string> callback, object requestBody = null, bool disableValidation = false) { InitializeRequest(resource, method, requestBody); RestRequestAsyncHandle handle = clnt.ExecuteAsync(req, response => { resp = (RestResponseBase)response; if (resp.ResponseStatus == ResponseStatus.Aborted) { return; } if (!disableValidation) { validateResponse(); } callback(response.Content); }); return(new ServerRequestAsyncHandle(handle)); }
public Task <T> RequestAsync <T>(string resource, HttpMethod method, CancellationToken?cancelToken = null, object requestBody = null, bool disableValidation = false) { InitializeRequest(resource, method, requestBody); //var resp = clnt.ExecuteTaskAsync<T>(req, cancelToken.GetValueOrDefault()).Result; return(clnt.ExecuteTaskAsync <T>(req, cancelToken.GetValueOrDefault()) .ContinueWith((x) => { try { resp = (RestResponse <T>)x.Result; if (!disableValidation) { validateResponse(); } return ((RestResponse <T>)resp).Data; } catch (AggregateException ex) when(ex.InnerException is OperationCanceledException) { throw new TaskCanceledException(x); } })); }
private void InitializeRequest(string resource, HttpMethod method, object requestBody) { resp = null; clnt = new RestClient(ServerPath); clnt.AddHandler("application/json", new AdvancedDeserializer()); req = new RestRequest(resource, (RestSharp.Method)method); req.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; }; req.Timeout = 1800000; //30 minutes if (requestBody != null) { req.AddJsonBody(requestBody); } if (!string.IsNullOrWhiteSpace(SessionToken)) { req.AddHeader(HEADER_TOKEN_KEY, SessionToken); } if (!string.IsNullOrWhiteSpace(CustomDatabaseKey)) { req.AddHeader(HEADER_DBSELECTION, CustomDatabaseKey); } }
private void SetResponse(RestResponseBase response) { Response = new TwitterResponse(response); }
public virtual dynamic DeserializeDynamic(RestResponseBase response) { var result = Deserialize <dynamic>(response); return(result); }
public dynamic DeserializeDynamic(RestResponseBase response) { throw new NotSupportedException(); }
public abstract object Deserialize(RestResponseBase response, Type type);
// internal coz, need to hide the RestResponse internal FacebookRequestException(string message, RestResponseBase response) : base(message) { _response = response ?? new RestResponse(); }
internal FacebookRequestException(RestResponseBase response) : this("Error occured while processing your Facebook request.", response) { }
public abstract T Deserialize <T>(RestResponseBase response);
internal BitlyResponse(RestResponseBase response, Exception exception = null) { this.response = response; this.exception = exception; }
internal TwitterResponse(RestResponseBase response, Exception exception = null) { _exception = exception; _response = response; }
private void SetResponse(RestResponseBase response) { Response = new BitlyResponse(response); }
public override object Deserialize(RestResponseBase response, Type type) { return(DeserializeJson(response.Content, type)); }
public override T Deserialize <T>(RestResponseBase response) { if (response == null) { return(default);