Ejemplo n.º 1
0
        public async Task <QueryResult> FetchAsync(
            HttpQueryRequest request,
            HttpClient httpClient,
            IEnumerable <IHttpQueryRequestInterceptor> interceptors)
        {
            (string json, HttpResponseMessage message)result =
                await FetchStringAsync(request, httpClient)
                .ConfigureAwait(false);

            QueryResult queryResult = HttpResponseDeserializer.Deserialize(
                JsonConvert.DeserializeObject <JObject>(
                    result.json, _jsonSettings));

            if (interceptors != null)
            {
                foreach (IHttpQueryRequestInterceptor interceptor in
                         interceptors)
                {
                    await interceptor.OnResponseReceivedAsync(
                        request, result.message, queryResult)
                    .ConfigureAwait(false);
                }
            }

            return(queryResult);
        }
Ejemplo n.º 2
0
        private async Task <QueryResult> FetchAsync(
            IReadOnlyQueryRequest request,
            HttpContent requestContent,
            HttpClient httpClient,
            IEnumerable <IHttpQueryRequestInterceptor>?interceptors,
            CancellationToken cancellationToken)
        {
            HttpResponseMessage message =
                await FetchInternalAsync(requestContent, httpClient).ConfigureAwait(false);

            using (Stream stream = await message.Content.ReadAsStreamAsync().ConfigureAwait(false))
            {
                object response = await BufferHelper.ReadAsync(
                    stream,
                    (buffer, bytesBuffered) => ParseJson(buffer, bytesBuffered),
                    cancellationToken)
                                  .ConfigureAwait(false);

                QueryResult queryResult =
                    response is IReadOnlyDictionary <string, object> d
                        ? HttpResponseDeserializer.Deserialize(d)
                        : QueryResult.CreateError(
                        ErrorBuilder.New()
                        .SetMessage("Could not deserialize query response.")
                        .Build());

                if (interceptors is { })
Ejemplo n.º 3
0
        public async Task <QueryResult> FetchAsync(
            HttpQueryRequest request,
            HttpClient httpClient)
        {
            string result = await FetchStringAsync(request, httpClient)
                            .ConfigureAwait(false);

            return(HttpResponseDeserializer.Deserialize(
                       JsonConvert.DeserializeObject <JObject>(result, _jsonSettings)));
        }
Ejemplo n.º 4
0
        public async Task <QueryResult> FetchAsync(
            HttpQueryRequest request,
            HttpClient httpClient,
            IEnumerable <IHttpQueryRequestInterceptor> interceptors)
        {
            HttpResponseMessage message =
                await FetchInternalAsync(request, httpClient)
                .ConfigureAwait(false);

            using (Stream stream = await message.Content.ReadAsStreamAsync()
                                   .ConfigureAwait(false))
            {
                object response = await RequestHelper.ReadAsync(
                    stream,
                    (buffer, bytesBuffered) =>
                    ParseJson(buffer, bytesBuffered))
                                  .ConfigureAwait(false);

                QueryResult queryResult =
                    response is IReadOnlyDictionary <string, object> d
                        ? HttpResponseDeserializer.Deserialize(d)
                        : QueryResult.CreateError(
                        ErrorBuilder.New()
                        .SetMessage(
                            "Could not deserialize query response.")
                        .Build());

                if (interceptors != null)
                {
                    foreach (IHttpQueryRequestInterceptor interceptor in
                             interceptors)
                    {
                        await interceptor.OnResponseReceivedAsync(
                            request, message, queryResult)
                        .ConfigureAwait(false);
                    }
                }

                return(queryResult);
            }
        }