Exemplo n.º 1
0
        public async Task <CulqiResponse> MakeRequestAsync(CulqiRequest request, CancellationToken cancellationToken = default)
        {
            Exception           requestException = null;
            HttpResponseMessage response         = null;

            requestException = null;

            var httpRequest = BuildRequestMessage(request);

            try
            {
                response = await httpClient.SendAsync(httpRequest, cancellationToken)
                           .ConfigureAwait(false);
            }
            catch (HttpRequestException exception)
            {
                requestException = exception;
            }
            catch (OperationCanceledException exception)
                when(!cancellationToken.IsCancellationRequested)
                {
                    requestException = exception;
                }

            if (requestException != null)
            {
                throw requestException;
            }

            string contentResponse = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            return(new CulqiResponse(response.StatusCode, response.Headers, contentResponse));
        }
Exemplo n.º 2
0
        private HttpRequestMessage BuildRequestMessage(CulqiRequest request)
        {
            var requestMessage = new HttpRequestMessage(request.Method, request.Uri);

            requestMessage.Headers.Authorization = request.AuthorizationHeader;
            requestMessage.Content = request.Content;
            return(requestMessage);
        }
Exemplo n.º 3
0
        public async Task <T> RequestAsync <T>(
            HttpMethod method,
            string path,
            BaseOptions options,
            RequestOptions requestOptions,
            CancellationToken cancellationToken = default) where T : ICulqiEntity
        {
            var request  = new CulqiRequest(this, method, path, options, requestOptions);
            var response = await HttpClient.MakeRequestAsync(request, cancellationToken)
                           .ConfigureAwait(false);

            return(ProcessResponse <T>(response));
        }