PageRenderTime 38ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/google-listings-and-ads/vendor/googleads/google-ads-php/src/Google/Ads/GoogleAds/V9/Services/Gapic/BiddingStrategySimulationServiceGapicClient.php

https://gitlab.com/remyvianne/krowkaramel
PHP | 300 lines | 103 code | 24 blank | 173 comment | 6 complexity | aaa5f3081bfb50e747aefc1398eaebcf MD5 | raw file
  1. <?php
  2. /*
  3. * Copyright 2021 Google LLC
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * https://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /*
  18. * GENERATED CODE WARNING
  19. * Generated by gapic-generator-php from the file
  20. * https://github.com/google/googleapis/blob/master/google/ads/googleads/v9/services/bidding_strategy_simulation_service.proto
  21. * Updates to the above are reflected here through a refresh process.
  22. */
  23. namespace Google\Ads\GoogleAds\V9\Services\Gapic;
  24. use Google\Ads\GoogleAds\V9\Resources\BiddingStrategySimulation;
  25. use Google\Ads\GoogleAds\V9\Services\GetBiddingStrategySimulationRequest;
  26. use Google\ApiCore\ApiException;
  27. use Google\ApiCore\CredentialsWrapper;
  28. use Google\ApiCore\GapicClientTrait;
  29. use Google\ApiCore\PathTemplate;
  30. use Google\ApiCore\RequestParamsHeaderDescriptor;
  31. use Google\ApiCore\RetrySettings;
  32. use Google\ApiCore\Transport\TransportInterface;
  33. use Google\ApiCore\ValidationException;
  34. use Google\Auth\FetchAuthTokenInterface;
  35. /**
  36. * Service Description: Service to fetch bidding strategy simulations.
  37. *
  38. * This class provides the ability to make remote calls to the backing service through method
  39. * calls that map to API methods. Sample code to get started:
  40. *
  41. * ```
  42. * $biddingStrategySimulationServiceClient = new BiddingStrategySimulationServiceClient();
  43. * try {
  44. * $formattedResourceName = $biddingStrategySimulationServiceClient->biddingStrategySimulationName('[CUSTOMER_ID]', '[BIDDING_STRATEGY_ID]', '[TYPE]', '[MODIFICATION_METHOD]', '[START_DATE]', '[END_DATE]');
  45. * $response = $biddingStrategySimulationServiceClient->getBiddingStrategySimulation($formattedResourceName);
  46. * } finally {
  47. * $biddingStrategySimulationServiceClient->close();
  48. * }
  49. * ```
  50. *
  51. * Many parameters require resource names to be formatted in a particular way. To
  52. * assist with these names, this class includes a format method for each type of
  53. * name, and additionally a parseName method to extract the individual identifiers
  54. * contained within formatted names that are returned by the API.
  55. */
  56. class BiddingStrategySimulationServiceGapicClient
  57. {
  58. use GapicClientTrait;
  59. /**
  60. * The name of the service.
  61. */
  62. const SERVICE_NAME = 'google.ads.googleads.v9.services.BiddingStrategySimulationService';
  63. /**
  64. * The default address of the service.
  65. */
  66. const SERVICE_ADDRESS = 'googleads.googleapis.com';
  67. /**
  68. * The default port of the service.
  69. */
  70. const DEFAULT_SERVICE_PORT = 443;
  71. /**
  72. * The name of the code generator, to be included in the agent header.
  73. */
  74. const CODEGEN_NAME = 'gapic';
  75. /**
  76. * The default scopes required by the service.
  77. */
  78. public static $serviceScopes = [
  79. 'https://www.googleapis.com/auth/adwords',
  80. ];
  81. private static $biddingStrategySimulationNameTemplate;
  82. private static $pathTemplateMap;
  83. private static function getClientDefaults()
  84. {
  85. return [
  86. 'serviceName' => self::SERVICE_NAME,
  87. 'serviceAddress' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT,
  88. 'clientConfig' => __DIR__ . '/../resources/bidding_strategy_simulation_service_client_config.json',
  89. 'descriptorsConfigPath' => __DIR__ . '/../resources/bidding_strategy_simulation_service_descriptor_config.php',
  90. 'gcpApiConfigPath' => __DIR__ . '/../resources/bidding_strategy_simulation_service_grpc_config.json',
  91. 'credentialsConfig' => [
  92. 'defaultScopes' => self::$serviceScopes,
  93. ],
  94. 'transportConfig' => [
  95. 'rest' => [
  96. 'restClientConfigPath' => __DIR__ . '/../resources/bidding_strategy_simulation_service_rest_client_config.php',
  97. ],
  98. ],
  99. ];
  100. }
  101. private static function getBiddingStrategySimulationNameTemplate()
  102. {
  103. if (self::$biddingStrategySimulationNameTemplate == null) {
  104. self::$biddingStrategySimulationNameTemplate = new PathTemplate('customers/{customer_id}/biddingStrategySimulations/{bidding_strategy_id}~{type}~{modification_method}~{start_date}~{end_date}');
  105. }
  106. return self::$biddingStrategySimulationNameTemplate;
  107. }
  108. private static function getPathTemplateMap()
  109. {
  110. if (self::$pathTemplateMap == null) {
  111. self::$pathTemplateMap = [
  112. 'biddingStrategySimulation' => self::getBiddingStrategySimulationNameTemplate(),
  113. ];
  114. }
  115. return self::$pathTemplateMap;
  116. }
  117. /**
  118. * Formats a string containing the fully-qualified path to represent a
  119. * bidding_strategy_simulation resource.
  120. *
  121. * @param string $customerId
  122. * @param string $biddingStrategyId
  123. * @param string $type
  124. * @param string $modificationMethod
  125. * @param string $startDate
  126. * @param string $endDate
  127. *
  128. * @return string The formatted bidding_strategy_simulation resource.
  129. */
  130. public static function biddingStrategySimulationName($customerId, $biddingStrategyId, $type, $modificationMethod, $startDate, $endDate)
  131. {
  132. return self::getBiddingStrategySimulationNameTemplate()->render([
  133. 'customer_id' => $customerId,
  134. 'bidding_strategy_id' => $biddingStrategyId,
  135. 'type' => $type,
  136. 'modification_method' => $modificationMethod,
  137. 'start_date' => $startDate,
  138. 'end_date' => $endDate,
  139. ]);
  140. }
  141. /**
  142. * Parses a formatted name string and returns an associative array of the components in the name.
  143. * The following name formats are supported:
  144. * Template: Pattern
  145. * - biddingStrategySimulation: customers/{customer_id}/biddingStrategySimulations/{bidding_strategy_id}~{type}~{modification_method}~{start_date}~{end_date}
  146. *
  147. * The optional $template argument can be supplied to specify a particular pattern,
  148. * and must match one of the templates listed above. If no $template argument is
  149. * provided, or if the $template argument does not match one of the templates
  150. * listed, then parseName will check each of the supported templates, and return
  151. * the first match.
  152. *
  153. * @param string $formattedName The formatted name string
  154. * @param string $template Optional name of template to match
  155. *
  156. * @return array An associative array from name component IDs to component values.
  157. *
  158. * @throws ValidationException If $formattedName could not be matched.
  159. */
  160. public static function parseName($formattedName, $template = null)
  161. {
  162. $templateMap = self::getPathTemplateMap();
  163. if ($template) {
  164. if (!isset($templateMap[$template])) {
  165. throw new ValidationException("Template name $template does not exist");
  166. }
  167. return $templateMap[$template]->match($formattedName);
  168. }
  169. foreach ($templateMap as $templateName => $pathTemplate) {
  170. try {
  171. return $pathTemplate->match($formattedName);
  172. } catch (ValidationException $ex) {
  173. // Swallow the exception to continue trying other path templates
  174. }
  175. }
  176. throw new ValidationException("Input did not match any known format. Input: $formattedName");
  177. }
  178. /**
  179. * Constructor.
  180. *
  181. * @param array $options {
  182. * Optional. Options for configuring the service API wrapper.
  183. *
  184. * @type string $serviceAddress
  185. * The address of the API remote host. May optionally include the port, formatted
  186. * as "<uri>:<port>". Default 'googleads.googleapis.com:443'.
  187. * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials
  188. * The credentials to be used by the client to authorize API calls. This option
  189. * accepts either a path to a credentials file, or a decoded credentials file as a
  190. * PHP array.
  191. * *Advanced usage*: In addition, this option can also accept a pre-constructed
  192. * {@see \Google\Auth\FetchAuthTokenInterface} object or
  193. * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these
  194. * objects are provided, any settings in $credentialsConfig will be ignored.
  195. * @type array $credentialsConfig
  196. * Options used to configure credentials, including auth token caching, for the
  197. * client. For a full list of supporting configuration options, see
  198. * {@see \Google\ApiCore\CredentialsWrapper::build()} .
  199. * @type bool $disableRetries
  200. * Determines whether or not retries defined by the client configuration should be
  201. * disabled. Defaults to `false`.
  202. * @type string|array $clientConfig
  203. * Client method configuration, including retry settings. This option can be either
  204. * a path to a JSON file, or a PHP array containing the decoded JSON data. By
  205. * default this settings points to the default client config file, which is
  206. * provided in the resources folder.
  207. * @type string|TransportInterface $transport
  208. * The transport used for executing network requests. May be either the string
  209. * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system.
  210. * *Advanced usage*: Additionally, it is possible to pass in an already
  211. * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note
  212. * that when this object is provided, any settings in $transportConfig, and any
  213. * $serviceAddress setting, will be ignored.
  214. * @type array $transportConfig
  215. * Configuration options that will be used to construct the transport. Options for
  216. * each supported transport type should be passed in a key for that transport. For
  217. * example:
  218. * $transportConfig = [
  219. * 'grpc' => [...],
  220. * 'rest' => [...],
  221. * ];
  222. * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and
  223. * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the
  224. * supported options.
  225. * @type callable $clientCertSource
  226. * A callable which returns the client cert as a string. This can be used to
  227. * provide a certificate and private key to the transport layer for mTLS.
  228. * }
  229. *
  230. * @throws ValidationException
  231. */
  232. public function __construct(array $options = [])
  233. {
  234. $clientOptions = $this->buildClientOptions($options);
  235. $this->setClientOptions($clientOptions);
  236. }
  237. /**
  238. * Returns the requested bidding strategy simulation in full detail.
  239. *
  240. * Sample code:
  241. * ```
  242. * $biddingStrategySimulationServiceClient = new BiddingStrategySimulationServiceClient();
  243. * try {
  244. * $formattedResourceName = $biddingStrategySimulationServiceClient->biddingStrategySimulationName('[CUSTOMER_ID]', '[BIDDING_STRATEGY_ID]', '[TYPE]', '[MODIFICATION_METHOD]', '[START_DATE]', '[END_DATE]');
  245. * $response = $biddingStrategySimulationServiceClient->getBiddingStrategySimulation($formattedResourceName);
  246. * } finally {
  247. * $biddingStrategySimulationServiceClient->close();
  248. * }
  249. * ```
  250. *
  251. * @param string $resourceName Required. The resource name of the bidding strategy simulation to fetch.
  252. * @param array $optionalArgs {
  253. * Optional.
  254. *
  255. * @type RetrySettings|array $retrySettings
  256. * Retry settings to use for this call. Can be a
  257. * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry
  258. * settings parameters. See the documentation on
  259. * {@see Google\ApiCore\RetrySettings} for example usage.
  260. * }
  261. *
  262. * @return \Google\Ads\GoogleAds\V9\Resources\BiddingStrategySimulation
  263. *
  264. * @throws ApiException if the remote call fails
  265. */
  266. public function getBiddingStrategySimulation($resourceName, array $optionalArgs = [])
  267. {
  268. $request = new GetBiddingStrategySimulationRequest();
  269. $requestParamHeaders = [];
  270. $request->setResourceName($resourceName);
  271. $requestParamHeaders['resource_name'] = $resourceName;
  272. $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders);
  273. $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader();
  274. return $this->startCall('GetBiddingStrategySimulation', BiddingStrategySimulation::class, $optionalArgs, $request)->wait();
  275. }
  276. }