diff --git a/ShoppingMerchantInventories/src/V1beta/Gapic/LocalInventoryServiceGapicClient.php b/ShoppingMerchantInventories/src/V1beta/Gapic/LocalInventoryServiceGapicClient.php deleted file mode 100644 index 95edebf1042d..000000000000 --- a/ShoppingMerchantInventories/src/V1beta/Gapic/LocalInventoryServiceGapicClient.php +++ /dev/null @@ -1,477 +0,0 @@ -localInventoryName('[ACCOUNT]', '[PRODUCT]', '[STORE_CODE]'); - * $localInventoryServiceClient->deleteLocalInventory($formattedName); - * } finally { - * $localInventoryServiceClient->close(); - * } - * ``` - * - * Many parameters require resource names to be formatted in a particular way. To - * assist with these names, this class includes a format method for each type of - * name, and additionally a parseName method to extract the individual identifiers - * contained within formatted names that are returned by the API. - * - * @experimental - */ -class LocalInventoryServiceGapicClient -{ - use GapicClientTrait; - - /** The name of the service. */ - const SERVICE_NAME = 'google.shopping.merchant.inventories.v1beta.LocalInventoryService'; - - /** The default address of the service. */ - const SERVICE_ADDRESS = 'merchantapi.googleapis.com'; - - /** The default port of the service. */ - const DEFAULT_SERVICE_PORT = 443; - - /** The name of the code generator, to be included in the agent header. */ - const CODEGEN_NAME = 'gapic'; - - /** The default scopes required by the service. */ - public static $serviceScopes = ['https://www.googleapis.com/auth/content']; - - private static $localInventoryNameTemplate; - - private static $pathTemplateMap; - - private static function getClientDefaults() - { - return [ - 'serviceName' => self::SERVICE_NAME, - 'apiEndpoint' => - self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, - 'clientConfig' => - __DIR__ . - '/../resources/local_inventory_service_client_config.json', - 'descriptorsConfigPath' => - __DIR__ . - '/../resources/local_inventory_service_descriptor_config.php', - 'gcpApiConfigPath' => - __DIR__ . - '/../resources/local_inventory_service_grpc_config.json', - 'credentialsConfig' => [ - 'defaultScopes' => self::$serviceScopes, - ], - 'transportConfig' => [ - 'rest' => [ - 'restClientConfigPath' => - __DIR__ . - '/../resources/local_inventory_service_rest_client_config.php', - ], - ], - ]; - } - - private static function getLocalInventoryNameTemplate() - { - if (self::$localInventoryNameTemplate == null) { - self::$localInventoryNameTemplate = new PathTemplate( - 'accounts/{account}/products/{product}/localInventories/{store_code}' - ); - } - - return self::$localInventoryNameTemplate; - } - - private static function getPathTemplateMap() - { - if (self::$pathTemplateMap == null) { - self::$pathTemplateMap = [ - 'localInventory' => self::getLocalInventoryNameTemplate(), - ]; - } - - return self::$pathTemplateMap; - } - - /** - * Formats a string containing the fully-qualified path to represent a - * local_inventory resource. - * - * @param string $account - * @param string $product - * @param string $storeCode - * - * @return string The formatted local_inventory resource. - * - * @experimental - */ - public static function localInventoryName($account, $product, $storeCode) - { - return self::getLocalInventoryNameTemplate()->render([ - 'account' => $account, - 'product' => $product, - 'store_code' => $storeCode, - ]); - } - - /** - * Parses a formatted name string and returns an associative array of the components in the name. - * The following name formats are supported: - * Template: Pattern - * - localInventory: accounts/{account}/products/{product}/localInventories/{store_code} - * - * The optional $template argument can be supplied to specify a particular pattern, - * and must match one of the templates listed above. If no $template argument is - * provided, or if the $template argument does not match one of the templates - * listed, then parseName will check each of the supported templates, and return - * the first match. - * - * @param string $formattedName The formatted name string - * @param string $template Optional name of template to match - * - * @return array An associative array from name component IDs to component values. - * - * @throws ValidationException If $formattedName could not be matched. - * - * @experimental - */ - public static function parseName($formattedName, $template = null) - { - $templateMap = self::getPathTemplateMap(); - if ($template) { - if (!isset($templateMap[$template])) { - throw new ValidationException( - "Template name $template does not exist" - ); - } - - return $templateMap[$template]->match($formattedName); - } - - foreach ($templateMap as $templateName => $pathTemplate) { - try { - return $pathTemplate->match($formattedName); - } catch (ValidationException $ex) { - // Swallow the exception to continue trying other path templates - } - } - - throw new ValidationException( - "Input did not match any known format. Input: $formattedName" - ); - } - - /** - * Constructor. - * - * @param array $options { - * Optional. Options for configuring the service API wrapper. - * - * @type string $apiEndpoint - * The address of the API remote host. May optionally include the port, formatted - * as ":". Default 'merchantapi.googleapis.com:443'. - * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials - * The credentials to be used by the client to authorize API calls. This option - * accepts either a path to a credentials file, or a decoded credentials file as a - * PHP array. - * *Advanced usage*: In addition, this option can also accept a pre-constructed - * {@see \Google\Auth\FetchAuthTokenInterface} object or - * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these - * objects are provided, any settings in $credentialsConfig will be ignored. - * @type array $credentialsConfig - * Options used to configure credentials, including auth token caching, for the - * client. For a full list of supporting configuration options, see - * {@see \Google\ApiCore\CredentialsWrapper::build()} . - * @type bool $disableRetries - * Determines whether or not retries defined by the client configuration should be - * disabled. Defaults to `false`. - * @type string|array $clientConfig - * Client method configuration, including retry settings. This option can be either - * a path to a JSON file, or a PHP array containing the decoded JSON data. By - * default this settings points to the default client config file, which is - * provided in the resources folder. - * @type string|TransportInterface $transport - * The transport used for executing network requests. May be either the string - * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. - * *Advanced usage*: Additionally, it is possible to pass in an already - * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note - * that when this object is provided, any settings in $transportConfig, and any - * $apiEndpoint setting, will be ignored. - * @type array $transportConfig - * Configuration options that will be used to construct the transport. Options for - * each supported transport type should be passed in a key for that transport. For - * example: - * $transportConfig = [ - * 'grpc' => [...], - * 'rest' => [...], - * ]; - * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and - * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the - * supported options. - * @type callable $clientCertSource - * A callable which returns the client cert as a string. This can be used to - * provide a certificate and private key to the transport layer for mTLS. - * } - * - * @throws ValidationException - * - * @experimental - */ - public function __construct(array $options = []) - { - $clientOptions = $this->buildClientOptions($options); - $this->setClientOptions($clientOptions); - } - - /** - * Deletes the specified `LocalInventory` from the given product in your - * merchant account. It might take a up to an hour for the - * `LocalInventory` to be deleted from the specific product. - * Once you have received a successful delete response, wait for that - * period before attempting a delete again. - * - * Sample code: - * ``` - * $localInventoryServiceClient = new LocalInventoryServiceClient(); - * try { - * $formattedName = $localInventoryServiceClient->localInventoryName('[ACCOUNT]', '[PRODUCT]', '[STORE_CODE]'); - * $localInventoryServiceClient->deleteLocalInventory($formattedName); - * } finally { - * $localInventoryServiceClient->close(); - * } - * ``` - * - * @param string $name Required. The name of the local inventory for the given product to delete. - * Format: - * `accounts/{account}/products/{product}/localInventories/{store_code}` - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @throws ApiException if the remote call fails - * - * @experimental - */ - public function deleteLocalInventory($name, array $optionalArgs = []) - { - $request = new DeleteLocalInventoryRequest(); - $requestParamHeaders = []; - $request->setName($name); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor( - $requestParamHeaders - ); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - return $this->startCall( - 'DeleteLocalInventory', - GPBEmpty::class, - $optionalArgs, - $request - )->wait(); - } - - /** - * Inserts a `LocalInventory` resource to a product in your merchant - * account. - * - * Replaces the full `LocalInventory` resource if an entry with the same - * [`storeCode`][google.shopping.merchant.inventories.v1beta.LocalInventory.store_code] - * already exists for the product. - * - * It might take up to 30 minutes for the new or updated `LocalInventory` - * resource to appear in products. - * - * Sample code: - * ``` - * $localInventoryServiceClient = new LocalInventoryServiceClient(); - * try { - * $parent = 'parent'; - * $localInventory = new LocalInventory(); - * $response = $localInventoryServiceClient->insertLocalInventory($parent, $localInventory); - * } finally { - * $localInventoryServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. The account and product where this inventory will be inserted. - * Format: `accounts/{account}/products/{product}` - * @param LocalInventory $localInventory Required. Local inventory information of the product. If the product - * already has a `LocalInventory` resource for the same `storeCode`, full - * replacement of the `LocalInventory` resource is performed. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Shopping\Merchant\Inventories\V1beta\LocalInventory - * - * @throws ApiException if the remote call fails - * - * @experimental - */ - public function insertLocalInventory( - $parent, - $localInventory, - array $optionalArgs = [] - ) { - $request = new InsertLocalInventoryRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $request->setLocalInventory($localInventory); - $requestParamHeaders['parent'] = $parent; - $requestParams = new RequestParamsHeaderDescriptor( - $requestParamHeaders - ); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - return $this->startCall( - 'InsertLocalInventory', - LocalInventory::class, - $optionalArgs, - $request - )->wait(); - } - - /** - * Lists the `LocalInventory` resources for the given product in your merchant - * account. The response might contain fewer items than specified by - * `pageSize`. If `pageToken` was returned in previous request, it can be used - * to obtain additional results. - * - * `LocalInventory` resources are listed per product for a given account. - * - * Sample code: - * ``` - * $localInventoryServiceClient = new LocalInventoryServiceClient(); - * try { - * $parent = 'parent'; - * // Iterate over pages of elements - * $pagedResponse = $localInventoryServiceClient->listLocalInventories($parent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $localInventoryServiceClient->listLocalInventories($parent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $localInventoryServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. The `name` of the parent product to list local inventories for. - * Format: - * `accounts/{account}/products/{product}` - * @param array $optionalArgs { - * Optional. - * - * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. - * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\PagedListResponse - * - * @throws ApiException if the remote call fails - * - * @experimental - */ - public function listLocalInventories($parent, array $optionalArgs = []) - { - $request = new ListLocalInventoriesRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['pageSize'])) { - $request->setPageSize($optionalArgs['pageSize']); - } - - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - - $requestParams = new RequestParamsHeaderDescriptor( - $requestParamHeaders - ); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - return $this->getPagedListResponse( - 'ListLocalInventories', - $optionalArgs, - ListLocalInventoriesResponse::class, - $request - ); - } -} diff --git a/ShoppingMerchantInventories/src/V1beta/Gapic/RegionalInventoryServiceGapicClient.php b/ShoppingMerchantInventories/src/V1beta/Gapic/RegionalInventoryServiceGapicClient.php deleted file mode 100644 index a84877920765..000000000000 --- a/ShoppingMerchantInventories/src/V1beta/Gapic/RegionalInventoryServiceGapicClient.php +++ /dev/null @@ -1,477 +0,0 @@ -regionalInventoryName('[ACCOUNT]', '[PRODUCT]', '[REGION]'); - * $regionalInventoryServiceClient->deleteRegionalInventory($formattedName); - * } finally { - * $regionalInventoryServiceClient->close(); - * } - * ``` - * - * Many parameters require resource names to be formatted in a particular way. To - * assist with these names, this class includes a format method for each type of - * name, and additionally a parseName method to extract the individual identifiers - * contained within formatted names that are returned by the API. - * - * @experimental - */ -class RegionalInventoryServiceGapicClient -{ - use GapicClientTrait; - - /** The name of the service. */ - const SERVICE_NAME = 'google.shopping.merchant.inventories.v1beta.RegionalInventoryService'; - - /** The default address of the service. */ - const SERVICE_ADDRESS = 'merchantapi.googleapis.com'; - - /** The default port of the service. */ - const DEFAULT_SERVICE_PORT = 443; - - /** The name of the code generator, to be included in the agent header. */ - const CODEGEN_NAME = 'gapic'; - - /** The default scopes required by the service. */ - public static $serviceScopes = ['https://www.googleapis.com/auth/content']; - - private static $regionalInventoryNameTemplate; - - private static $pathTemplateMap; - - private static function getClientDefaults() - { - return [ - 'serviceName' => self::SERVICE_NAME, - 'apiEndpoint' => - self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, - 'clientConfig' => - __DIR__ . - '/../resources/regional_inventory_service_client_config.json', - 'descriptorsConfigPath' => - __DIR__ . - '/../resources/regional_inventory_service_descriptor_config.php', - 'gcpApiConfigPath' => - __DIR__ . - '/../resources/regional_inventory_service_grpc_config.json', - 'credentialsConfig' => [ - 'defaultScopes' => self::$serviceScopes, - ], - 'transportConfig' => [ - 'rest' => [ - 'restClientConfigPath' => - __DIR__ . - '/../resources/regional_inventory_service_rest_client_config.php', - ], - ], - ]; - } - - private static function getRegionalInventoryNameTemplate() - { - if (self::$regionalInventoryNameTemplate == null) { - self::$regionalInventoryNameTemplate = new PathTemplate( - 'accounts/{account}/products/{product}/regionalInventories/{region}' - ); - } - - return self::$regionalInventoryNameTemplate; - } - - private static function getPathTemplateMap() - { - if (self::$pathTemplateMap == null) { - self::$pathTemplateMap = [ - 'regionalInventory' => self::getRegionalInventoryNameTemplate(), - ]; - } - - return self::$pathTemplateMap; - } - - /** - * Formats a string containing the fully-qualified path to represent a - * regional_inventory resource. - * - * @param string $account - * @param string $product - * @param string $region - * - * @return string The formatted regional_inventory resource. - * - * @experimental - */ - public static function regionalInventoryName($account, $product, $region) - { - return self::getRegionalInventoryNameTemplate()->render([ - 'account' => $account, - 'product' => $product, - 'region' => $region, - ]); - } - - /** - * Parses a formatted name string and returns an associative array of the components in the name. - * The following name formats are supported: - * Template: Pattern - * - regionalInventory: accounts/{account}/products/{product}/regionalInventories/{region} - * - * The optional $template argument can be supplied to specify a particular pattern, - * and must match one of the templates listed above. If no $template argument is - * provided, or if the $template argument does not match one of the templates - * listed, then parseName will check each of the supported templates, and return - * the first match. - * - * @param string $formattedName The formatted name string - * @param string $template Optional name of template to match - * - * @return array An associative array from name component IDs to component values. - * - * @throws ValidationException If $formattedName could not be matched. - * - * @experimental - */ - public static function parseName($formattedName, $template = null) - { - $templateMap = self::getPathTemplateMap(); - if ($template) { - if (!isset($templateMap[$template])) { - throw new ValidationException( - "Template name $template does not exist" - ); - } - - return $templateMap[$template]->match($formattedName); - } - - foreach ($templateMap as $templateName => $pathTemplate) { - try { - return $pathTemplate->match($formattedName); - } catch (ValidationException $ex) { - // Swallow the exception to continue trying other path templates - } - } - - throw new ValidationException( - "Input did not match any known format. Input: $formattedName" - ); - } - - /** - * Constructor. - * - * @param array $options { - * Optional. Options for configuring the service API wrapper. - * - * @type string $apiEndpoint - * The address of the API remote host. May optionally include the port, formatted - * as ":". Default 'merchantapi.googleapis.com:443'. - * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials - * The credentials to be used by the client to authorize API calls. This option - * accepts either a path to a credentials file, or a decoded credentials file as a - * PHP array. - * *Advanced usage*: In addition, this option can also accept a pre-constructed - * {@see \Google\Auth\FetchAuthTokenInterface} object or - * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these - * objects are provided, any settings in $credentialsConfig will be ignored. - * @type array $credentialsConfig - * Options used to configure credentials, including auth token caching, for the - * client. For a full list of supporting configuration options, see - * {@see \Google\ApiCore\CredentialsWrapper::build()} . - * @type bool $disableRetries - * Determines whether or not retries defined by the client configuration should be - * disabled. Defaults to `false`. - * @type string|array $clientConfig - * Client method configuration, including retry settings. This option can be either - * a path to a JSON file, or a PHP array containing the decoded JSON data. By - * default this settings points to the default client config file, which is - * provided in the resources folder. - * @type string|TransportInterface $transport - * The transport used for executing network requests. May be either the string - * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. - * *Advanced usage*: Additionally, it is possible to pass in an already - * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note - * that when this object is provided, any settings in $transportConfig, and any - * $apiEndpoint setting, will be ignored. - * @type array $transportConfig - * Configuration options that will be used to construct the transport. Options for - * each supported transport type should be passed in a key for that transport. For - * example: - * $transportConfig = [ - * 'grpc' => [...], - * 'rest' => [...], - * ]; - * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and - * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the - * supported options. - * @type callable $clientCertSource - * A callable which returns the client cert as a string. This can be used to - * provide a certificate and private key to the transport layer for mTLS. - * } - * - * @throws ValidationException - * - * @experimental - */ - public function __construct(array $options = []) - { - $clientOptions = $this->buildClientOptions($options); - $this->setClientOptions($clientOptions); - } - - /** - * Deletes the specified `RegionalInventory` resource from the given product - * in your merchant account. It might take up to an hour for the - * `RegionalInventory` to be deleted from the specific product. - * Once you have received a successful delete response, wait for that - * period before attempting a delete again. - * - * Sample code: - * ``` - * $regionalInventoryServiceClient = new RegionalInventoryServiceClient(); - * try { - * $formattedName = $regionalInventoryServiceClient->regionalInventoryName('[ACCOUNT]', '[PRODUCT]', '[REGION]'); - * $regionalInventoryServiceClient->deleteRegionalInventory($formattedName); - * } finally { - * $regionalInventoryServiceClient->close(); - * } - * ``` - * - * @param string $name Required. The name of the `RegionalInventory` resource to delete. - * Format: - * `accounts/{account}/products/{product}/regionalInventories/{region}` - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @throws ApiException if the remote call fails - * - * @experimental - */ - public function deleteRegionalInventory($name, array $optionalArgs = []) - { - $request = new DeleteRegionalInventoryRequest(); - $requestParamHeaders = []; - $request->setName($name); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor( - $requestParamHeaders - ); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - return $this->startCall( - 'DeleteRegionalInventory', - GPBEmpty::class, - $optionalArgs, - $request - )->wait(); - } - - /** - * Inserts a `RegionalInventory` to a given product in your - * merchant account. - * - * Replaces the full `RegionalInventory` resource if an entry with the same - * [`region`][google.shopping.merchant.inventories.v1beta.RegionalInventory.region] - * already exists for the product. - * - * It might take up to 30 minutes for the new or updated `RegionalInventory` - * resource to appear in products. - * - * Sample code: - * ``` - * $regionalInventoryServiceClient = new RegionalInventoryServiceClient(); - * try { - * $parent = 'parent'; - * $regionalInventory = new RegionalInventory(); - * $response = $regionalInventoryServiceClient->insertRegionalInventory($parent, $regionalInventory); - * } finally { - * $regionalInventoryServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. The account and product where this inventory will be inserted. - * Format: `accounts/{account}/products/{product}` - * @param RegionalInventory $regionalInventory Required. Regional inventory information to add to the product. If the - * product already has a `RegionalInventory` resource for the same `region`, - * full replacement of the `RegionalInventory` resource is performed. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Shopping\Merchant\Inventories\V1beta\RegionalInventory - * - * @throws ApiException if the remote call fails - * - * @experimental - */ - public function insertRegionalInventory( - $parent, - $regionalInventory, - array $optionalArgs = [] - ) { - $request = new InsertRegionalInventoryRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $request->setRegionalInventory($regionalInventory); - $requestParamHeaders['parent'] = $parent; - $requestParams = new RequestParamsHeaderDescriptor( - $requestParamHeaders - ); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - return $this->startCall( - 'InsertRegionalInventory', - RegionalInventory::class, - $optionalArgs, - $request - )->wait(); - } - - /** - * Lists the `RegionalInventory` resources for the given product in your - * merchant account. The response might contain fewer items than specified by - * `pageSize`. If `pageToken` was returned in previous request, it can be - * used to obtain additional results. - * - * `RegionalInventory` resources are listed per product for a given account. - * - * Sample code: - * ``` - * $regionalInventoryServiceClient = new RegionalInventoryServiceClient(); - * try { - * $parent = 'parent'; - * // Iterate over pages of elements - * $pagedResponse = $regionalInventoryServiceClient->listRegionalInventories($parent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $regionalInventoryServiceClient->listRegionalInventories($parent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $regionalInventoryServiceClient->close(); - * } - * ``` - * - * @param string $parent Required. The `name` of the parent product to list `RegionalInventory` - * resources for. Format: `accounts/{account}/products/{product}` - * @param array $optionalArgs { - * Optional. - * - * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. - * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\PagedListResponse - * - * @throws ApiException if the remote call fails - * - * @experimental - */ - public function listRegionalInventories($parent, array $optionalArgs = []) - { - $request = new ListRegionalInventoriesRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['pageSize'])) { - $request->setPageSize($optionalArgs['pageSize']); - } - - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - - $requestParams = new RequestParamsHeaderDescriptor( - $requestParamHeaders - ); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - return $this->getPagedListResponse( - 'ListRegionalInventories', - $optionalArgs, - ListRegionalInventoriesResponse::class, - $request - ); - } -} diff --git a/ShoppingMerchantInventories/src/V1beta/LocalInventoryServiceClient.php b/ShoppingMerchantInventories/src/V1beta/LocalInventoryServiceClient.php deleted file mode 100644 index 760fd1ae56a3..000000000000 --- a/ShoppingMerchantInventories/src/V1beta/LocalInventoryServiceClient.php +++ /dev/null @@ -1,36 +0,0 @@ -getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); - } - - /** @return LocalInventoryServiceClient */ - private function createClient(array $options = []) - { - $options += [ - 'credentials' => $this->createCredentials(), - ]; - return new LocalInventoryServiceClient($options); - } - - /** @test */ - public function deleteLocalInventoryTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->localInventoryName('[ACCOUNT]', '[PRODUCT]', '[STORE_CODE]'); - $gapicClient->deleteLocalInventory($formattedName); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.shopping.merchant.inventories.v1beta.LocalInventoryService/DeleteLocalInventory', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function deleteLocalInventoryExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $formattedName = $gapicClient->localInventoryName('[ACCOUNT]', '[PRODUCT]', '[STORE_CODE]'); - try { - $gapicClient->deleteLocalInventory($formattedName); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function insertLocalInventoryTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name = 'name3373707'; - $account = 1177318867; - $storeCode = 'storeCode921424523'; - $availability = 'availability1997542747'; - $quantity = 1285004149; - $pickupMethod = 'pickupMethod-950845436'; - $pickupSla = 'pickupSla-964667163'; - $instoreProductLocation = 'instoreProductLocation-243942392'; - $expectedResponse = new LocalInventory(); - $expectedResponse->setName($name); - $expectedResponse->setAccount($account); - $expectedResponse->setStoreCode($storeCode); - $expectedResponse->setAvailability($availability); - $expectedResponse->setQuantity($quantity); - $expectedResponse->setPickupMethod($pickupMethod); - $expectedResponse->setPickupSla($pickupSla); - $expectedResponse->setInstoreProductLocation($instoreProductLocation); - $transport->addResponse($expectedResponse); - // Mock request - $parent = 'parent-995424086'; - $localInventory = new LocalInventory(); - $localInventoryStoreCode = 'localInventoryStoreCode1126909757'; - $localInventory->setStoreCode($localInventoryStoreCode); - $response = $gapicClient->insertLocalInventory($parent, $localInventory); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.shopping.merchant.inventories.v1beta.LocalInventoryService/InsertLocalInventory', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($parent, $actualValue); - $actualValue = $actualRequestObject->getLocalInventory(); - $this->assertProtobufEquals($localInventory, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function insertLocalInventoryExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $parent = 'parent-995424086'; - $localInventory = new LocalInventory(); - $localInventoryStoreCode = 'localInventoryStoreCode1126909757'; - $localInventory->setStoreCode($localInventoryStoreCode); - try { - $gapicClient->insertLocalInventory($parent, $localInventory); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listLocalInventoriesTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $localInventoriesElement = new LocalInventory(); - $localInventories = [ - $localInventoriesElement, - ]; - $expectedResponse = new ListLocalInventoriesResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setLocalInventories($localInventories); - $transport->addResponse($expectedResponse); - // Mock request - $parent = 'parent-995424086'; - $response = $gapicClient->listLocalInventories($parent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getLocalInventories()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.shopping.merchant.inventories.v1beta.LocalInventoryService/ListLocalInventories', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($parent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listLocalInventoriesExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $parent = 'parent-995424086'; - try { - $gapicClient->listLocalInventories($parent); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } -} diff --git a/ShoppingMerchantInventories/tests/Unit/V1beta/RegionalInventoryServiceClientTest.php b/ShoppingMerchantInventories/tests/Unit/V1beta/RegionalInventoryServiceClientTest.php deleted file mode 100644 index 8f1abd6b6218..000000000000 --- a/ShoppingMerchantInventories/tests/Unit/V1beta/RegionalInventoryServiceClientTest.php +++ /dev/null @@ -1,262 +0,0 @@ -getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); - } - - /** @return RegionalInventoryServiceClient */ - private function createClient(array $options = []) - { - $options += [ - 'credentials' => $this->createCredentials(), - ]; - return new RegionalInventoryServiceClient($options); - } - - /** @test */ - public function deleteRegionalInventoryTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->regionalInventoryName('[ACCOUNT]', '[PRODUCT]', '[REGION]'); - $gapicClient->deleteRegionalInventory($formattedName); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.shopping.merchant.inventories.v1beta.RegionalInventoryService/DeleteRegionalInventory', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function deleteRegionalInventoryExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $formattedName = $gapicClient->regionalInventoryName('[ACCOUNT]', '[PRODUCT]', '[REGION]'); - try { - $gapicClient->deleteRegionalInventory($formattedName); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function insertRegionalInventoryTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name = 'name3373707'; - $account = 1177318867; - $region = 'region-934795532'; - $availability = 'availability1997542747'; - $expectedResponse = new RegionalInventory(); - $expectedResponse->setName($name); - $expectedResponse->setAccount($account); - $expectedResponse->setRegion($region); - $expectedResponse->setAvailability($availability); - $transport->addResponse($expectedResponse); - // Mock request - $parent = 'parent-995424086'; - $regionalInventory = new RegionalInventory(); - $regionalInventoryRegion = 'regionalInventoryRegion-40810671'; - $regionalInventory->setRegion($regionalInventoryRegion); - $response = $gapicClient->insertRegionalInventory($parent, $regionalInventory); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.shopping.merchant.inventories.v1beta.RegionalInventoryService/InsertRegionalInventory', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($parent, $actualValue); - $actualValue = $actualRequestObject->getRegionalInventory(); - $this->assertProtobufEquals($regionalInventory, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function insertRegionalInventoryExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $parent = 'parent-995424086'; - $regionalInventory = new RegionalInventory(); - $regionalInventoryRegion = 'regionalInventoryRegion-40810671'; - $regionalInventory->setRegion($regionalInventoryRegion); - try { - $gapicClient->insertRegionalInventory($parent, $regionalInventory); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listRegionalInventoriesTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $regionalInventoriesElement = new RegionalInventory(); - $regionalInventories = [ - $regionalInventoriesElement, - ]; - $expectedResponse = new ListRegionalInventoriesResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setRegionalInventories($regionalInventories); - $transport->addResponse($expectedResponse); - // Mock request - $parent = 'parent-995424086'; - $response = $gapicClient->listRegionalInventories($parent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getRegionalInventories()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.shopping.merchant.inventories.v1beta.RegionalInventoryService/ListRegionalInventories', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($parent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listRegionalInventoriesExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $parent = 'parent-995424086'; - try { - $gapicClient->listRegionalInventories($parent); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } -}