Ejemplo n.º 1
0
        internal async Task <UberTime> GetTimeEstimate(CancellationToken ct, Guid productId, Coordinate startLocation)
        {
            string url = baseUri.ToString() + "/estimates/time?server_token=" + serverToken + "&start_latitude=" + startLocation.Latitude.ToString(CultureInfo.InvariantCulture) + "&start_longitude=" + startLocation.Longitude.ToString(CultureInfo.InvariantCulture) + "&product_id=" + productId.ToString();

            RestResponse response = await RestService.Get(ct, url);

            if (response.Success)
            {
                var getTimesJsonWrapper = JsonConvert.DeserializeObject <UberTimeResultWrapper>(response.Data);

                return(ResultBuilder.BuildUberTimeResult(getTimesJsonWrapper.Times.FirstOrDefault(x => x.product_id == productId)));
            }
            else if (!response.IsException)
            {
                response.Error.HandleError(this.GetType().Name, MethodBase.GetCurrentMethod().Name);

                return(null);
            }
            else
            {
                throw new Exception(response.Data);
            }
        }
Ejemplo n.º 2
0
        internal async Task <IEnumerable <UberPrice> > GetPriceEstimates(CancellationToken ct, Coordinate startLocation, Coordinate endLocation)
        {
            string url = baseUri.ToString() + "/estimates/price?server_token=" + serverToken + "&start_latitude=" + startLocation.Latitude.ToString(CultureInfo.InvariantCulture) + "&start_longitude=" + startLocation.Longitude.ToString(CultureInfo.InvariantCulture) + "&end_latitude=" + endLocation.Latitude.ToString(CultureInfo.InvariantCulture) + "&end_longitude=" + endLocation.Longitude.ToString(CultureInfo.InvariantCulture);

            RestResponse response = await RestService.Get(ct, url);

            if (response.Success)
            {
                var getPricesJsonWrapper = JsonConvert.DeserializeObject <UberPriceResultWrapper>(response.Data);

                return(ResultBuilder.BuildUberPriceResult(getPricesJsonWrapper.Prices));
            }
            else if (!response.IsException)
            {
                response.Error.HandleError(this.GetType().Name, MethodBase.GetCurrentMethod().Name);

                return(null);
            }
            else
            {
                throw new Exception(response.Data);
            }
        }