public async Task <IApiResponse <TPlainResponse> > SendAsync <TPlainResponse>(Uri uri, ClientRequest request) where TPlainResponse : PlainResponse, new() { Ensure.ArgumentNotNull(uri, "uri"); Ensure.ArgumentNotNull(request, "request"); var apiRequest = new ApiRequest(uri, request.GetPlain()); _authenticator.Apply(apiRequest); var response = await ExecuteAsync(apiRequest).ConfigureAwait(false); if (!response.IsXml()) { throw new InvalidResponseApiException($"Expected xml content but received '{response.ContentType}'", response); } HandleErrors(response); if (!_authenticator.Satisfies(response)) { throw new InvalidResponseApiException("Response signature is invalid", response); } var apiResponse = _xmlPipeline.Deserialize <TPlainResponse>(response); return(apiResponse); }
private WebAgent ResolveWebAgent() { var webAgent = new WebAgent(); _authenticator.Apply(webAgent); Authenticated = true; return(webAgent); }
// THIS IS THE METHOD THAT EVERY REQUEST MUST GO THROUGH! async Task <IResponse> RunRequest(IRequest request, CancellationToken cancellationToken) { await _authenticator.Apply(request).ConfigureAwait(false); var response = await _httpClient.Send(request, cancellationToken).ConfigureAwait(false); HandleErrors(response); return(response); }
public CallbackResponse EncodeResponse(ApiCallbackResponse response) { _authenticator.Apply(response); var content = _xmlPipeline.Serialize(response); return(new CallbackResponse { Content = content }); }
async Task <IResponse> RunRequest(IRequest request) { request.Headers.Add("User-Agent", UserAgent); SerializeRequest(request); await _authenticator.Apply(request).ConfigureAwait(false); var response = await _httpClient.Send(request).ConfigureAwait(false); return(response); }
private async Task <IResponse> RunRequest(Request request, CancellationToken cancellationToken) { request.Headers.Add("User-Agent", UserAgent); await _authenticator.Apply(request).ConfigureAwait(false); var response = await _httpClient.Send(request, cancellationToken).ConfigureAwait(false); HandleErrors(response); return(response); }
// THIS IS THE METHOD THAT EVERY REQUEST MUST GO THROUGH! async Task <IResponse <T> > RunRequest <T>(IRequest request, CancellationToken cancellationToken) { request.Headers.Add("User-Agent", UserAgent); await _authenticator.Apply(request).ConfigureAwait(false); var response = await _httpClient.Send <T>(request, cancellationToken).ConfigureAwait(false); ApiInfoParser.ParseApiHttpHeaders(response); HandleErrors(response); return(response); }
// THIS IS THE METHOD THAT EVERY REQUEST MUST GO THROUGH! async Task <IResponse <T> > RunRequest <T>(IRequest request) { request.Headers.Add("User-Agent", UserAgent); await _authenticator.Apply(request); var response = await _httpClient.Send <T>(request); ApiInfoParser.ParseApiHttpHeaders(response); HandleErrors(response); return(response); }
// THIS IS THE METHOD THAT EVERY REQUEST MUST GO THROUGH! async Task <IResponse> RunRequest(IRequest request, CancellationToken cancellationToken) { request.Headers.Add("User-Agent", UserAgent); await _authenticator.Apply(request).ConfigureAwait(false); var response = await _httpClient.Send(request, cancellationToken).ConfigureAwait(false); if (response != null) { // Use the clone method to avoid keeping hold of the original (just in case it effect the lifetime of the whole response _lastApiInfo = response.ApiInfo.Clone(); } HandleErrors(response); return(response); }
private void SetRequest(IRequest request) { Authenticator?.Apply(this); request.Timeout = Timeout; if (AllowAutoRedirect) { request.AddObserver(new AutoRedictObserver()); } request.AddHeader("content-type", ContentType); foreach (var header in _initHeaders) { request.AddHeader(header.Name, header.Value); } request.AddObserver(this); foreach (var observer in _observer) { request.AddObserver(observer); } foreach (var cookie in Cookies) { request.Cookies.AddOrUpdate(cookie.Name, cookie.Value); } }