Esempio n. 1
0
        public static async Task <ApiResponse> Delete(this HttpClient client, string url)
        {
            var response = await client.DeleteAsync(url);

            var qr = await QuickResponse.FromMessage(response);

            return(qr.ToApiResponse());
        }
Esempio n. 2
0
        public static async Task <ApiResponse <T> > Post <T>(this HttpClient client, string url, object data)
        {
            var response = await client.PostAsync(url, HttpClientHelpers.GetJsonBody(data));

            var qr = await QuickResponse <T> .FromMessage(response);

            return(qr.ToApiResponse());
        }
Esempio n. 3
0
        public static async Task <ApiResponse <T> > Post <T>(this HttpClient client, string url, Dictionary <string, string> parameters)
        {
            var response = await client.PostAsync(url, HttpClientHelpers.GetPostBody(parameters));

            var qr = await QuickResponse <T> .FromMessage(response);

            return(qr.ToApiResponse());
        }
Esempio n. 4
0
        public static async Task <ApiResponse <T> > Get <T>(this HttpClient client, string url)
        {
            var response = await client.GetAsync(url);

            var qr = await QuickResponse <T> .FromMessage(response);

            return(qr.ToApiResponse());
        }
Esempio n. 5
0
        public static async Task <QuickResponse> FromMessage(HttpResponseMessage message)
        {
            var response = new QuickResponse();

            response.Message      = message;
            response.ResponseBody = await message.Content.ReadAsStringAsync();

            if (!message.IsSuccessStatusCode)
            {
                response.HandleFailedCall();
            }

            return(response);
        }
Esempio n. 6
0
        public static async Task<QuickResponse> FromMessage(HttpResponseMessage message)
        {
            var response = new QuickResponse();
            response.Message = message;
            response.ResponseBody = await message.Content.ReadAsStringAsync();

            if (!message.IsSuccessStatusCode)
            {
                try
                {
                    response.Errors = JsonConvert.DeserializeObject<List<ApiError>>(response.ResponseBody);
                }
                catch (Exception ex)
                {
                    response.Errors.Add(new ApiError()
                    {
                        ErrorMessage = response.ResponseBody
                    });
                }
            }

            return response;
        }