/// <inheritdoc/> public async Task <IDictionary <long, ProductStatus> > GetStatusesAsync(IDictionary <long, string> productList, CancellationToken cancellationToken) { var result = new Dictionary <long, ProductStatus>(); var batchRequest = new ProductstatusesCustomBatchRequest { Entries = new List <ProductstatusesCustomBatchRequestEntry>() }; foreach (var item in productList) { var entry = new ProductstatusesCustomBatchRequestEntry { BatchId = item.Key, MerchantId = _options.MerchantId, Method = "get", ProductId = item.Value }; batchRequest.Entries.Add(entry); } var response = await _contentService.Productstatuses.Custombatch(batchRequest).ExecuteAsync(cancellationToken); if (response.Kind == "content#productstatusesCustomBatchResponse") { for (var i = 0; i < response.Entries.Count; i++) { var productStatus = response.Entries[i].ProductStatus; result.Add(response.Entries[i].BatchId ?? 0, productStatus); } } else { _logger.LogDebug("There was an error. Response: {responseCode}", response.ToString()); } return(result); }
/// <summary> /// Gets the statuses of multiple products in a single request. This method can only be called for non-multi-client accounts. /// Documentation https://developers.google.com/shoppingcontent/v2/reference/productstatuses/custombatch /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated ShoppingContent service.</param> /// <param name="body">A valid ShoppingContent v2 body.</param> /// <returns>ProductstatusesCustomBatchResponseResponse</returns> public static ProductstatusesCustomBatchResponse Custombatch(ShoppingContentService service, ProductstatusesCustomBatchRequest body) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } // Make the request. return(service.Productstatuses.Custombatch(body).Execute()); } catch (Exception ex) { throw new Exception("Request Productstatuses.Custombatch failed.", ex); } }
/// <summary> /// Gets the statuses of multiple products in a single request. This method can only be called for non-multi-client accounts. /// Documentation https://developers.google.com/shoppingcontent/v2/reference/productstatuses/custombatch /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Shoppingcontent service.</param> /// <param name="body">A valid Shoppingcontent v2 body.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>ProductstatusesCustomBatchResponseResponse</returns> public static ProductstatusesCustomBatchResponse Custombatch(ShoppingcontentService service, ProductstatusesCustomBatchRequest body, ProductstatusesCustombatchOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } // Building the initial request. var request = service.Productstatuses.Custombatch(body); // Applying optional parameters to the request. request = (ProductstatusesResource.CustombatchRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request Productstatuses.Custombatch failed.", ex); } }