Ejemplo n.º 1
0
        /// <summary>
        /// Request Google Directions
        /// <param name="request">Request object</param>
        /// <returns>The response model</returns>
        /// </summary>
        public async Task <OperationResult <DirectionsResponse> > RequestDirections(DirectionsRequest request)
        {
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("Content-Type", "application/json;charset=utf-8");

                var result = DirectionsUrlFactory.BuildDirectionsUrl(request, _apiKey);
                if (result.IsSuccessful)
                {
                    var fullUrlString  = result.Result;
                    var responseString = await client.GetStringAsync(fullUrlString);

                    return(await ProcessResponse(responseString));
                }
                else
                {
                    return(OperationResult <DirectionsResponse> .AsFailure(result.Exception));
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Request Google Directions
        /// <param name="request">Request object</param>
        /// <returns>The response model</returns>
        /// </summary>
        public async Task <OperationResult <DirectionsResponse> > RequestDirections(DirectionsRequest request)
        {
            using (var client = new HttpClient())
            {
                AcceptJsonResponse(client);
                var result = DirectionsUrlFactory.BuildDirectionsUrl(request, _apiKey);
                if (result.IsSuccessful)
                {
                    var fullUrlString = result.Result;
                    var response      = await client.GetAsync(fullUrlString).ConfigureAwait(false);

                    if (!response.IsSuccessStatusCode)
                    {
                        return(OperationResult <DirectionsResponse> .AsFailure(response.ReasonPhrase));
                    }

                    var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    return(await ProcessResponse(content));
                }

                return(OperationResult <DirectionsResponse> .AsFailure(result.Exception));
            }
        }