From f37b25a53752623b1ed5ee8b0f2f307ca05f5444 Mon Sep 17 00:00:00 2001 From: Jesse Evers Date: Fri, 26 May 2023 17:23:13 -0400 Subject: [PATCH] Initial version of README --- README.md | 182 +++ src/Apis/MP/US/InsightApi.php | 2368 --------------------------------- 2 files changed, 182 insertions(+), 2368 deletions(-) create mode 100644 README.md delete mode 100644 src/Apis/MP/US/InsightApi.php diff --git a/README.md b/README.md new file mode 100644 index 00000000..4e00e2af --- /dev/null +++ b/README.md @@ -0,0 +1,182 @@ +

+ + + +

+ +

+ Total downloads + Latest stable version + License +

+ +## Walmart API for PHP +A PHP library for connecting to Walmart's [Marketplace](https://developer.walmart.com/home/us-mp/), [Drop Ship Vendor](https://developer.walmart.com/home/us-dsv/), [Content Provider](https://developer.walmart.com/home/us-cp/), and [Warehouse Supplier](https://developer.walmart.com/home/us-ws/) APIs, for the US, Canada, and Mexico. + +### Related packages + +* [`jlevers/selling-partner-api`](https://github.com/jlevers/selling-partner-api): A PHP library for Amazon's [Selling Partner API](https://developer-docs.amazon.com/sp-api/docs), with a similar interface to this package. Our most popular package. +* [`highsidelabs/laravel-spapi`](https://github.com/highsidelabs/laravel-spapi): An Laravel wrapper for the package above, making Selling Partner API integration in Laravel projects quick and easy. +* [`highsidelabs/amazon-business-api`](https://github.com/highsidelabs/amazon-business-api): A PHP library for Amazon's [Business API](https://developer-docs.amazon.com/amazon-business/docs), with a near-identical interface to [`jlevers/selling-partner-api`](https://github.com/jlevers/selling-partner-api). + +--- + +**This package is developed and maintained by [Highside Labs](https://highsidelabs.co). If you need support integrating with Walmart's (or any other e-commerce platform's) APIs, we're happy to help! Shoot us an email at [hi@highsidelabs.co](mailto:hi@highsidelabs.co).** + +If you've found any of our packages useful, please consider [becoming a Sponsor](https://github.com/sponsors/highsidelabs), or making a donation via the button below. We appreciate any and all support you can provide! + +--- + +## Features + +* Supports all Walmart API operations for Marketplace Sellers, Drop Ship Vendors, Content Providers, and Warehouse Suppliers as of 5/26/2023 ([see here](#supported-api-segments) for links to documentation for all calls) +* Supports the United States, Canada, and Mexico marketplaces +* Automatically handles all forms of authentication used by Walmart (basic auth, access tokens, and request signatures) with minimal configuration + +## Installation + +`composer require highsidelabs/walmart-api` + +## Why make this library? + +The existing Walmart client libraries for PHP are either incomplete, outdated, or both. This library aims to provide a complete, up-to-date, and easy-to-use interface for all of Walmart's APIs. We built it to scratch our own itch. + + +## Table of Contents + + + + + +## Getting Started + +### Prerequisites + +You need a couple things to get started: +* A Walmart Seller and/or Supplier account +* A Walmart Client ID/Client secret pair, and/or a Walmart Consumer ID and private key + +### Setup + +The [`Configuration`](https://github.com/highsidelabs/walmart-api/blob/main/src/Configuration.php) constructor takes three arguments, which cover all the credentials you need to access the Walmart APIs: +* A client ID +* A client secret +* An optional array of additional configuration parameters + +```php +use Walmart\Configuration; + +$clientId = ''; +$clientSecret = ''; +$config = new Walmart\Configuration($clientId, $clientSecret); +``` + +If you are a Marketplace Seller selling in the US (which is likely true of most people using this API), that's all the configuration you need to do to start making calls to the Marketplace API. If you want to call the Drop Ship Vendor, Content Provider, or Warehouse Supplier APIs, or if you sell goods outside the US and need to make calls to the Marketplace API for, you'll need to provide additional configuration parameters, which are detailed in the [Configuration](#configuration) section below. + +### Basic Usage + +Once you've created an instance of the `Configuration` class, you can start making calls to the Walmart APIs. The `Walmart` class provides an easy interface for retrieving an instance of any API class, from any of the four major API categories (Marketplace, Drop Ship Vendor, Content Provider, Warehouse Supplier). For example, to retrieve an instance of the Marketplace `Authentication` API and check the status of your authentication token, you can do the following: + +```php +use Walmart\Configuration; +use Walmart\Walmart; + +$config = new Walmart\Configuration($clientId, $clientSecret); +$authApi = Walmart::marketplace($config)->auth(); + +// $authApi is an instance of Walmart\Apis\MP\US\AuthenticationApi +$tokenDetail = $authApi->getTokenDetail(); +$tokenStatus = $tokenDetail->isValid; +var_dump($tokenStatus); +``` + +Similarly, the other API categories can be accessed via the `Walmart::dropShipVendor()`, `Walmart::contentProvider()`, and `Walmart::warehouseSupplier()` methods. + + +### Debug mode + +To get debugging output when you make an API request, you can call `$config->setDebug()`. By default, debug output goes to `stdout` via `php://output`, but you can redirect it a file with `$config->setDebugFile('log/file/path.log')`. + +```php +require_once __DIR__ . '/vendor/autoload.php'; + +use Walmart\Configuration; + +$config = new Configuration($clientId, $clientSecret); +$config->setDebug(true); +// To redirect debug info to a file: +$config->setDebugFile('debug.log'); +``` + + +## Supported API segments + +This is an exhaustive list of all the APIs supported by this library, organized by API category and marketplace. For more information on each API, see the [Walmart Developer Portal](https://developer.walmart.com/). + +### Marketplace + +##### United States +* [Authentication API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/US/AuthenticationApi.md) +* [Feeds API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/US/FeedsApi.md) +* [Fulfillment API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/US/FulfillmentApi.md) +* [Insights API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/US/InsightsApi.md) +* [Inventory API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/US/InventoryApi.md) +* [Items API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/US/ItemsApi.md) +* [Lag Time API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/US/LagTimeApi.md) +* [Listing Quality API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/US/ListingQualityApi.md) +* [Notifications API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/US/NotificationsApi.md) +* [On Request Reports API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/US/OnRequestReportsApi.md) +* [Orders API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/US/OrdersApi.md) +* [Prices API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/US/PricesApi.md) +* [Promotions API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/US/PromotionsApi.md) +* [Reports API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/US/ReportsApi.md) +* [Returns API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/US/ReturnsApi.md) +* [Rules API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/US/RulesApi.md) +* [Settings API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/US/SettingsApi.md) +* [Utilities API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/US/UtilitiesApi.md) + +##### Canada +* [Events API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/CA/Api.md) +* [Feeds API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/CA/FeedsApi.md) +* [International Shipping API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/CA/InternationalShippingApi.md) +* [Inventory API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/CA/InventoryApi.md) +* [Items API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/CA/ItemsApi.md) +* [Orders API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/CA/OrdersApi.md) +* [Prices API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/CA/PricesApi.md) +* [Promotions API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/CA/PromotionsApi.md) +* [Reports API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/CA/ReportsApi.md) + +##### Mexico +* [Authentication API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/MX/AuthenticationApi.md) +* [Feeds API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/MX/FeedsApi.md) +* [International Shipping API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/MX/InternationalShippingApi.md) +* [Inventory API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/MX/InventoryApi.md) +* [Items API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/MX/ItemsApi.md) +* [Orders API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/MX/OrdersApi.md) +* [Prices API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/MX/PricesApi.md) +* [Reports API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/MX/ReportsApi.md) +* [Returns API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/MP/MX/ReturnsApi.md) + + +### Drop Ship Vendor + +##### United States +* [Cost API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/DSV/US/CostApi.md) +* [Feeds API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/DSV/US/FeedsApi.md) +* [Inventory API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/DSV/US/InventoryApi.md) +* [Items API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/DSV/US/ItemsApi.md) +* [Lag Time API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/DSV/US/LagTimeApi.md) +* [Orders API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/DSV/US/OrdersApi.md) +* [Reports API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/DSV/US/ReportsApi.md) + +### Content Provider + +##### United States +* [Feeds API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/CP/US/FeedsApi.md) + +### Warehouse Supplier + +##### United States +* [Feeds API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/WS/US/FeedsApi.md) +* [Items API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/WS/US/ItemsApi.md) +* [Reports API](https://github.com/highsidelabs/walmart-sdk-php/blob/main/docs/Apis/WS/US/ReportsApi.md) \ No newline at end of file diff --git a/src/Apis/MP/US/InsightApi.php b/src/Apis/MP/US/InsightApi.php deleted file mode 100644 index c7c41d24..00000000 --- a/src/Apis/MP/US/InsightApi.php +++ /dev/null @@ -1,2368 +0,0 @@ - 'application/json', - 'getListingQualityScore' => 'application/json', - 'getProSellerBadgeInfo' => 'application/json', - 'getTrendingResult' => 'application/json', - 'getUnpublishedItemCount' => 'application/json', - 'getUnpublishedItems' => 'application/json', - 'itemsDetailsForListing' => 'application/json', - ]; - - /** - * Operation getCategoriesList - * - * Item count with listing quality issues - * - * @param bool $viewTrendingItems Specify whether or not to include seller's items that are trending in the Listing Quality Score. (optional, default to true) - * @param bool $wfsFlag Specify whether or not to include WFS-eligible items in the overall Listing Quality Score. (optional) - * @param int $hasIssue Specify whether or not to include items that have issues in the Listing Quality Score. (optional, default to 0) - * @param string $type Specify whether to get item count by brand or category. Category is the default value when no type is specified. (optional) - * @param int $limit Specify number of items to return. The value is defaulted to 100 and the maximum value is 1000. (optional) - * @param int $offset Specify the offset of item list to be returned. (optional, default to 0) - * - * @throws \Walmart\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return \Walmart\Models\MP\US\GetCategoriesList200Response - */ - public function getCategoriesList( - ?bool $viewTrendingItems = true, - ?bool $wfsFlag = null, - ?int $hasIssue = 0, - ?string $type = null, - ?int $limit = null, - ?int $offset = 0 - ): \Walmart\Models\MP\US\GetCategoriesList200Response { - return $this->getCategoriesListWithHttpInfo($viewTrendingItems, $wfsFlag, $hasIssue, $type, $limit, $offset); - } - - /** - * Operation getCategoriesListWithHttpInfo - * - * Item count with listing quality issues - * - * @param bool $viewTrendingItems Specify whether or not to include seller's items that are trending in the Listing Quality Score. (optional, default to true) - * @param bool $wfsFlag Specify whether or not to include WFS-eligible items in the overall Listing Quality Score. (optional) - * @param int $hasIssue Specify whether or not to include items that have issues in the Listing Quality Score. (optional, default to 0) - * @param string $type Specify whether to get item count by brand or category. Category is the default value when no type is specified. (optional) - * @param int $limit Specify number of items to return. The value is defaulted to 100 and the maximum value is 1000. (optional) - * @param int $offset Specify the offset of item list to be returned. (optional, default to 0) - * - * @throws \Walmart\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return \Walmart\Models\MP\US\GetCategoriesList200Response - */ - protected function getCategoriesListWithHttpInfo( - ?bool $viewTrendingItems = true, - ?bool $wfsFlag = null, - ?int $hasIssue = 0, - ?string $type = null, - ?int $limit = null, - ?int $offset = 0, - ): \Walmart\Models\MP\US\GetCategoriesList200Response { - $request = $this->getCategoriesListRequest($viewTrendingItems, $wfsFlag, $hasIssue, $type, $limit, $offset, ); - $this->writeDebug($request); - $this->writeDebug((string) $request->getBody()); - - try { - $options = $this->createHttpClientOption(); - try { - $response = $this->client->send($request, $options); - $this->writeDebug($response); - $this->writeDebug((string) $response->getBody()); - } catch (RequestException $e) { - $hasResponse = !empty($e->hasResponse()); - $body = (string) ($hasResponse ? $e->getResponse()->getBody() : '[NULL response]'); - $this->writeDebug($e->getResponse()); - $this->writeDebug($body); - - throw new ApiException( - "[{$e->getCode()}] {$body}", - (int) $e->getCode(), - $hasResponse ? $e->getResponse()->getHeaders() : null, - $body - ); - } catch (ConnectException $e) { - $this->writeDebug($e->getMessage()); - - throw new ApiException( - "[{$e->getCode()}] {$e->getMessage()}", - (int) $e->getCode(), - null, - null - ); - } - - $statusCode = $response->getStatusCode(); - - if ($statusCode < 200 || $statusCode > 299) { - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - (string) $request->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() - ); - } - switch ($statusCode) { - case 200: - if ('\Walmart\Models\MP\US\GetCategoriesList200Response' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\Walmart\Models\MP\US\GetCategoriesList200Response' !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, '\Walmart\Models\MP\US\GetCategoriesList200Response', $response->getHeaders()); - } - - $returnType = '\Walmart\Models\MP\US\GetCategoriesList200Response'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, $returnType, $response->getHeaders()); - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = ObjectSerializer::deserialize( - $e->getResponseBody(), - '\Walmart\Models\MP\US\GetCategoriesList200Response', - $e->getResponseHeaders() - ); - $e->setResponseObject($data); - break; - } - - $this->writeDebug($e); - throw $e; - } - } - - /** - * Operation getCategoriesListAsync - * - * Item count with listing quality issues - * - * @param bool $viewTrendingItems Specify whether or not to include seller's items that are trending in the Listing Quality Score. (optional, default to true) - * @param bool $wfsFlag Specify whether or not to include WFS-eligible items in the overall Listing Quality Score. (optional) - * @param int $hasIssue Specify whether or not to include items that have issues in the Listing Quality Score. (optional, default to 0) - * @param string $type Specify whether to get item count by brand or category. Category is the default value when no type is specified. (optional) - * @param int $limit Specify number of items to return. The value is defaulted to 100 and the maximum value is 1000. (optional) - * @param int $offset Specify the offset of item list to be returned. (optional, default to 0) - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - public function getCategoriesListAsync( - ?bool $viewTrendingItems = true, - ?bool $wfsFlag = null, - ?int $hasIssue = 0, - ?string $type = null, - ?int $limit = null, - ?int $offset = 0 - ): PromiseInterface { - return $this->getCategoriesListAsyncWithHttpInfo($viewTrendingItems, $wfsFlag, $hasIssue, $type, $limit, $offset) - ->then( - function ($response) { - return $response[0]; - } - ); - } - - /** - * Operation getCategoriesListAsyncWithHttpInfo - * - * - * Item count with listing quality issues - * - * @param bool $viewTrendingItems Specify whether or not to include seller's items that are trending in the Listing Quality Score. (optional, default to true) - * @param bool $wfsFlag Specify whether or not to include WFS-eligible items in the overall Listing Quality Score. (optional) - * @param int $hasIssue Specify whether or not to include items that have issues in the Listing Quality Score. (optional, default to 0) - * @param string $type Specify whether to get item count by brand or category. Category is the default value when no type is specified. (optional) - * @param int $limit Specify number of items to return. The value is defaulted to 100 and the maximum value is 1000. (optional) - * @param int $offset Specify the offset of item list to be returned. (optional, default to 0) - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - protected function getCategoriesListAsyncWithHttpInfo( - ?bool $viewTrendingItems = true, - ?bool $wfsFlag = null, - ?int $hasIssue = 0, - ?string $type = null, - ?int $limit = null, - ?int $offset = 0, - ): PromiseInterface { - $returnType = '\Walmart\Models\MP\US\GetCategoriesList200Response'; - $request = $this->getCategoriesListRequest($viewTrendingItems, $wfsFlag, $hasIssue, $type, $limit, $offset, ); - $this->writeDebug($request); - $this->writeDebug((string) $request->getBody()); - - return $this->client - ->sendAsync($request, $this->createHttpClientOption()) - ->then( - function ($response) use ($returnType) { - $this->writeDebug($response); - $this->writeDebug((string) $response->getBody()); - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, $returnType, $response->getHeaders()); - }, - function ($exception) { - $response = $exception->getResponse(); - $hasResponse = !empty($response); - $body = (string) ($hasResponse ? $response->getBody() : '[NULL response]'); - $this->writeDebug($response); - $statusCode = $hasResponse ? $response->getStatusCode() : $exception->getCode(); - - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - $body, - ); - } - ); - } - - /** - * Create request for operation 'getCategoriesList' - * - * @param bool $viewTrendingItems Specify whether or not to include seller's items that are trending in the Listing Quality Score. (optional, default to true) - * @param bool $wfsFlag Specify whether or not to include WFS-eligible items in the overall Listing Quality Score. (optional) - * @param int $hasIssue Specify whether or not to include items that have issues in the Listing Quality Score. (optional, default to 0) - * @param string $type Specify whether to get item count by brand or category. Category is the default value when no type is specified. (optional) - * @param int $limit Specify number of items to return. The value is defaulted to 100 and the maximum value is 1000. (optional) - * @param int $offset Specify the offset of item list to be returned. (optional, default to 0) - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Psr7\Request - */ - protected function getCategoriesListRequest( - ?bool $viewTrendingItems = true, - ?bool $wfsFlag = null, - ?int $hasIssue = 0, - ?string $type = null, - ?int $limit = null, - ?int $offset = 0, - ): Request { - $contentType = self::contentTypes['getCategoriesList']; - - $resourcePath = '/v3/insights/items/listingQuality/count'; - $formParams = []; - $queryParams = []; - $headerParams = []; - $httpBody = ''; - $multipart = false; - - // query params - $queryParams = [ - ObjectSerializer::toQueryValue( - $viewTrendingItems, - 'viewTrendingItems', // param base name - 'boolean', // openApiType - 'form', // style - true, // explode - false // required - ) ?? [], - ObjectSerializer::toQueryValue( - $wfsFlag, - 'wfsFlag', // param base name - 'boolean', // openApiType - 'form', // style - true, // explode - false // required - ) ?? [], - ObjectSerializer::toQueryValue( - $hasIssue, - 'hasIssue', // param base name - 'integer', // openApiType - 'form', // style - true, // explode - false // required - ) ?? [], - ObjectSerializer::toQueryValue( - $type, - 'type', // param base name - 'string', // openApiType - 'form', // style - true, // explode - false // required - ) ?? [], - ObjectSerializer::toQueryValue( - $limit, - 'limit', // param base name - 'integer', // openApiType - 'form', // style - true, // explode - false // required - ) ?? [], - ObjectSerializer::toQueryValue( - $offset, - 'offset', // param base name - 'integer', // openApiType - 'form', // style - true, // explode - false // required - ) ?? [], - ]; - - $headers = $this->headerSelector->selectHeaders( - ['application/json'], - $contentType, - $multipart - ); - - // for model (json/xml) - if (count($formParams) > 0) { - if ($multipart) { - $multipartContents = []; - foreach ($formParams as $formParamName => $formParamValue) { - $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; - foreach ($formParamValueItems as $formParamValueItem) { - $multipartContents[] = [ - 'name' => $formParamName, - 'contents' => $formParamValueItem - ]; - } - } - // for HTTP post (form) - $httpBody = new MultipartStream($multipartContents); - } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { - # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); - } else { - // for HTTP post (form) - $httpBody = ObjectSerializer::buildQuery($formParams); - } - } - - // this endpoint requires Bearer authentication (access token) - $token = $this->config->getAccessToken(); - if ($token) { - $headers['WM_SEC.ACCESS_TOKEN'] = $token->accessToken; - } - - $defaultHeaders = parent::getDefaultHeaders(); - if ($this->config->getUserAgent()) { - $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); - } - - $headers = array_merge( - $defaultHeaders, - $headerParams, - $headers - ); - - $operationHost = $this->config->getHost(); - $query = ObjectSerializer::buildQuery($queryParams); - return new Request( - 'GET', - $operationHost . $resourcePath . ($query ? "?{$query}" : ''), - $headers, - $httpBody - ); - } - - /** - * Operation getListingQualityScore - * - * Seller Listing Quality Score - * - * @param bool $viewTrendingItems Specify whether or not to include seller's items that are trending in the Listing Quality Score. (optional) - * @param string $wfsFlag Specify whether or not to include WFS-eligible items in the overall Listing Quality Score. (optional) - * - * @throws \Walmart\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return \Walmart\Models\MP\US\GetListingQualityScore200Response - */ - public function getListingQualityScore( - ?bool $viewTrendingItems = null, - ?string $wfsFlag = null - ): \Walmart\Models\MP\US\GetListingQualityScore200Response { - return $this->getListingQualityScoreWithHttpInfo($viewTrendingItems, $wfsFlag); - } - - /** - * Operation getListingQualityScoreWithHttpInfo - * - * Seller Listing Quality Score - * - * @param bool $viewTrendingItems Specify whether or not to include seller's items that are trending in the Listing Quality Score. (optional) - * @param string $wfsFlag Specify whether or not to include WFS-eligible items in the overall Listing Quality Score. (optional) - * - * @throws \Walmart\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return \Walmart\Models\MP\US\GetListingQualityScore200Response - */ - protected function getListingQualityScoreWithHttpInfo( - ?bool $viewTrendingItems = null, - ?string $wfsFlag = null, - ): \Walmart\Models\MP\US\GetListingQualityScore200Response { - $request = $this->getListingQualityScoreRequest($viewTrendingItems, $wfsFlag, ); - $this->writeDebug($request); - $this->writeDebug((string) $request->getBody()); - - try { - $options = $this->createHttpClientOption(); - try { - $response = $this->client->send($request, $options); - $this->writeDebug($response); - $this->writeDebug((string) $response->getBody()); - } catch (RequestException $e) { - $hasResponse = !empty($e->hasResponse()); - $body = (string) ($hasResponse ? $e->getResponse()->getBody() : '[NULL response]'); - $this->writeDebug($e->getResponse()); - $this->writeDebug($body); - - throw new ApiException( - "[{$e->getCode()}] {$body}", - (int) $e->getCode(), - $hasResponse ? $e->getResponse()->getHeaders() : null, - $body - ); - } catch (ConnectException $e) { - $this->writeDebug($e->getMessage()); - - throw new ApiException( - "[{$e->getCode()}] {$e->getMessage()}", - (int) $e->getCode(), - null, - null - ); - } - - $statusCode = $response->getStatusCode(); - - if ($statusCode < 200 || $statusCode > 299) { - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - (string) $request->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() - ); - } - switch ($statusCode) { - case 200: - if ('\Walmart\Models\MP\US\GetListingQualityScore200Response' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\Walmart\Models\MP\US\GetListingQualityScore200Response' !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, '\Walmart\Models\MP\US\GetListingQualityScore200Response', $response->getHeaders()); - } - - $returnType = '\Walmart\Models\MP\US\GetListingQualityScore200Response'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, $returnType, $response->getHeaders()); - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = ObjectSerializer::deserialize( - $e->getResponseBody(), - '\Walmart\Models\MP\US\GetListingQualityScore200Response', - $e->getResponseHeaders() - ); - $e->setResponseObject($data); - break; - } - - $this->writeDebug($e); - throw $e; - } - } - - /** - * Operation getListingQualityScoreAsync - * - * Seller Listing Quality Score - * - * @param bool $viewTrendingItems Specify whether or not to include seller's items that are trending in the Listing Quality Score. (optional) - * @param string $wfsFlag Specify whether or not to include WFS-eligible items in the overall Listing Quality Score. (optional) - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - public function getListingQualityScoreAsync( - ?bool $viewTrendingItems = null, - ?string $wfsFlag = null - ): PromiseInterface { - return $this->getListingQualityScoreAsyncWithHttpInfo($viewTrendingItems, $wfsFlag) - ->then( - function ($response) { - return $response[0]; - } - ); - } - - /** - * Operation getListingQualityScoreAsyncWithHttpInfo - * - * - * Seller Listing Quality Score - * - * @param bool $viewTrendingItems Specify whether or not to include seller's items that are trending in the Listing Quality Score. (optional) - * @param string $wfsFlag Specify whether or not to include WFS-eligible items in the overall Listing Quality Score. (optional) - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - protected function getListingQualityScoreAsyncWithHttpInfo( - ?bool $viewTrendingItems = null, - ?string $wfsFlag = null, - ): PromiseInterface { - $returnType = '\Walmart\Models\MP\US\GetListingQualityScore200Response'; - $request = $this->getListingQualityScoreRequest($viewTrendingItems, $wfsFlag, ); - $this->writeDebug($request); - $this->writeDebug((string) $request->getBody()); - - return $this->client - ->sendAsync($request, $this->createHttpClientOption()) - ->then( - function ($response) use ($returnType) { - $this->writeDebug($response); - $this->writeDebug((string) $response->getBody()); - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, $returnType, $response->getHeaders()); - }, - function ($exception) { - $response = $exception->getResponse(); - $hasResponse = !empty($response); - $body = (string) ($hasResponse ? $response->getBody() : '[NULL response]'); - $this->writeDebug($response); - $statusCode = $hasResponse ? $response->getStatusCode() : $exception->getCode(); - - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - $body, - ); - } - ); - } - - /** - * Create request for operation 'getListingQualityScore' - * - * @param bool $viewTrendingItems Specify whether or not to include seller's items that are trending in the Listing Quality Score. (optional) - * @param string $wfsFlag Specify whether or not to include WFS-eligible items in the overall Listing Quality Score. (optional) - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Psr7\Request - */ - protected function getListingQualityScoreRequest( - ?bool $viewTrendingItems = null, - ?string $wfsFlag = null, - ): Request { - $contentType = self::contentTypes['getListingQualityScore']; - - $resourcePath = '/v3/insights/items/listingQuality/score'; - $formParams = []; - $queryParams = []; - $headerParams = []; - $httpBody = ''; - $multipart = false; - - // query params - $queryParams = [ - ObjectSerializer::toQueryValue( - $viewTrendingItems, - 'viewTrendingItems', // param base name - 'boolean', // openApiType - 'form', // style - true, // explode - false // required - ) ?? [], - ObjectSerializer::toQueryValue( - $wfsFlag, - 'wfsFlag', // param base name - 'string', // openApiType - 'form', // style - true, // explode - false // required - ) ?? [], - ]; - - $headers = $this->headerSelector->selectHeaders( - ['application/json'], - $contentType, - $multipart - ); - - // for model (json/xml) - if (count($formParams) > 0) { - if ($multipart) { - $multipartContents = []; - foreach ($formParams as $formParamName => $formParamValue) { - $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; - foreach ($formParamValueItems as $formParamValueItem) { - $multipartContents[] = [ - 'name' => $formParamName, - 'contents' => $formParamValueItem - ]; - } - } - // for HTTP post (form) - $httpBody = new MultipartStream($multipartContents); - } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { - # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); - } else { - // for HTTP post (form) - $httpBody = ObjectSerializer::buildQuery($formParams); - } - } - - // this endpoint requires Bearer authentication (access token) - $token = $this->config->getAccessToken(); - if ($token) { - $headers['WM_SEC.ACCESS_TOKEN'] = $token->accessToken; - } - - $defaultHeaders = parent::getDefaultHeaders(); - if ($this->config->getUserAgent()) { - $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); - } - - $headers = array_merge( - $defaultHeaders, - $headerParams, - $headers - ); - - $operationHost = $this->config->getHost(); - $query = ObjectSerializer::buildQuery($queryParams); - return new Request( - 'GET', - $operationHost . $resourcePath . ($query ? "?{$query}" : ''), - $headers, - $httpBody - ); - } - - /** - * Operation getProSellerBadgeInfo - * - * Pro Seller Badge Status - * - * @throws \Walmart\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return \Walmart\Models\MP\US\GetProSellerBadgeInfo200Response - */ - public function getProSellerBadgeInfo(): \Walmart\Models\MP\US\GetProSellerBadgeInfo200Response - { - return $this->getProSellerBadgeInfoWithHttpInfo(); - } - - /** - * Operation getProSellerBadgeInfoWithHttpInfo - * - * Pro Seller Badge Status - * - * @throws \Walmart\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return \Walmart\Models\MP\US\GetProSellerBadgeInfo200Response - */ - protected function getProSellerBadgeInfoWithHttpInfo(): \Walmart\Models\MP\US\GetProSellerBadgeInfo200Response - { - $request = $this->getProSellerBadgeInfoRequest(); - $this->writeDebug($request); - $this->writeDebug((string) $request->getBody()); - - try { - $options = $this->createHttpClientOption(); - try { - $response = $this->client->send($request, $options); - $this->writeDebug($response); - $this->writeDebug((string) $response->getBody()); - } catch (RequestException $e) { - $hasResponse = !empty($e->hasResponse()); - $body = (string) ($hasResponse ? $e->getResponse()->getBody() : '[NULL response]'); - $this->writeDebug($e->getResponse()); - $this->writeDebug($body); - - throw new ApiException( - "[{$e->getCode()}] {$body}", - (int) $e->getCode(), - $hasResponse ? $e->getResponse()->getHeaders() : null, - $body - ); - } catch (ConnectException $e) { - $this->writeDebug($e->getMessage()); - - throw new ApiException( - "[{$e->getCode()}] {$e->getMessage()}", - (int) $e->getCode(), - null, - null - ); - } - - $statusCode = $response->getStatusCode(); - - if ($statusCode < 200 || $statusCode > 299) { - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - (string) $request->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() - ); - } - switch ($statusCode) { - case 200: - if ('\Walmart\Models\MP\US\GetProSellerBadgeInfo200Response' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\Walmart\Models\MP\US\GetProSellerBadgeInfo200Response' !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, '\Walmart\Models\MP\US\GetProSellerBadgeInfo200Response', $response->getHeaders()); - } - - $returnType = '\Walmart\Models\MP\US\GetProSellerBadgeInfo200Response'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, $returnType, $response->getHeaders()); - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = ObjectSerializer::deserialize( - $e->getResponseBody(), - '\Walmart\Models\MP\US\GetProSellerBadgeInfo200Response', - $e->getResponseHeaders() - ); - $e->setResponseObject($data); - break; - } - - $this->writeDebug($e); - throw $e; - } - } - - /** - * Operation getProSellerBadgeInfoAsync - * - * Pro Seller Badge Status - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - public function getProSellerBadgeInfoAsync( - ): PromiseInterface { - return $this->getProSellerBadgeInfoAsyncWithHttpInfo() - ->then( - function ($response) { - return $response[0]; - } - ); - } - - /** - * Operation getProSellerBadgeInfoAsyncWithHttpInfo - * - * - * Pro Seller Badge Status - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - protected function getProSellerBadgeInfoAsyncWithHttpInfo(): PromiseInterface - { - $returnType = '\Walmart\Models\MP\US\GetProSellerBadgeInfo200Response'; - $request = $this->getProSellerBadgeInfoRequest(); - $this->writeDebug($request); - $this->writeDebug((string) $request->getBody()); - - return $this->client - ->sendAsync($request, $this->createHttpClientOption()) - ->then( - function ($response) use ($returnType) { - $this->writeDebug($response); - $this->writeDebug((string) $response->getBody()); - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, $returnType, $response->getHeaders()); - }, - function ($exception) { - $response = $exception->getResponse(); - $hasResponse = !empty($response); - $body = (string) ($hasResponse ? $response->getBody() : '[NULL response]'); - $this->writeDebug($response); - $statusCode = $hasResponse ? $response->getStatusCode() : $exception->getCode(); - - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - $body, - ); - } - ); - } - - /** - * Create request for operation 'getProSellerBadgeInfo' - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Psr7\Request - */ - protected function getProSellerBadgeInfoRequest(): Request - { - $contentType = self::contentTypes['getProSellerBadgeInfo']; - - $resourcePath = '/v3/insights/prosellerbadge'; - $formParams = []; - $queryParams = []; - $headerParams = []; - $httpBody = ''; - $multipart = false; - - $headers = $this->headerSelector->selectHeaders( - ['application/json'], - $contentType, - $multipart - ); - - // for model (json/xml) - if (count($formParams) > 0) { - if ($multipart) { - $multipartContents = []; - foreach ($formParams as $formParamName => $formParamValue) { - $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; - foreach ($formParamValueItems as $formParamValueItem) { - $multipartContents[] = [ - 'name' => $formParamName, - 'contents' => $formParamValueItem - ]; - } - } - // for HTTP post (form) - $httpBody = new MultipartStream($multipartContents); - } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { - # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); - } else { - // for HTTP post (form) - $httpBody = ObjectSerializer::buildQuery($formParams); - } - } - - // this endpoint requires Bearer authentication (access token) - $token = $this->config->getAccessToken(); - if ($token) { - $headers['WM_SEC.ACCESS_TOKEN'] = $token->accessToken; - } - - $defaultHeaders = parent::getDefaultHeaders(); - if ($this->config->getUserAgent()) { - $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); - } - - $headers = array_merge( - $defaultHeaders, - $headerParams, - $headers - ); - - $operationHost = $this->config->getHost(); - $query = ObjectSerializer::buildQuery($queryParams); - return new Request( - 'GET', - $operationHost . $resourcePath . ($query ? "?{$query}" : ''), - $headers, - $httpBody - ); - } - - /** - * Operation getTrendingResult - * - * Top Trending Items - * - * @param string $departmentId departmentId (required) - * @param string $categoryId categoryId (optional, default to 'null') - * @param string $limit The number of items to be returned. (optional, default to '20') - * @param string $offset The object response to start with, where 0 is the first entity that can be requested. (optional, default to '0') - * @param string $timeFrame Returns all trending items for the given time frame in days (optional, default to '7') - * - * @throws \Walmart\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return \Walmart\Models\MP\US\GetTrendingResult200Response - */ - public function getTrendingResult( - string $departmentId, - ?string $categoryId = 'null', - ?string $limit = '20', - ?string $offset = '0', - ?string $timeFrame = '7' - ): \Walmart\Models\MP\US\GetTrendingResult200Response { - return $this->getTrendingResultWithHttpInfo($departmentId, $categoryId, $limit, $offset, $timeFrame); - } - - /** - * Operation getTrendingResultWithHttpInfo - * - * Top Trending Items - * - * @param string $departmentId departmentId (required) - * @param string $categoryId categoryId (optional, default to 'null') - * @param string $limit The number of items to be returned. (optional, default to '20') - * @param string $offset The object response to start with, where 0 is the first entity that can be requested. (optional, default to '0') - * @param string $timeFrame Returns all trending items for the given time frame in days (optional, default to '7') - * - * @throws \Walmart\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return \Walmart\Models\MP\US\GetTrendingResult200Response - */ - protected function getTrendingResultWithHttpInfo( - string $departmentId, - ?string $categoryId = 'null', - ?string $limit = '20', - ?string $offset = '0', - ?string $timeFrame = '7', - ): \Walmart\Models\MP\US\GetTrendingResult200Response { - $request = $this->getTrendingResultRequest($departmentId, $categoryId, $limit, $offset, $timeFrame, ); - $this->writeDebug($request); - $this->writeDebug((string) $request->getBody()); - - try { - $options = $this->createHttpClientOption(); - try { - $response = $this->client->send($request, $options); - $this->writeDebug($response); - $this->writeDebug((string) $response->getBody()); - } catch (RequestException $e) { - $hasResponse = !empty($e->hasResponse()); - $body = (string) ($hasResponse ? $e->getResponse()->getBody() : '[NULL response]'); - $this->writeDebug($e->getResponse()); - $this->writeDebug($body); - - throw new ApiException( - "[{$e->getCode()}] {$body}", - (int) $e->getCode(), - $hasResponse ? $e->getResponse()->getHeaders() : null, - $body - ); - } catch (ConnectException $e) { - $this->writeDebug($e->getMessage()); - - throw new ApiException( - "[{$e->getCode()}] {$e->getMessage()}", - (int) $e->getCode(), - null, - null - ); - } - - $statusCode = $response->getStatusCode(); - - if ($statusCode < 200 || $statusCode > 299) { - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - (string) $request->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() - ); - } - switch ($statusCode) { - case 200: - if ('\Walmart\Models\MP\US\GetTrendingResult200Response' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\Walmart\Models\MP\US\GetTrendingResult200Response' !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, '\Walmart\Models\MP\US\GetTrendingResult200Response', $response->getHeaders()); - } - - $returnType = '\Walmart\Models\MP\US\GetTrendingResult200Response'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, $returnType, $response->getHeaders()); - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = ObjectSerializer::deserialize( - $e->getResponseBody(), - '\Walmart\Models\MP\US\GetTrendingResult200Response', - $e->getResponseHeaders() - ); - $e->setResponseObject($data); - break; - } - - $this->writeDebug($e); - throw $e; - } - } - - /** - * Operation getTrendingResultAsync - * - * Top Trending Items - * - * @param string $departmentId departmentId (required) - * @param string $categoryId categoryId (optional, default to 'null') - * @param string $limit The number of items to be returned. (optional, default to '20') - * @param string $offset The object response to start with, where 0 is the first entity that can be requested. (optional, default to '0') - * @param string $timeFrame Returns all trending items for the given time frame in days (optional, default to '7') - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - public function getTrendingResultAsync( - string $departmentId, - ?string $categoryId = 'null', - ?string $limit = '20', - ?string $offset = '0', - ?string $timeFrame = '7' - ): PromiseInterface { - return $this->getTrendingResultAsyncWithHttpInfo($departmentId, $categoryId, $limit, $offset, $timeFrame) - ->then( - function ($response) { - return $response[0]; - } - ); - } - - /** - * Operation getTrendingResultAsyncWithHttpInfo - * - * - * Top Trending Items - * - * @param string $departmentId departmentId (required) - * @param string $categoryId categoryId (optional, default to 'null') - * @param string $limit The number of items to be returned. (optional, default to '20') - * @param string $offset The object response to start with, where 0 is the first entity that can be requested. (optional, default to '0') - * @param string $timeFrame Returns all trending items for the given time frame in days (optional, default to '7') - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - protected function getTrendingResultAsyncWithHttpInfo( - string $departmentId, - ?string $categoryId = 'null', - ?string $limit = '20', - ?string $offset = '0', - ?string $timeFrame = '7', - ): PromiseInterface { - $returnType = '\Walmart\Models\MP\US\GetTrendingResult200Response'; - $request = $this->getTrendingResultRequest($departmentId, $categoryId, $limit, $offset, $timeFrame, ); - $this->writeDebug($request); - $this->writeDebug((string) $request->getBody()); - - return $this->client - ->sendAsync($request, $this->createHttpClientOption()) - ->then( - function ($response) use ($returnType) { - $this->writeDebug($response); - $this->writeDebug((string) $response->getBody()); - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, $returnType, $response->getHeaders()); - }, - function ($exception) { - $response = $exception->getResponse(); - $hasResponse = !empty($response); - $body = (string) ($hasResponse ? $response->getBody() : '[NULL response]'); - $this->writeDebug($response); - $statusCode = $hasResponse ? $response->getStatusCode() : $exception->getCode(); - - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - $body, - ); - } - ); - } - - /** - * Create request for operation 'getTrendingResult' - * - * @param string $departmentId departmentId (required) - * @param string $categoryId categoryId (optional, default to 'null') - * @param string $limit The number of items to be returned. (optional, default to '20') - * @param string $offset The object response to start with, where 0 is the first entity that can be requested. (optional, default to '0') - * @param string $timeFrame Returns all trending items for the given time frame in days (optional, default to '7') - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Psr7\Request - */ - protected function getTrendingResultRequest( - string $departmentId, - ?string $categoryId = 'null', - ?string $limit = '20', - ?string $offset = '0', - ?string $timeFrame = '7', - ): Request { - $contentType = self::contentTypes['getTrendingResult']; - - // verify the required parameter 'departmentId' is set - if ($departmentId === null || (is_array($departmentId) && count($departmentId) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $departmentId when calling getTrendingResult' - ); - } - $resourcePath = '/v3/insights/items/trending'; - $formParams = []; - $queryParams = []; - $headerParams = []; - $httpBody = ''; - $multipart = false; - - // query params - $queryParams = [ - ObjectSerializer::toQueryValue( - $departmentId, - 'departmentId', // param base name - 'string', // openApiType - 'form', // style - true, // explode - true // required - ) ?? [], - ObjectSerializer::toQueryValue( - $categoryId, - 'categoryId', // param base name - 'string', // openApiType - 'form', // style - true, // explode - false // required - ) ?? [], - ObjectSerializer::toQueryValue( - $limit, - 'limit', // param base name - 'string', // openApiType - 'form', // style - true, // explode - false // required - ) ?? [], - ObjectSerializer::toQueryValue( - $offset, - 'offset', // param base name - 'string', // openApiType - 'form', // style - true, // explode - false // required - ) ?? [], - ObjectSerializer::toQueryValue( - $timeFrame, - 'timeFrame', // param base name - 'string', // openApiType - 'form', // style - true, // explode - false // required - ) ?? [], - ]; - - $headers = $this->headerSelector->selectHeaders( - ['application/json'], - $contentType, - $multipart - ); - - // for model (json/xml) - if (count($formParams) > 0) { - if ($multipart) { - $multipartContents = []; - foreach ($formParams as $formParamName => $formParamValue) { - $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; - foreach ($formParamValueItems as $formParamValueItem) { - $multipartContents[] = [ - 'name' => $formParamName, - 'contents' => $formParamValueItem - ]; - } - } - // for HTTP post (form) - $httpBody = new MultipartStream($multipartContents); - } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { - # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); - } else { - // for HTTP post (form) - $httpBody = ObjectSerializer::buildQuery($formParams); - } - } - - // this endpoint requires Bearer authentication (access token) - $token = $this->config->getAccessToken(); - if ($token) { - $headers['WM_SEC.ACCESS_TOKEN'] = $token->accessToken; - } - - $defaultHeaders = parent::getDefaultHeaders(); - if ($this->config->getUserAgent()) { - $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); - } - - $headers = array_merge( - $defaultHeaders, - $headerParams, - $headers - ); - - $operationHost = $this->config->getHost(); - $query = ObjectSerializer::buildQuery($queryParams); - return new Request( - 'GET', - $operationHost . $resourcePath . ($query ? "?{$query}" : ''), - $headers, - $httpBody - ); - } - - /** - * Operation getUnpublishedItemCount - * - * Unpublished Item Counts - * - * @param string $fromDate Returns all unpublished items count with reason codes since the given date (required) - * - * @throws \Walmart\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return \Walmart\Models\MP\US\GetUnpublishedItemCount200Response - */ - public function getUnpublishedItemCount( - string $fromDate - ): \Walmart\Models\MP\US\GetUnpublishedItemCount200Response { - return $this->getUnpublishedItemCountWithHttpInfo($fromDate); - } - - /** - * Operation getUnpublishedItemCountWithHttpInfo - * - * Unpublished Item Counts - * - * @param string $fromDate Returns all unpublished items count with reason codes since the given date (required) - * - * @throws \Walmart\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return \Walmart\Models\MP\US\GetUnpublishedItemCount200Response - */ - protected function getUnpublishedItemCountWithHttpInfo( - string $fromDate, - ): \Walmart\Models\MP\US\GetUnpublishedItemCount200Response { - $request = $this->getUnpublishedItemCountRequest($fromDate, ); - $this->writeDebug($request); - $this->writeDebug((string) $request->getBody()); - - try { - $options = $this->createHttpClientOption(); - try { - $response = $this->client->send($request, $options); - $this->writeDebug($response); - $this->writeDebug((string) $response->getBody()); - } catch (RequestException $e) { - $hasResponse = !empty($e->hasResponse()); - $body = (string) ($hasResponse ? $e->getResponse()->getBody() : '[NULL response]'); - $this->writeDebug($e->getResponse()); - $this->writeDebug($body); - - throw new ApiException( - "[{$e->getCode()}] {$body}", - (int) $e->getCode(), - $hasResponse ? $e->getResponse()->getHeaders() : null, - $body - ); - } catch (ConnectException $e) { - $this->writeDebug($e->getMessage()); - - throw new ApiException( - "[{$e->getCode()}] {$e->getMessage()}", - (int) $e->getCode(), - null, - null - ); - } - - $statusCode = $response->getStatusCode(); - - if ($statusCode < 200 || $statusCode > 299) { - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - (string) $request->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() - ); - } - switch ($statusCode) { - case 200: - if ('\Walmart\Models\MP\US\GetUnpublishedItemCount200Response' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\Walmart\Models\MP\US\GetUnpublishedItemCount200Response' !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, '\Walmart\Models\MP\US\GetUnpublishedItemCount200Response', $response->getHeaders()); - } - - $returnType = '\Walmart\Models\MP\US\GetUnpublishedItemCount200Response'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, $returnType, $response->getHeaders()); - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = ObjectSerializer::deserialize( - $e->getResponseBody(), - '\Walmart\Models\MP\US\GetUnpublishedItemCount200Response', - $e->getResponseHeaders() - ); - $e->setResponseObject($data); - break; - } - - $this->writeDebug($e); - throw $e; - } - } - - /** - * Operation getUnpublishedItemCountAsync - * - * Unpublished Item Counts - * - * @param string $fromDate Returns all unpublished items count with reason codes since the given date (required) - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - public function getUnpublishedItemCountAsync( - string $fromDate - ): PromiseInterface { - return $this->getUnpublishedItemCountAsyncWithHttpInfo($fromDate) - ->then( - function ($response) { - return $response[0]; - } - ); - } - - /** - * Operation getUnpublishedItemCountAsyncWithHttpInfo - * - * - * Unpublished Item Counts - * - * @param string $fromDate Returns all unpublished items count with reason codes since the given date (required) - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - protected function getUnpublishedItemCountAsyncWithHttpInfo( - string $fromDate, - ): PromiseInterface { - $returnType = '\Walmart\Models\MP\US\GetUnpublishedItemCount200Response'; - $request = $this->getUnpublishedItemCountRequest($fromDate, ); - $this->writeDebug($request); - $this->writeDebug((string) $request->getBody()); - - return $this->client - ->sendAsync($request, $this->createHttpClientOption()) - ->then( - function ($response) use ($returnType) { - $this->writeDebug($response); - $this->writeDebug((string) $response->getBody()); - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, $returnType, $response->getHeaders()); - }, - function ($exception) { - $response = $exception->getResponse(); - $hasResponse = !empty($response); - $body = (string) ($hasResponse ? $response->getBody() : '[NULL response]'); - $this->writeDebug($response); - $statusCode = $hasResponse ? $response->getStatusCode() : $exception->getCode(); - - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - $body, - ); - } - ); - } - - /** - * Create request for operation 'getUnpublishedItemCount' - * - * @param string $fromDate Returns all unpublished items count with reason codes since the given date (required) - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Psr7\Request - */ - protected function getUnpublishedItemCountRequest( - string $fromDate, - ): Request { - $contentType = self::contentTypes['getUnpublishedItemCount']; - - // verify the required parameter 'fromDate' is set - if ($fromDate === null || (is_array($fromDate) && count($fromDate) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $fromDate when calling getUnpublishedItemCount' - ); - } - $resourcePath = '/v3/insights/items/unpublished/counts'; - $formParams = []; - $queryParams = []; - $headerParams = []; - $httpBody = ''; - $multipart = false; - - // query params - $queryParams = [ - ObjectSerializer::toQueryValue( - $fromDate, - 'fromDate', // param base name - 'string', // openApiType - 'form', // style - true, // explode - true // required - ) ?? [], - ]; - - $headers = $this->headerSelector->selectHeaders( - ['application/json'], - $contentType, - $multipart - ); - - // for model (json/xml) - if (count($formParams) > 0) { - if ($multipart) { - $multipartContents = []; - foreach ($formParams as $formParamName => $formParamValue) { - $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; - foreach ($formParamValueItems as $formParamValueItem) { - $multipartContents[] = [ - 'name' => $formParamName, - 'contents' => $formParamValueItem - ]; - } - } - // for HTTP post (form) - $httpBody = new MultipartStream($multipartContents); - } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { - # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); - } else { - // for HTTP post (form) - $httpBody = ObjectSerializer::buildQuery($formParams); - } - } - - // this endpoint requires Bearer authentication (access token) - $token = $this->config->getAccessToken(); - if ($token) { - $headers['WM_SEC.ACCESS_TOKEN'] = $token->accessToken; - } - - $defaultHeaders = parent::getDefaultHeaders(); - if ($this->config->getUserAgent()) { - $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); - } - - $headers = array_merge( - $defaultHeaders, - $headerParams, - $headers - ); - - $operationHost = $this->config->getHost(); - $query = ObjectSerializer::buildQuery($queryParams); - return new Request( - 'GET', - $operationHost . $resourcePath . ($query ? "?{$query}" : ''), - $headers, - $httpBody - ); - } - - /** - * Operation getUnpublishedItems - * - * Unpublished Items - * - * @param string $fromDate Returns all unpublished items since the given date (required) - * @param string $unpublishedReasonCode Unpublished reason code (optional, default to 'all') - * @param string $limit The number of items to be returned. (optional, default to '20') - * @param string $offerLifecycleStatus The lifecycle status of an item describes where the item listing is in the overall lifecycle. Examples of allowed values are ACTIVE , ARCHIVED, RETIRED. (optional, default to 'all') - * @param string $marketTrending Filter the item list to return only items that are trending on Walmart.com (optional, default to 'true') - * @param string $itemsWithInventory Filter the item list to return only items that have inventory (optional, default to 'true') - * - * @throws \Walmart\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return \Walmart\Models\MP\US\GetUnpublishedItems200Response - */ - public function getUnpublishedItems( - string $fromDate, - ?string $unpublishedReasonCode = 'all', - ?string $limit = '20', - ?string $offerLifecycleStatus = 'all', - ?string $marketTrending = 'true', - ?string $itemsWithInventory = 'true' - ): \Walmart\Models\MP\US\GetUnpublishedItems200Response { - return $this->getUnpublishedItemsWithHttpInfo($fromDate, $unpublishedReasonCode, $limit, $offerLifecycleStatus, $marketTrending, $itemsWithInventory); - } - - /** - * Operation getUnpublishedItemsWithHttpInfo - * - * Unpublished Items - * - * @param string $fromDate Returns all unpublished items since the given date (required) - * @param string $unpublishedReasonCode Unpublished reason code (optional, default to 'all') - * @param string $limit The number of items to be returned. (optional, default to '20') - * @param string $offerLifecycleStatus The lifecycle status of an item describes where the item listing is in the overall lifecycle. Examples of allowed values are ACTIVE , ARCHIVED, RETIRED. (optional, default to 'all') - * @param string $marketTrending Filter the item list to return only items that are trending on Walmart.com (optional, default to 'true') - * @param string $itemsWithInventory Filter the item list to return only items that have inventory (optional, default to 'true') - * - * @throws \Walmart\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return \Walmart\Models\MP\US\GetUnpublishedItems200Response - */ - protected function getUnpublishedItemsWithHttpInfo( - string $fromDate, - ?string $unpublishedReasonCode = 'all', - ?string $limit = '20', - ?string $offerLifecycleStatus = 'all', - ?string $marketTrending = 'true', - ?string $itemsWithInventory = 'true', - ): \Walmart\Models\MP\US\GetUnpublishedItems200Response { - $request = $this->getUnpublishedItemsRequest($fromDate, $unpublishedReasonCode, $limit, $offerLifecycleStatus, $marketTrending, $itemsWithInventory, ); - $this->writeDebug($request); - $this->writeDebug((string) $request->getBody()); - - try { - $options = $this->createHttpClientOption(); - try { - $response = $this->client->send($request, $options); - $this->writeDebug($response); - $this->writeDebug((string) $response->getBody()); - } catch (RequestException $e) { - $hasResponse = !empty($e->hasResponse()); - $body = (string) ($hasResponse ? $e->getResponse()->getBody() : '[NULL response]'); - $this->writeDebug($e->getResponse()); - $this->writeDebug($body); - - throw new ApiException( - "[{$e->getCode()}] {$body}", - (int) $e->getCode(), - $hasResponse ? $e->getResponse()->getHeaders() : null, - $body - ); - } catch (ConnectException $e) { - $this->writeDebug($e->getMessage()); - - throw new ApiException( - "[{$e->getCode()}] {$e->getMessage()}", - (int) $e->getCode(), - null, - null - ); - } - - $statusCode = $response->getStatusCode(); - - if ($statusCode < 200 || $statusCode > 299) { - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - (string) $request->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() - ); - } - switch ($statusCode) { - case 200: - if ('\Walmart\Models\MP\US\GetUnpublishedItems200Response' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\Walmart\Models\MP\US\GetUnpublishedItems200Response' !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, '\Walmart\Models\MP\US\GetUnpublishedItems200Response', $response->getHeaders()); - } - - $returnType = '\Walmart\Models\MP\US\GetUnpublishedItems200Response'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, $returnType, $response->getHeaders()); - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = ObjectSerializer::deserialize( - $e->getResponseBody(), - '\Walmart\Models\MP\US\GetUnpublishedItems200Response', - $e->getResponseHeaders() - ); - $e->setResponseObject($data); - break; - } - - $this->writeDebug($e); - throw $e; - } - } - - /** - * Operation getUnpublishedItemsAsync - * - * Unpublished Items - * - * @param string $fromDate Returns all unpublished items since the given date (required) - * @param string $unpublishedReasonCode Unpublished reason code (optional, default to 'all') - * @param string $limit The number of items to be returned. (optional, default to '20') - * @param string $offerLifecycleStatus The lifecycle status of an item describes where the item listing is in the overall lifecycle. Examples of allowed values are ACTIVE , ARCHIVED, RETIRED. (optional, default to 'all') - * @param string $marketTrending Filter the item list to return only items that are trending on Walmart.com (optional, default to 'true') - * @param string $itemsWithInventory Filter the item list to return only items that have inventory (optional, default to 'true') - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - public function getUnpublishedItemsAsync( - string $fromDate, - ?string $unpublishedReasonCode = 'all', - ?string $limit = '20', - ?string $offerLifecycleStatus = 'all', - ?string $marketTrending = 'true', - ?string $itemsWithInventory = 'true' - ): PromiseInterface { - return $this->getUnpublishedItemsAsyncWithHttpInfo($fromDate, $unpublishedReasonCode, $limit, $offerLifecycleStatus, $marketTrending, $itemsWithInventory) - ->then( - function ($response) { - return $response[0]; - } - ); - } - - /** - * Operation getUnpublishedItemsAsyncWithHttpInfo - * - * - * Unpublished Items - * - * @param string $fromDate Returns all unpublished items since the given date (required) - * @param string $unpublishedReasonCode Unpublished reason code (optional, default to 'all') - * @param string $limit The number of items to be returned. (optional, default to '20') - * @param string $offerLifecycleStatus The lifecycle status of an item describes where the item listing is in the overall lifecycle. Examples of allowed values are ACTIVE , ARCHIVED, RETIRED. (optional, default to 'all') - * @param string $marketTrending Filter the item list to return only items that are trending on Walmart.com (optional, default to 'true') - * @param string $itemsWithInventory Filter the item list to return only items that have inventory (optional, default to 'true') - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - protected function getUnpublishedItemsAsyncWithHttpInfo( - string $fromDate, - ?string $unpublishedReasonCode = 'all', - ?string $limit = '20', - ?string $offerLifecycleStatus = 'all', - ?string $marketTrending = 'true', - ?string $itemsWithInventory = 'true', - ): PromiseInterface { - $returnType = '\Walmart\Models\MP\US\GetUnpublishedItems200Response'; - $request = $this->getUnpublishedItemsRequest($fromDate, $unpublishedReasonCode, $limit, $offerLifecycleStatus, $marketTrending, $itemsWithInventory, ); - $this->writeDebug($request); - $this->writeDebug((string) $request->getBody()); - - return $this->client - ->sendAsync($request, $this->createHttpClientOption()) - ->then( - function ($response) use ($returnType) { - $this->writeDebug($response); - $this->writeDebug((string) $response->getBody()); - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, $returnType, $response->getHeaders()); - }, - function ($exception) { - $response = $exception->getResponse(); - $hasResponse = !empty($response); - $body = (string) ($hasResponse ? $response->getBody() : '[NULL response]'); - $this->writeDebug($response); - $statusCode = $hasResponse ? $response->getStatusCode() : $exception->getCode(); - - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - $body, - ); - } - ); - } - - /** - * Create request for operation 'getUnpublishedItems' - * - * @param string $fromDate Returns all unpublished items since the given date (required) - * @param string $unpublishedReasonCode Unpublished reason code (optional, default to 'all') - * @param string $limit The number of items to be returned. (optional, default to '20') - * @param string $offerLifecycleStatus The lifecycle status of an item describes where the item listing is in the overall lifecycle. Examples of allowed values are ACTIVE , ARCHIVED, RETIRED. (optional, default to 'all') - * @param string $marketTrending Filter the item list to return only items that are trending on Walmart.com (optional, default to 'true') - * @param string $itemsWithInventory Filter the item list to return only items that have inventory (optional, default to 'true') - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Psr7\Request - */ - protected function getUnpublishedItemsRequest( - string $fromDate, - ?string $unpublishedReasonCode = 'all', - ?string $limit = '20', - ?string $offerLifecycleStatus = 'all', - ?string $marketTrending = 'true', - ?string $itemsWithInventory = 'true', - ): Request { - $contentType = self::contentTypes['getUnpublishedItems']; - - // verify the required parameter 'fromDate' is set - if ($fromDate === null || (is_array($fromDate) && count($fromDate) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $fromDate when calling getUnpublishedItems' - ); - } - $resourcePath = '/v3/insights/items/unpublished/items'; - $formParams = []; - $queryParams = []; - $headerParams = []; - $httpBody = ''; - $multipart = false; - - // query params - $queryParams = [ - ObjectSerializer::toQueryValue( - $unpublishedReasonCode, - 'unpublishedReasonCode', // param base name - 'string', // openApiType - 'form', // style - true, // explode - false // required - ) ?? [], - ObjectSerializer::toQueryValue( - $fromDate, - 'fromDate', // param base name - 'string', // openApiType - 'form', // style - true, // explode - true // required - ) ?? [], - ObjectSerializer::toQueryValue( - $limit, - 'limit', // param base name - 'string', // openApiType - 'form', // style - true, // explode - false // required - ) ?? [], - ObjectSerializer::toQueryValue( - $offerLifecycleStatus, - 'offerLifecycleStatus', // param base name - 'string', // openApiType - 'form', // style - true, // explode - false // required - ) ?? [], - ObjectSerializer::toQueryValue( - $marketTrending, - 'marketTrending', // param base name - 'string', // openApiType - 'form', // style - true, // explode - false // required - ) ?? [], - ObjectSerializer::toQueryValue( - $itemsWithInventory, - 'itemsWithInventory', // param base name - 'string', // openApiType - 'form', // style - true, // explode - false // required - ) ?? [], - ]; - - $headers = $this->headerSelector->selectHeaders( - ['application/json'], - $contentType, - $multipart - ); - - // for model (json/xml) - if (count($formParams) > 0) { - if ($multipart) { - $multipartContents = []; - foreach ($formParams as $formParamName => $formParamValue) { - $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; - foreach ($formParamValueItems as $formParamValueItem) { - $multipartContents[] = [ - 'name' => $formParamName, - 'contents' => $formParamValueItem - ]; - } - } - // for HTTP post (form) - $httpBody = new MultipartStream($multipartContents); - } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { - # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); - } else { - // for HTTP post (form) - $httpBody = ObjectSerializer::buildQuery($formParams); - } - } - - // this endpoint requires Bearer authentication (access token) - $token = $this->config->getAccessToken(); - if ($token) { - $headers['WM_SEC.ACCESS_TOKEN'] = $token->accessToken; - } - - $defaultHeaders = parent::getDefaultHeaders(); - if ($this->config->getUserAgent()) { - $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); - } - - $headers = array_merge( - $defaultHeaders, - $headerParams, - $headers - ); - - $operationHost = $this->config->getHost(); - $query = ObjectSerializer::buildQuery($queryParams); - return new Request( - 'GET', - $operationHost . $resourcePath . ($query ? "?{$query}" : ''), - $headers, - $httpBody - ); - } - - /** - * Operation itemsDetailsForListing - * - * Item Listing Quality Details - * - * @param \Walmart\Models\MP\US\ItemsDetailsForListingRequest $itemsDetailsForListingRequest Request payload (required) - * @param string $limit Specify number of items to return. If no limit is specified, API returns 200 items by default. (optional, default to '200') - * @param string $nextCursor Specify pagination for long list of items. (optional) - * - * @throws \Walmart\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return \Walmart\Models\MP\US\ItemsDetailsForListing200Response - */ - public function itemsDetailsForListing( - \Walmart\Models\MP\US\ItemsDetailsForListingRequest $itemsDetailsForListingRequest, - ?string $limit = '200', - ?string $nextCursor = null - ): \Walmart\Models\MP\US\ItemsDetailsForListing200Response { - return $this->itemsDetailsForListingWithHttpInfo($itemsDetailsForListingRequest, $limit, $nextCursor); - } - - /** - * Operation itemsDetailsForListingWithHttpInfo - * - * Item Listing Quality Details - * - * @param \Walmart\Models\MP\US\ItemsDetailsForListingRequest $itemsDetailsForListingRequest Request payload (required) - * @param string $limit Specify number of items to return. If no limit is specified, API returns 200 items by default. (optional, default to '200') - * @param string $nextCursor Specify pagination for long list of items. (optional) - * - * @throws \Walmart\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return \Walmart\Models\MP\US\ItemsDetailsForListing200Response - */ - protected function itemsDetailsForListingWithHttpInfo( - \Walmart\Models\MP\US\ItemsDetailsForListingRequest $itemsDetailsForListingRequest, - ?string $limit = '200', - ?string $nextCursor = null, - ): \Walmart\Models\MP\US\ItemsDetailsForListing200Response { - $request = $this->itemsDetailsForListingRequest($itemsDetailsForListingRequest, $limit, $nextCursor, ); - $this->writeDebug($request); - $this->writeDebug((string) $request->getBody()); - - try { - $options = $this->createHttpClientOption(); - try { - $response = $this->client->send($request, $options); - $this->writeDebug($response); - $this->writeDebug((string) $response->getBody()); - } catch (RequestException $e) { - $hasResponse = !empty($e->hasResponse()); - $body = (string) ($hasResponse ? $e->getResponse()->getBody() : '[NULL response]'); - $this->writeDebug($e->getResponse()); - $this->writeDebug($body); - - throw new ApiException( - "[{$e->getCode()}] {$body}", - (int) $e->getCode(), - $hasResponse ? $e->getResponse()->getHeaders() : null, - $body - ); - } catch (ConnectException $e) { - $this->writeDebug($e->getMessage()); - - throw new ApiException( - "[{$e->getCode()}] {$e->getMessage()}", - (int) $e->getCode(), - null, - null - ); - } - - $statusCode = $response->getStatusCode(); - - if ($statusCode < 200 || $statusCode > 299) { - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - (string) $request->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() - ); - } - switch ($statusCode) { - case 200: - if ('\Walmart\Models\MP\US\ItemsDetailsForListing200Response' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\Walmart\Models\MP\US\ItemsDetailsForListing200Response' !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, '\Walmart\Models\MP\US\ItemsDetailsForListing200Response', $response->getHeaders()); - } - - $returnType = '\Walmart\Models\MP\US\ItemsDetailsForListing200Response'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, $returnType, $response->getHeaders()); - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = ObjectSerializer::deserialize( - $e->getResponseBody(), - '\Walmart\Models\MP\US\ItemsDetailsForListing200Response', - $e->getResponseHeaders() - ); - $e->setResponseObject($data); - break; - } - - $this->writeDebug($e); - throw $e; - } - } - - /** - * Operation itemsDetailsForListingAsync - * - * Item Listing Quality Details - * - * @param \Walmart\Models\MP\US\ItemsDetailsForListingRequest $itemsDetailsForListingRequest Request payload (required) - * @param string $limit Specify number of items to return. If no limit is specified, API returns 200 items by default. (optional, default to '200') - * @param string $nextCursor Specify pagination for long list of items. (optional) - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - public function itemsDetailsForListingAsync( - \Walmart\Models\MP\US\ItemsDetailsForListingRequest $itemsDetailsForListingRequest, - ?string $limit = '200', - ?string $nextCursor = null - ): PromiseInterface { - return $this->itemsDetailsForListingAsyncWithHttpInfo($itemsDetailsForListingRequest, $limit, $nextCursor) - ->then( - function ($response) { - return $response[0]; - } - ); - } - - /** - * Operation itemsDetailsForListingAsyncWithHttpInfo - * - * - * Item Listing Quality Details - * - * @param \Walmart\Models\MP\US\ItemsDetailsForListingRequest $itemsDetailsForListingRequest Request payload (required) - * @param string $limit Specify number of items to return. If no limit is specified, API returns 200 items by default. (optional, default to '200') - * @param string $nextCursor Specify pagination for long list of items. (optional) - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - protected function itemsDetailsForListingAsyncWithHttpInfo( - \Walmart\Models\MP\US\ItemsDetailsForListingRequest $itemsDetailsForListingRequest, - ?string $limit = '200', - ?string $nextCursor = null, - ): PromiseInterface { - $returnType = '\Walmart\Models\MP\US\ItemsDetailsForListing200Response'; - $request = $this->itemsDetailsForListingRequest($itemsDetailsForListingRequest, $limit, $nextCursor, ); - $this->writeDebug($request); - $this->writeDebug((string) $request->getBody()); - - return $this->client - ->sendAsync($request, $this->createHttpClientOption()) - ->then( - function ($response) use ($returnType) { - $this->writeDebug($response); - $this->writeDebug((string) $response->getBody()); - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return ObjectSerializer::deserialize($content, $returnType, $response->getHeaders()); - }, - function ($exception) { - $response = $exception->getResponse(); - $hasResponse = !empty($response); - $body = (string) ($hasResponse ? $response->getBody() : '[NULL response]'); - $this->writeDebug($response); - $statusCode = $hasResponse ? $response->getStatusCode() : $exception->getCode(); - - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - $body, - ); - } - ); - } - - /** - * Create request for operation 'itemsDetailsForListing' - * - * @param \Walmart\Models\MP\US\ItemsDetailsForListingRequest $itemsDetailsForListingRequest Request payload (required) - * @param string $limit Specify number of items to return. If no limit is specified, API returns 200 items by default. (optional, default to '200') - * @param string $nextCursor Specify pagination for long list of items. (optional) - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Psr7\Request - */ - protected function itemsDetailsForListingRequest( - \Walmart\Models\MP\US\ItemsDetailsForListingRequest $itemsDetailsForListingRequest, - ?string $limit = '200', - ?string $nextCursor = null, - ): Request { - $contentType = self::contentTypes['itemsDetailsForListing']; - - // verify the required parameter 'itemsDetailsForListingRequest' is set - if ($itemsDetailsForListingRequest === null || (is_array($itemsDetailsForListingRequest) && count($itemsDetailsForListingRequest) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter $itemsDetailsForListingRequest when calling itemsDetailsForListing' - ); - } - $resourcePath = '/v3/insights/items/listingQuality/items'; - $formParams = []; - $queryParams = []; - $headerParams = []; - $httpBody = ''; - $multipart = false; - - // query params - $queryParams = [ - ObjectSerializer::toQueryValue( - $limit, - 'limit', // param base name - 'string', // openApiType - 'form', // style - true, // explode - false // required - ) ?? [], - ObjectSerializer::toQueryValue( - $nextCursor, - 'nextCursor', // param base name - 'string', // openApiType - 'form', // style - true, // explode - false // required - ) ?? [], - ]; - - $headers = $this->headerSelector->selectHeaders( - ['application/json'], - $contentType, - $multipart - ); - - // for model (json/xml) - if (isset($itemsDetailsForListingRequest)) { - if (stripos($headers['Content-Type'], 'application/json') !== false) { - # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($itemsDetailsForListingRequest)); - } else { - $httpBody = $itemsDetailsForListingRequest; - } - } elseif (count($formParams) > 0) { - if ($multipart) { - $multipartContents = []; - foreach ($formParams as $formParamName => $formParamValue) { - $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; - foreach ($formParamValueItems as $formParamValueItem) { - $multipartContents[] = [ - 'name' => $formParamName, - 'contents' => $formParamValueItem - ]; - } - } - // for HTTP post (form) - $httpBody = new MultipartStream($multipartContents); - } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { - # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); - } else { - // for HTTP post (form) - $httpBody = ObjectSerializer::buildQuery($formParams); - } - } - - // this endpoint requires Bearer authentication (access token) - $token = $this->config->getAccessToken(); - if ($token) { - $headers['WM_SEC.ACCESS_TOKEN'] = $token->accessToken; - } - - $defaultHeaders = parent::getDefaultHeaders(); - if ($this->config->getUserAgent()) { - $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); - } - - $headers = array_merge( - $defaultHeaders, - $headerParams, - $headers - ); - - $operationHost = $this->config->getHost(); - $query = ObjectSerializer::buildQuery($queryParams); - return new Request( - 'POST', - $operationHost . $resourcePath . ($query ? "?{$query}" : ''), - $headers, - $httpBody - ); - } -} -