Exemplo n.º 1
0
        private RestApiResponse <TError> ProcessResponse <TError>(HttpResponseMessage response)
        {
            RestApiResponse <TError> restClientResponse = new RestApiResponse <TError>();

            restClientResponse.IsSuccessStatusCode = response.IsSuccessStatusCode;

            int statusCode = (int)response.StatusCode;

            restClientResponse.StatusCode = statusCode;

            restClientResponse.Error = ProcessErrorResponse <TError>(response);

            return(restClientResponse);
        }
Exemplo n.º 2
0
        protected virtual async Task <RestApiResponse <TError> > DeleteAsync <TError>(string url, Dictionary <string, string> headers = null)
        {
            RestApiResponse <TError> restClientResponse = new RestApiResponse <TError>();

            using (HttpClient httpClient = GetHttpClient(headers))
            {
                url = url ?? BaseUrl;
                HttpResponseMessage response = await HttpInvoker(() => httpClient.DeleteAsync(url));

                restClientResponse = ProcessResponse <TError>(response);
            }

            return(restClientResponse);
        }
Exemplo n.º 3
0
        private async Task <RestApiResponse <TResponse, TError> > GetResponseAsync <TRequest, TResponse, TError>(string method, TRequest request, string url, Dictionary <string, string> headers)
        {
            RestApiResponse <TResponse, TError> restClientResponse = new RestApiResponse <TResponse, TError>();

            using (HttpClient httpClient = GetHttpClient(headers))
            {
                url = url ?? BaseUrl;
                HttpContent        content        = GetStringContent(request, headers);
                HttpRequestMessage requestMessage = new HttpRequestMessage(new HttpMethod(method), url)
                {
                    Content = content
                };

                HttpResponseMessage response = await HttpInvoker(() => httpClient.SendAsync(requestMessage));

                restClientResponse = ProcessResponse <TResponse, TError>(response);
            }

            return(restClientResponse);
        }