public dynamic Build() { _contentType = _contentType ?? "application/xml"; _acceptType = _acceptType ?? "application/xml"; if (_noAcceptHeader){ _acceptType = string.Empty; } if (_requestBuilder == null) { _requestBuilder = new HttpVerbRequestBuilder(new RequestFactory()); } if (_responseProcessor == null) { var serviceType = _acceptType.Contains("xml") ? RestService.Xml : (_acceptType.Contains("json") ? RestService.Json : RestService.Binary); if (_noAcceptHeader){ serviceType = RestService.Xml; } this._responseProcessor = new ResponseProcessor(new StandardResultBuilder(serviceType)); } _requestBuilder.Uri = _uri; _requestBuilder.ContentType = _contentType; _requestBuilder.AcceptHeader = _acceptType; _requestBuilder.Body = _body; _requestBuilder.SetOAuth2AuthorizationHeader(_token); _requestBuilder.AllowAutoRedirect = _autoRedirect; if(!string.IsNullOrEmpty(_acceptEncodingType)) { _requestBuilder.AddHeader(HttpRequestHeader.AcceptEncoding, _acceptEncodingType); } if(_ifModifiedSince.HasValue) { _requestBuilder.IfModifiedSince(_ifModifiedSince.Value); } foreach (var header in _headers) { _requestBuilder.AddHeader(header.Key, header.Value); } foreach (var header in _customHeaders) { _requestBuilder.AddCustomHeader(header.Key, header.Value); } return new RestClient(_requestBuilder, _responseProcessor); }
private RestOperation PerformOperationAsync(string operationName, IProcessResponses responseProcessor, params object[] args) { JsonObject argsObject = null; if ((args != null) && (args.Length != 0)) { argsObject = (JsonObject)args[0]; } var operation = new RestOperation(); IHttpRequest webRequest = _requestBuilder.CreateRequest(operationName, argsObject); webRequest.BeginGetResponse(ar => InterpretResponse(responseProcessor, operation, () => webRequest.EndGetResponse(ar)), null); return(operation); }
private void InterpretResponse(IProcessResponses responseProcessor, RestOperation operation, Func <IHttpResponse> returnsResponse) { try { var webResponse = returnsResponse(); responseProcessor.Process(webResponse, operation); _responseHeaders.Add(webResponse.Headers); } catch (WebException webException) { if (webException.Status != WebExceptionStatus.ProtocolError) { throw; } var response = (HttpWebResponse)webException.Response; var responseWrapper = new HttpWebResponseWrapper(response); responseProcessor.Process(responseWrapper, operation); _responseHeaders.Add(response.Headers); } }
public RestClient(IBuildRequests requestBuilder, IProcessResponses responseProcessor) { _responseProcessor = responseProcessor; _requestBuilder = requestBuilder; }
private RestOperation PerformOperationAsync(string operationName, IProcessResponses responseProcessor, params object[] args) { JsonObject argsObject = null; if ((args != null) && (args.Length != 0)) { argsObject = (JsonObject)args[0]; } var operation = new RestOperation(); IHttpRequest webRequest = _requestBuilder.CreateRequest(operationName, argsObject); webRequest.BeginGetResponse(ar => InterpretResponse(responseProcessor, operation, () => webRequest.EndGetResponse(ar)), null); return operation; }
private void InterpretResponse(IProcessResponses responseProcessor, RestOperation operation, Func<IHttpResponse> returnsResponse) { try { var webResponse = returnsResponse(); responseProcessor.Process(webResponse, operation); _responseHeaders.Add(webResponse.Headers); } catch (WebException webException) { if (webException.Status != WebExceptionStatus.ProtocolError) { throw; } var response = (HttpWebResponse) webException.Response; var responseWrapper = new HttpWebResponseWrapper(response); responseProcessor.Process(responseWrapper, operation); _responseHeaders.Add(response.Headers); } }
public RestClient(IBuildRequests requestBuilder, IProcessResponses responseProcessor) { _responseProcessor = responseProcessor; _requestBuilder = requestBuilder; }
public IRestClientBuilder WithResponseProcessor(IProcessResponses responseProcessor) { _responseProcessor = responseProcessor; return this; }
public dynamic Build() { _timeout = _timeout == 0 ? 100000 : _timeout; // default timeout i the CLR is 100s _contentType = _contentType ?? "application/xml"; _acceptType = _acceptType ?? "application/xml"; if (_noAcceptHeader) { _acceptType = string.Empty; } if (_requestBuilder == null) { _requestBuilder = new HttpVerbRequestBuilder(new RequestFactory()); } if (_responseProcessor == null) { var serviceType = _acceptType.Contains("xml") ? RestService.Xml : _acceptType.Contains("json") ? RestService.Json : _acceptType.EndsWith("plain") ? RestService.Text: RestService.Binary; if (_noAcceptHeader) { serviceType = RestService.Xml; } this._responseProcessor = new ResponseProcessor(new StandardResultBuilder(serviceType)); } if (_proxy != null) { _requestBuilder.Proxy = _proxy; } _requestBuilder.Uri = _uri; _requestBuilder.ContentType = _contentType; _requestBuilder.AcceptHeader = _acceptType; _requestBuilder.Body = _body; _requestBuilder.AllowAutoRedirect = _autoRedirect; _requestBuilder.UserAgent = _userAgent; _requestBuilder.Timeout = _timeout; if (!string.IsNullOrEmpty(_token)) { _requestBuilder.SetOAuth2AuthorizationHeader(_token); } if (!string.IsNullOrEmpty(_acceptEncodingType)) { _requestBuilder.AddHeader(HttpRequestHeader.AcceptEncoding, _acceptEncodingType); } if (_ifModifiedSince.HasValue) { _requestBuilder.IfModifiedSince(_ifModifiedSince.Value); } foreach (var header in _headers) { _requestBuilder.AddHeader(header.Key, header.Value); } foreach (var header in _customHeaders) { _requestBuilder.AddCustomHeader(header.Key, header.Value); } return(new RestClient(_requestBuilder, _responseProcessor)); }
public IRestClientBuilder WithResponseProcessor(IProcessResponses responseProcessor) { _responseProcessor = responseProcessor; return(this); }