コード例 #1
0
        /// <summary>
        /// This endpoint returns a list of GeoJSON-valid FeatureCollection objects representing all of our active delivery zones.
        ///
        /// Coordinates will be in the format[longitude, latitude].
        ///
        /// Our zones are not bound by zip code borders.If you need to check to see if an address is within a given zone, use the Delivery Quote endpoint.
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <IEnumerable <FeatureCollection> > GetDeliveryZonesAsync(CancellationToken cancellationToken = default)
        {
            var response = await _jsonClient.GetUnsafeAsync("/v1/delivery_zones", cancellationToken : cancellationToken);

            if (response.IsSuccess)
            {
                return(response.As <IEnumerable <FeatureCollection> >());
            }
            else
            {
                var args = response.As <PostmatesExceptionArgs>();
                throw PostmatesExceptionThrower.GetException(args);
            }
        }
コード例 #2
0
        /// <summary>
        /// Cancel an ongoing delivery. A delivery can only be canceled prior to a courier completing pickup.
        /// Delivery fees still apply.
        /// </summary>
        public async Task <PostmatesDelivery> CancelDeliveryAsync(string deliveryId, CancellationToken cancellationToken = default)
        {
            var response = await _jsonClient.PostUnsafeAsync(FormatPath($"deliveries/{deliveryId}/cancel"), null);

            if (response.IsSuccess)
            {
                return(response.As <PostmatesDelivery>());
            }
            else
            {
                var args = response.As <PostmatesExceptionArgs>();
                throw PostmatesExceptionThrower.GetException(args);
            }
        }
コード例 #3
0
        /// <summary>
        /// Converts JSON to a application/x-www-form-urlencoded before POSTing to the Postmates API.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="url"></param>
        /// <param name="_object"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <T> PostFormAsync <T>(string url, dynamic _object, CancellationToken cancellationToken = default)
        {
            var payloadString = "";
            var first         = true;

            //dynamic data = JObject.Parse(_object);

            dynamic data = JObject.FromObject(_object);

            foreach (var descriptor in TypeDescriptor.GetProperties(data))
            {
                var key   = descriptor.Name;
                var value = descriptor.GetValue(data).Value;
                if (value is null)
                {
                    continue;
                }
                if (!(value is string))
                {
                    value = (descriptor.GetValue(data) == null) ? null : JsonConvert.SerializeObject(descriptor.GetValue(data),
                                                                                                     Newtonsoft.Json.Formatting.None,
                                                                                                     _jsonSettings);
                    value = (string)value.Trim('"');
                }
                if (!string.IsNullOrEmpty(value))
                {
                    if (!first)
                    {
                        payloadString += "&";
                    }
                    payloadString += $"{key}={value}";
                    first          = false;
                }
            }

            var payload = new JsonClientPayload("application/x-www-form-urlencoded", payloadString);

            var response = await _jsonClient.PostUnsafeAsync(url, payload);

            if (response.IsSuccess)
            {
                return(response.As <T>());
            }
            else
            {
                var args = response.As <PostmatesExceptionArgs>();
                throw PostmatesExceptionThrower.GetException(args);
            }
        }