public async Task <GeocodeBatchResponse> GetGeocodeBatchAsync(
            GeocodeBatchRequest request)
        {
            if (request is null)
            {
                return(null);
            }

            if (request.Addresses.Count() > MaxBatchCount)
            {
                throw new InvalidOperationException($"You're attempting to batch geocode {request.Addresses.Count()} addresses, which is more than the permitted limit of {MaxBatchCount}");
            }

            var response = await GetResponseAsync(request);

            return(JsonConvert.DeserializeObject <GeocodeBatchResponse>(response));
        }
예제 #2
0
        /// <summary>
        /// Geocode a batch of addresses.
        /// </summary>
        /// <param name="request">A GeocodeRequest instance.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>GeocodeBatchResponse</returns>
        public async Task <GeocodeBatchResponse> GeocodeBatchAsync(
            GeocodeBatchRequest request,
            CancellationToken cancellationToken = default)
        {
            if (request is null)
            {
                return(InvalidResponse <GeocodeBatchResponse>());
            }

            if (request.Addresses.Count() > MaxBatchSize)
            {
                return(InvalidBatchSizeResponse <GeocodeBatchResponse>());
            }

            if (cancellationToken.IsCancellationRequested)
            {
                return(CancelledResponse2 <GeocodeBatchResponse>());
            }

            return(await RequestAsync <GeocodeBatchResponse>(request, cancellationToken).ConfigureAwait(false));
        }