From 185b8ddb8378337de4162e22bdb8d6f82398e701 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Mon, 23 Dec 2024 12:40:35 -0800 Subject: [PATCH] feat(dev): add samples to README --- AdsAdManager/README.md | 23 ++++++ AdsMarketingPlatformAdmin/README.md | 23 ++++++ AdvisoryNotifications/README.md | 23 ++++++ AlloyDb/README.md | 23 ++++++ ApiHub/README.md | 23 ++++++ AppHub/README.md | 23 ++++++ AppsChat/README.md | 23 ++++++ AppsEventsSubscriptions/README.md | 23 ++++++ AppsMeet/README.md | 23 ++++++ BackupDr/README.md | 23 ++++++ CommerceConsumerProcurement/README.md | 23 ++++++ ConfidentialComputing/README.md | 22 ++++++ Config/README.md | 23 ++++++ ControlsPartner/README.md | 23 ++++++ DataCatalogLineage/README.md | 25 ++++++- DeveloperConnect/README.md | 23 ++++++ DialogflowCx/README.md | 23 ++++++ DiscoveryEngine/README.md | 23 ++++++ EdgeNetwork/README.md | 23 ++++++ ErrorReporting/README.md | 23 ++++++ KmsInventory/README.md | 23 ++++++ ManagedKafka/README.md | 23 ++++++ MapsFleetEngine/README.md | 23 ++++++ MapsFleetEngineDelivery/README.md | 23 ++++++ MapsRouteOptimization/README.md | 23 ++++++ Memorystore/README.md | 23 ++++++ MigrationCenter/README.md | 23 ++++++ NetApp/README.md | 23 ++++++ NetworkServices/README.md | 23 ++++++ OracleDatabase/README.md | 23 ++++++ Parallelstore/README.md | 23 ++++++ PolicySimulator/README.md | 23 ++++++ PolicyTroubleshooterIam/README.md | 22 ++++++ PrivilegedAccessManager/README.md | 23 ++++++ Quotas/README.md | 23 ++++++ RapidMigrationAssessment/README.md | 23 ++++++ RedisCluster/README.md | 23 ++++++ SecureSourceManager/README.md | 23 ++++++ SecurityCenterManagement/README.md | 23 ++++++ ServiceHealth/README.md | 23 ++++++ ShoppingCss/README.md | 23 ++++++ ShoppingMerchantAccounts/README.md | 23 ++++++ ShoppingMerchantConversions/README.md | 23 ++++++ ShoppingMerchantDataSources/README.md | 23 ++++++ ShoppingMerchantInventories/README.md | 21 ++++++ ShoppingMerchantLfp/README.md | 23 ++++++ ShoppingMerchantNotifications/README.md | 23 ++++++ ShoppingMerchantProducts/README.md | 23 ++++++ ShoppingMerchantPromotions/README.md | 23 ++++++ ShoppingMerchantQuota/README.md | 28 ++++++++ ShoppingMerchantReports/README.md | 29 ++++++++ ShoppingMerchantReviews/README.md | 23 ++++++ StorageControl/README.md | 23 ++++++ StorageInsights/README.md | 22 ++++++ Support/README.md | 23 ++++++ TelcoAutomation/README.md | 23 ++++++ Translate/README.md | 50 ++++++++++++- dev/google-cloud | 2 + dev/src/Command/AddComponentCommand.php | 4 -- dev/src/Command/AddSampleToReadmeCommand.php | 74 ++++++++++++++++++++ dev/src/Component.php | 55 +++++++++++++++ dev/src/NewComponent.php | 1 + dev/tests/Unit/ComponentTest.php | 10 +++ 63 files changed, 1485 insertions(+), 7 deletions(-) create mode 100644 dev/src/Command/AddSampleToReadmeCommand.php diff --git a/AdsAdManager/README.md b/AdsAdManager/README.md index 57cd9b172508..b36a2b6d9a07 100644 --- a/AdsAdManager/README.md +++ b/AdsAdManager/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\Ads\AdManager\V1\AdUnit; +Google\Ads\AdManager\V1\Client\AdUnitServiceClient; +Google\Ads\AdManager\V1\GetAdUnitRequest; +Google\ApiCore\ApiException; + +// Create a client. +$adUnitServiceClient = new AdUnitServiceClient(); + +// Prepare the request message. +$request = (new GetAdUnitRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var AdUnit $response */ + $response = $adUnitServiceClient->getAdUnit($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-ads-ad-manager/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/AdsMarketingPlatformAdmin/README.md b/AdsMarketingPlatformAdmin/README.md index 4e0da390b14f..227697d1c97a 100644 --- a/AdsMarketingPlatformAdmin/README.md +++ b/AdsMarketingPlatformAdmin/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\Ads\MarketingPlatform\Admin\V1alpha\Client\MarketingplatformAdminServiceClient; +Google\Ads\MarketingPlatform\Admin\V1alpha\GetOrganizationRequest; +Google\Ads\MarketingPlatform\Admin\V1alpha\Organization; +Google\ApiCore\ApiException; + +// Create a client. +$marketingplatformAdminServiceClient = new MarketingplatformAdminServiceClient(); + +// Prepare the request message. +$request = (new GetOrganizationRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Organization $response */ + $response = $marketingplatformAdminServiceClient->getOrganization($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-ads-marketingplatform-admin/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/AdvisoryNotifications/README.md b/AdvisoryNotifications/README.md index 130e86a0859c..30a6f475c368 100644 --- a/AdvisoryNotifications/README.md +++ b/AdvisoryNotifications/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\AdvisoryNotifications\V1\Client\AdvisoryNotificationsServiceClient; +Google\Cloud\AdvisoryNotifications\V1\GetNotificationRequest; +Google\Cloud\AdvisoryNotifications\V1\Notification; + +// Create a client. +$advisoryNotificationsServiceClient = new AdvisoryNotificationsServiceClient(); + +// Prepare the request message. +$request = (new GetNotificationRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Notification $response */ + $response = $advisoryNotificationsServiceClient->getNotification($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-advisorynotifications/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/AlloyDb/README.md b/AlloyDb/README.md index a3fa4b07c309..d39fd73990cb 100644 --- a/AlloyDb/README.md +++ b/AlloyDb/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\AlloyDb\V1\Backup; +Google\Cloud\AlloyDb\V1\Client\AlloyDBAdminClient; +Google\Cloud\AlloyDb\V1\GetBackupRequest; + +// Create a client. +$alloyDBAdminClient = new AlloyDBAdminClient(); + +// Prepare the request message. +$request = (new GetBackupRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Backup $response */ + $response = $alloyDBAdminClient->getBackup($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-alloydb/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/ApiHub/README.md b/ApiHub/README.md index fa6d935da323..0831b83f10d3 100644 --- a/ApiHub/README.md +++ b/ApiHub/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\ApiHub\V1\Api; +Google\Cloud\ApiHub\V1\Client\ApiHubClient; +Google\Cloud\ApiHub\V1\GetApiRequest; + +// Create a client. +$apiHubClient = new ApiHubClient(); + +// Prepare the request message. +$request = (new GetApiRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Api $response */ + $response = $apiHubClient->getApi($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-apihub/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/AppHub/README.md b/AppHub/README.md index 91c160a6df9c..4bef10c112b1 100644 --- a/AppHub/README.md +++ b/AppHub/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\AppHub\V1\Application; +Google\Cloud\AppHub\V1\Client\AppHubClient; +Google\Cloud\AppHub\V1\GetApplicationRequest; + +// Create a client. +$appHubClient = new AppHubClient(); + +// Prepare the request message. +$request = (new GetApplicationRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Application $response */ + $response = $appHubClient->getApplication($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-apphub/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/AppsChat/README.md b/AppsChat/README.md index 33c1abfcdc84..8941e889c5e6 100644 --- a/AppsChat/README.md +++ b/AppsChat/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Apps\Chat\V1\Attachment; +Google\Apps\Chat\V1\Client\ChatServiceClient; +Google\Apps\Chat\V1\GetAttachmentRequest; + +// Create a client. +$chatServiceClient = new ChatServiceClient(); + +// Prepare the request message. +$request = (new GetAttachmentRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Attachment $response */ + $response = $chatServiceClient->getAttachment($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-chat/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/AppsEventsSubscriptions/README.md b/AppsEventsSubscriptions/README.md index e3abf240e369..0cfa6d3cfa74 100644 --- a/AppsEventsSubscriptions/README.md +++ b/AppsEventsSubscriptions/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Apps\Events\Subscriptions\V1\Client\SubscriptionsServiceClient; +Google\Apps\Events\Subscriptions\V1\GetSubscriptionRequest; +Google\Apps\Events\Subscriptions\V1\Subscription; + +// Create a client. +$subscriptionsServiceClient = new SubscriptionsServiceClient(); + +// Prepare the request message. +$request = (new GetSubscriptionRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Subscription $response */ + $response = $subscriptionsServiceClient->getSubscription($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-apps-events-subscriptions/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/AppsMeet/README.md b/AppsMeet/README.md index 0e7ccf2ef1af..5298347b554b 100644 --- a/AppsMeet/README.md +++ b/AppsMeet/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Apps\Meet\V2\Client\ConferenceRecordsServiceClient; +Google\Apps\Meet\V2\ConferenceRecord; +Google\Apps\Meet\V2\GetConferenceRecordRequest; + +// Create a client. +$conferenceRecordsServiceClient = new ConferenceRecordsServiceClient(); + +// Prepare the request message. +$request = (new GetConferenceRecordRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var ConferenceRecord $response */ + $response = $conferenceRecordsServiceClient->getConferenceRecord($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-apps-meet/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/BackupDr/README.md b/BackupDr/README.md index a2ad73851c31..88bda21d7318 100644 --- a/BackupDr/README.md +++ b/BackupDr/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\BackupDR\V1\Backup; +Google\Cloud\BackupDR\V1\Client\BackupDRClient; +Google\Cloud\BackupDR\V1\GetBackupRequest; + +// Create a client. +$backupDRClient = new BackupDRClient(); + +// Prepare the request message. +$request = (new GetBackupRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Backup $response */ + $response = $backupDRClient->getBackup($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-backupdr/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/CommerceConsumerProcurement/README.md b/CommerceConsumerProcurement/README.md index 7ffc22294d20..ef1f5fe60a90 100644 --- a/CommerceConsumerProcurement/README.md +++ b/CommerceConsumerProcurement/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\Commerce\Consumer\Procurement\V1\Client\ConsumerProcurementServiceClient; +Google\Cloud\Commerce\Consumer\Procurement\V1\GetOrderRequest; +Google\Cloud\Commerce\Consumer\Procurement\V1\Order; + +// Create a client. +$consumerProcurementServiceClient = new ConsumerProcurementServiceClient(); + +// Prepare the request message. +$request = (new GetOrderRequest()) + ->setName($name); + +// Call the API and handle any network failures. +try { + /** @var Order $response */ + $response = $consumerProcurementServiceClient->getOrder($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-commerce-consumer-procurement/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/ConfidentialComputing/README.md b/ConfidentialComputing/README.md index beeabdc2769e..97739b5534da 100644 --- a/ConfidentialComputing/README.md +++ b/ConfidentialComputing/README.md @@ -34,6 +34,28 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\ConfidentialComputing\V1\Client\ConfidentialComputingClient; +Google\Cloud\Location\GetLocationRequest; +Google\Cloud\Location\Location; + +// Create a client. +$confidentialComputingClient = new ConfidentialComputingClient(); + +// Prepare the request message. +$request = new GetLocationRequest(); + +// Call the API and handle any network failures. +try { + /** @var Location $response */ + $response = $confidentialComputingClient->getLocation($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-confidentialcomputing/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/Config/README.md b/Config/README.md index 86dcaaa7b9cf..c19a363e60bb 100644 --- a/Config/README.md +++ b/Config/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\Config\V1\Client\ConfigClient; +Google\Cloud\Config\V1\Deployment; +Google\Cloud\Config\V1\GetDeploymentRequest; + +// Create a client. +$configClient = new ConfigClient(); + +// Prepare the request message. +$request = (new GetDeploymentRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Deployment $response */ + $response = $configClient->getDeployment($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-config/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/ControlsPartner/README.md b/ControlsPartner/README.md index 69fa709d73c7..ebd768aaced0 100644 --- a/ControlsPartner/README.md +++ b/ControlsPartner/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\CloudControlsPartner\V1beta\Client\CloudControlsPartnerCoreClient; +Google\Cloud\CloudControlsPartner\V1beta\Customer; +Google\Cloud\CloudControlsPartner\V1beta\GetCustomerRequest; + +// Create a client. +$cloudControlsPartnerCoreClient = new CloudControlsPartnerCoreClient(); + +// Prepare the request message. +$request = (new GetCustomerRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Customer $response */ + $response = $cloudControlsPartnerCoreClient->getCustomer($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-cloudcontrolspartner/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/DataCatalogLineage/README.md b/DataCatalogLineage/README.md index 3e0a267327ce..fae635a8f79b 100644 --- a/DataCatalogLineage/README.md +++ b/DataCatalogLineage/README.md @@ -28,7 +28,30 @@ $ composer require google/cloud-datacatalog-lineage Please see our [Authentication guide](https://github.com/googleapis/google-cloud-php/blob/main/AUTHENTICATION.md) for more information on authenticating your client. Once authenticated, you'll be ready to start making requests. -### Samples +### Sample + +```php +Google\ApiCore\ApiException; +Google\Cloud\DataCatalog\Lineage\V1\Client\LineageClient; +Google\Cloud\DataCatalog\Lineage\V1\GetLineageEventRequest; +Google\Cloud\DataCatalog\Lineage\V1\LineageEvent; + +// Create a client. +$lineageClient = new LineageClient(); + +// Prepare the request message. +$request = (new GetLineageEventRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var LineageEvent $response */ + $response = $lineageClient->getLineageEvent($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +```s See the [samples directory](samples/) for a canonical list of samples. diff --git a/DeveloperConnect/README.md b/DeveloperConnect/README.md index 6d3e2078165f..233d40813549 100644 --- a/DeveloperConnect/README.md +++ b/DeveloperConnect/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\DeveloperConnect\V1\Client\DeveloperConnectClient; +Google\Cloud\DeveloperConnect\V1\Connection; +Google\Cloud\DeveloperConnect\V1\GetConnectionRequest; + +// Create a client. +$developerConnectClient = new DeveloperConnectClient(); + +// Prepare the request message. +$request = (new GetConnectionRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Connection $response */ + $response = $developerConnectClient->getConnection($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-developerconnect/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/DialogflowCx/README.md b/DialogflowCx/README.md index e4e8df0c0f17..b396e5b4ee96 100644 --- a/DialogflowCx/README.md +++ b/DialogflowCx/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\Dialogflow\Cx\V3\Agent; +Google\Cloud\Dialogflow\Cx\V3\Client\AgentsClient; +Google\Cloud\Dialogflow\Cx\V3\GetAgentRequest; + +// Create a client. +$agentsClient = new AgentsClient(); + +// Prepare the request message. +$request = (new GetAgentRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Agent $response */ + $response = $agentsClient->getAgent($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-dialogflow-cx/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/DiscoveryEngine/README.md b/DiscoveryEngine/README.md index 85dac5c2f788..22e23380a15c 100644 --- a/DiscoveryEngine/README.md +++ b/DiscoveryEngine/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\DiscoveryEngine\V1\Client\ControlServiceClient; +Google\Cloud\DiscoveryEngine\V1\Control; +Google\Cloud\DiscoveryEngine\V1\GetControlRequest; + +// Create a client. +$controlServiceClient = new ControlServiceClient(); + +// Prepare the request message. +$request = (new GetControlRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Control $response */ + $response = $controlServiceClient->getControl($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-discoveryengine/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/EdgeNetwork/README.md b/EdgeNetwork/README.md index 356c1089b0c7..b477c58d7e58 100644 --- a/EdgeNetwork/README.md +++ b/EdgeNetwork/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\EdgeNetwork\V1\Client\EdgeNetworkClient; +Google\Cloud\EdgeNetwork\V1\GetInterconnectRequest; +Google\Cloud\EdgeNetwork\V1\Interconnect; + +// Create a client. +$edgeNetworkClient = new EdgeNetworkClient(); + +// Prepare the request message. +$request = (new GetInterconnectRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Interconnect $response */ + $response = $edgeNetworkClient->getInterconnect($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-edgenetwork/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/ErrorReporting/README.md b/ErrorReporting/README.md index 2e83f860970d..f3ad070c9ebb 100644 --- a/ErrorReporting/README.md +++ b/ErrorReporting/README.md @@ -32,6 +32,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\ErrorReporting\V1beta1\Client\ErrorGroupServiceClient; +Google\Cloud\ErrorReporting\V1beta1\ErrorGroup; +Google\Cloud\ErrorReporting\V1beta1\GetGroupRequest; + +// Create a client. +$errorGroupServiceClient = new ErrorGroupServiceClient(); + +// Prepare the request message. +$request = (new GetGroupRequest()) + ->setGroupName($formattedGroupName); + +// Call the API and handle any network failures. +try { + /** @var ErrorGroup $response */ + $response = $errorGroupServiceClient->getGroup($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + The Stackdriver Error Reporting client provides APIs allowing you to easily configure your application to send errors and exceptions automatically to Stackdriver, or to manually report and manage errors and statistics. #### Reporting errors from your application: diff --git a/KmsInventory/README.md b/KmsInventory/README.md index b69fd4f497f5..d60089dbe197 100644 --- a/KmsInventory/README.md +++ b/KmsInventory/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\Kms\Inventory\V1\Client\KeyTrackingServiceClient; +Google\Cloud\Kms\Inventory\V1\GetProtectedResourcesSummaryRequest; +Google\Cloud\Kms\Inventory\V1\ProtectedResourcesSummary; + +// Create a client. +$keyTrackingServiceClient = new KeyTrackingServiceClient(); + +// Prepare the request message. +$request = (new GetProtectedResourcesSummaryRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var ProtectedResourcesSummary $response */ + $response = $keyTrackingServiceClient->getProtectedResourcesSummary($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-kms-inventory/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/ManagedKafka/README.md b/ManagedKafka/README.md index 67a729e81c71..93ac69ea3da2 100644 --- a/ManagedKafka/README.md +++ b/ManagedKafka/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\ManagedKafka\V1\Client\ManagedKafkaClient; +Google\Cloud\ManagedKafka\V1\Cluster; +Google\Cloud\ManagedKafka\V1\GetClusterRequest; + +// Create a client. +$managedKafkaClient = new ManagedKafkaClient(); + +// Prepare the request message. +$request = (new GetClusterRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Cluster $response */ + $response = $managedKafkaClient->getCluster($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-managedkafka/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/MapsFleetEngine/README.md b/MapsFleetEngine/README.md index c161ce424535..d61465af85e4 100644 --- a/MapsFleetEngine/README.md +++ b/MapsFleetEngine/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Maps\FleetEngine\V1\Client\TripServiceClient; +Google\Maps\FleetEngine\V1\GetTripRequest; +Google\Maps\FleetEngine\V1\Trip; + +// Create a client. +$tripServiceClient = new TripServiceClient(); + +// Prepare the request message. +$request = (new GetTripRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Trip $response */ + $response = $tripServiceClient->getTrip($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-maps-fleetengine/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/MapsFleetEngineDelivery/README.md b/MapsFleetEngineDelivery/README.md index 204d2b577141..5c711f4532ba 100644 --- a/MapsFleetEngineDelivery/README.md +++ b/MapsFleetEngineDelivery/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Maps\FleetEngine\Delivery\V1\Client\DeliveryServiceClient; +Google\Maps\FleetEngine\Delivery\V1\DeliveryVehicle; +Google\Maps\FleetEngine\Delivery\V1\GetDeliveryVehicleRequest; + +// Create a client. +$deliveryServiceClient = new DeliveryServiceClient(); + +// Prepare the request message. +$request = (new GetDeliveryVehicleRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var DeliveryVehicle $response */ + $response = $deliveryServiceClient->getDeliveryVehicle($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-maps-fleetengine-delivery/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/MapsRouteOptimization/README.md b/MapsRouteOptimization/README.md index df18f080e378..8cbd5ef6e516 100644 --- a/MapsRouteOptimization/README.md +++ b/MapsRouteOptimization/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Maps\RouteOptimization\V1\Client\RouteOptimizationClient; +Google\Maps\RouteOptimization\V1\OptimizeToursRequest; +Google\Maps\RouteOptimization\V1\OptimizeToursResponse; + +// Create a client. +$routeOptimizationClient = new RouteOptimizationClient(); + +// Prepare the request message. +$request = (new OptimizeToursRequest()) + ->setParent($parent); + +// Call the API and handle any network failures. +try { + /** @var OptimizeToursResponse $response */ + $response = $routeOptimizationClient->optimizeTours($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-maps-routeoptimization/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/Memorystore/README.md b/Memorystore/README.md index 904020b1f9bc..f7ded83ba871 100644 --- a/Memorystore/README.md +++ b/Memorystore/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\Memorystore\V1\CertificateAuthority; +Google\Cloud\Memorystore\V1\Client\MemorystoreClient; +Google\Cloud\Memorystore\V1\GetCertificateAuthorityRequest; + +// Create a client. +$memorystoreClient = new MemorystoreClient(); + +// Prepare the request message. +$request = (new GetCertificateAuthorityRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var CertificateAuthority $response */ + $response = $memorystoreClient->getCertificateAuthority($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-memorystore/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/MigrationCenter/README.md b/MigrationCenter/README.md index 0573b970bb1d..a2929e93e267 100644 --- a/MigrationCenter/README.md +++ b/MigrationCenter/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\MigrationCenter\V1\Asset; +Google\Cloud\MigrationCenter\V1\Client\MigrationCenterClient; +Google\Cloud\MigrationCenter\V1\GetAssetRequest; + +// Create a client. +$migrationCenterClient = new MigrationCenterClient(); + +// Prepare the request message. +$request = (new GetAssetRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Asset $response */ + $response = $migrationCenterClient->getAsset($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-migrationcenter/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/NetApp/README.md b/NetApp/README.md index 85ac11fa76f6..c2141b61543e 100644 --- a/NetApp/README.md +++ b/NetApp/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\NetApp\V1\ActiveDirectory; +Google\Cloud\NetApp\V1\Client\NetAppClient; +Google\Cloud\NetApp\V1\GetActiveDirectoryRequest; + +// Create a client. +$netAppClient = new NetAppClient(); + +// Prepare the request message. +$request = (new GetActiveDirectoryRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var ActiveDirectory $response */ + $response = $netAppClient->getActiveDirectory($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-netapp/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/NetworkServices/README.md b/NetworkServices/README.md index 832a6b5951da..2bc1f68294fe 100644 --- a/NetworkServices/README.md +++ b/NetworkServices/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\NetworkServices\V1\Client\DepServiceClient; +Google\Cloud\NetworkServices\V1\GetLbRouteExtensionRequest; +Google\Cloud\NetworkServices\V1\LbRouteExtension; + +// Create a client. +$depServiceClient = new DepServiceClient(); + +// Prepare the request message. +$request = (new GetLbRouteExtensionRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var LbRouteExtension $response */ + $response = $depServiceClient->getLbRouteExtension($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-networkservices/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/OracleDatabase/README.md b/OracleDatabase/README.md index 492d174a60ca..b65427d514c4 100644 --- a/OracleDatabase/README.md +++ b/OracleDatabase/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\OracleDatabase\V1\AutonomousDatabase; +Google\Cloud\OracleDatabase\V1\Client\OracleDatabaseClient; +Google\Cloud\OracleDatabase\V1\GetAutonomousDatabaseRequest; + +// Create a client. +$oracleDatabaseClient = new OracleDatabaseClient(); + +// Prepare the request message. +$request = (new GetAutonomousDatabaseRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var AutonomousDatabase $response */ + $response = $oracleDatabaseClient->getAutonomousDatabase($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-oracledatabase/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/Parallelstore/README.md b/Parallelstore/README.md index 9999deb52b0a..425de3129692 100644 --- a/Parallelstore/README.md +++ b/Parallelstore/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\Parallelstore\V1\Client\ParallelstoreClient; +Google\Cloud\Parallelstore\V1\GetInstanceRequest; +Google\Cloud\Parallelstore\V1\Instance; + +// Create a client. +$parallelstoreClient = new ParallelstoreClient(); + +// Prepare the request message. +$request = (new GetInstanceRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Instance $response */ + $response = $parallelstoreClient->getInstance($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-parallelstore/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/PolicySimulator/README.md b/PolicySimulator/README.md index 54dbe57c16b1..98438432fefa 100644 --- a/PolicySimulator/README.md +++ b/PolicySimulator/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\PolicySimulator\V1\Client\SimulatorClient; +Google\Cloud\PolicySimulator\V1\GetReplayRequest; +Google\Cloud\PolicySimulator\V1\Replay; + +// Create a client. +$simulatorClient = new SimulatorClient(); + +// Prepare the request message. +$request = (new GetReplayRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Replay $response */ + $response = $simulatorClient->getReplay($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-policysimulator/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/PolicyTroubleshooterIam/README.md b/PolicyTroubleshooterIam/README.md index 1651af75c3ac..23216b51c816 100644 --- a/PolicyTroubleshooterIam/README.md +++ b/PolicyTroubleshooterIam/README.md @@ -34,6 +34,28 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\PolicyTroubleshooter\Iam\V3\Client\PolicyTroubleshooterClient; +Google\Cloud\PolicyTroubleshooter\Iam\V3\TroubleshootIamPolicyRequest; +Google\Cloud\PolicyTroubleshooter\Iam\V3\TroubleshootIamPolicyResponse; + +// Create a client. +$policyTroubleshooterClient = new PolicyTroubleshooterClient(); + +// Prepare the request message. +$request = new TroubleshootIamPolicyRequest(); + +// Call the API and handle any network failures. +try { + /** @var TroubleshootIamPolicyResponse $response */ + $response = $policyTroubleshooterClient->troubleshootIamPolicy($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-policytroubleshooter-iam/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/PrivilegedAccessManager/README.md b/PrivilegedAccessManager/README.md index 9ff1c90482eb..88d6519890d2 100644 --- a/PrivilegedAccessManager/README.md +++ b/PrivilegedAccessManager/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\PrivilegedAccessManager\V1\Client\PrivilegedAccessManagerClient; +Google\Cloud\PrivilegedAccessManager\V1\Entitlement; +Google\Cloud\PrivilegedAccessManager\V1\GetEntitlementRequest; + +// Create a client. +$privilegedAccessManagerClient = new PrivilegedAccessManagerClient(); + +// Prepare the request message. +$request = (new GetEntitlementRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Entitlement $response */ + $response = $privilegedAccessManagerClient->getEntitlement($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-privilegedaccessmanager/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/Quotas/README.md b/Quotas/README.md index b8411a7fb548..e300d5c57bfe 100644 --- a/Quotas/README.md +++ b/Quotas/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\CloudQuotas\V1\Client\CloudQuotasClient; +Google\Cloud\CloudQuotas\V1\GetQuotaInfoRequest; +Google\Cloud\CloudQuotas\V1\QuotaInfo; + +// Create a client. +$cloudQuotasClient = new CloudQuotasClient(); + +// Prepare the request message. +$request = (new GetQuotaInfoRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var QuotaInfo $response */ + $response = $cloudQuotasClient->getQuotaInfo($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-quotas/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/RapidMigrationAssessment/README.md b/RapidMigrationAssessment/README.md index ff4d5700af85..7c3c2855bcf8 100644 --- a/RapidMigrationAssessment/README.md +++ b/RapidMigrationAssessment/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\RapidMigrationAssessment\V1\Annotation; +Google\Cloud\RapidMigrationAssessment\V1\Client\RapidMigrationAssessmentClient; +Google\Cloud\RapidMigrationAssessment\V1\GetAnnotationRequest; + +// Create a client. +$rapidMigrationAssessmentClient = new RapidMigrationAssessmentClient(); + +// Prepare the request message. +$request = (new GetAnnotationRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Annotation $response */ + $response = $rapidMigrationAssessmentClient->getAnnotation($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-rapidmigrationassessment/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/RedisCluster/README.md b/RedisCluster/README.md index 4c15cacf7b51..13b6abe16283 100644 --- a/RedisCluster/README.md +++ b/RedisCluster/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\Redis\Cluster\V1\Client\CloudRedisClusterClient; +Google\Cloud\Redis\Cluster\V1\Cluster; +Google\Cloud\Redis\Cluster\V1\GetClusterRequest; + +// Create a client. +$cloudRedisClusterClient = new CloudRedisClusterClient(); + +// Prepare the request message. +$request = (new GetClusterRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Cluster $response */ + $response = $cloudRedisClusterClient->getCluster($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-redis-cluster/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/SecureSourceManager/README.md b/SecureSourceManager/README.md index 06fd1cc19801..0e45d3fff312 100644 --- a/SecureSourceManager/README.md +++ b/SecureSourceManager/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\SecureSourceManager\V1\BranchRule; +Google\Cloud\SecureSourceManager\V1\Client\SecureSourceManagerClient; +Google\Cloud\SecureSourceManager\V1\GetBranchRuleRequest; + +// Create a client. +$secureSourceManagerClient = new SecureSourceManagerClient(); + +// Prepare the request message. +$request = (new GetBranchRuleRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var BranchRule $response */ + $response = $secureSourceManagerClient->getBranchRule($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-securesourcemanager/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/SecurityCenterManagement/README.md b/SecurityCenterManagement/README.md index 705013af5a4e..f202c4501ecd 100644 --- a/SecurityCenterManagement/README.md +++ b/SecurityCenterManagement/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\SecurityCenterManagement\V1\Client\SecurityCenterManagementClient; +Google\Cloud\SecurityCenterManagement\V1\EffectiveEventThreatDetectionCustomModule; +Google\Cloud\SecurityCenterManagement\V1\GetEffectiveEventThreatDetectionCustomModuleRequest; + +// Create a client. +$securityCenterManagementClient = new SecurityCenterManagementClient(); + +// Prepare the request message. +$request = (new GetEffectiveEventThreatDetectionCustomModuleRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var EffectiveEventThreatDetectionCustomModule $response */ + $response = $securityCenterManagementClient->getEffectiveEventThreatDetectionCustomModule($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-securitycentermanagement/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/ServiceHealth/README.md b/ServiceHealth/README.md index 039f2470c181..a5a5c67484de 100644 --- a/ServiceHealth/README.md +++ b/ServiceHealth/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\ServiceHealth\V1\Client\ServiceHealthClient; +Google\Cloud\ServiceHealth\V1\Event; +Google\Cloud\ServiceHealth\V1\GetEventRequest; + +// Create a client. +$serviceHealthClient = new ServiceHealthClient(); + +// Prepare the request message. +$request = (new GetEventRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Event $response */ + $response = $serviceHealthClient->getEvent($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-servicehealth/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/ShoppingCss/README.md b/ShoppingCss/README.md index 3b9c85ea879a..302127c3c39b 100644 --- a/ShoppingCss/README.md +++ b/ShoppingCss/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Shopping\Css\V1\Account; +Google\Shopping\Css\V1\Client\AccountsServiceClient; +Google\Shopping\Css\V1\GetAccountRequest; + +// Create a client. +$accountsServiceClient = new AccountsServiceClient(); + +// Prepare the request message. +$request = (new GetAccountRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Account $response */ + $response = $accountsServiceClient->getAccount($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-shopping-css/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/ShoppingMerchantAccounts/README.md b/ShoppingMerchantAccounts/README.md index a3db5be269db..2410fe8d173f 100644 --- a/ShoppingMerchantAccounts/README.md +++ b/ShoppingMerchantAccounts/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Shopping\Merchant\Accounts\V1beta\AccountTax; +Google\Shopping\Merchant\Accounts\V1beta\Client\AccountTaxServiceClient; +Google\Shopping\Merchant\Accounts\V1beta\GetAccountTaxRequest; + +// Create a client. +$accountTaxServiceClient = new AccountTaxServiceClient(); + +// Prepare the request message. +$request = (new GetAccountTaxRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var AccountTax $response */ + $response = $accountTaxServiceClient->getAccountTax($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-shopping-merchant-accounts/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/ShoppingMerchantConversions/README.md b/ShoppingMerchantConversions/README.md index 9155bc925711..a47bc9d8cd3d 100644 --- a/ShoppingMerchantConversions/README.md +++ b/ShoppingMerchantConversions/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Shopping\Merchant\Conversions\V1beta\Client\ConversionSourcesServiceClient; +Google\Shopping\Merchant\Conversions\V1beta\ConversionSource; +Google\Shopping\Merchant\Conversions\V1beta\GetConversionSourceRequest; + +// Create a client. +$conversionSourcesServiceClient = new ConversionSourcesServiceClient(); + +// Prepare the request message. +$request = (new GetConversionSourceRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var ConversionSource $response */ + $response = $conversionSourcesServiceClient->getConversionSource($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-shopping-merchant-conversions/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/ShoppingMerchantDataSources/README.md b/ShoppingMerchantDataSources/README.md index 4c48eb9cd8f2..8112ec1b9f00 100644 --- a/ShoppingMerchantDataSources/README.md +++ b/ShoppingMerchantDataSources/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Shopping\Merchant\DataSources\V1beta\Client\DataSourcesServiceClient; +Google\Shopping\Merchant\DataSources\V1beta\DataSource; +Google\Shopping\Merchant\DataSources\V1beta\GetDataSourceRequest; + +// Create a client. +$dataSourcesServiceClient = new DataSourcesServiceClient(); + +// Prepare the request message. +$request = (new GetDataSourceRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var DataSource $response */ + $response = $dataSourcesServiceClient->getDataSource($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-shopping-merchant-datasources/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/ShoppingMerchantInventories/README.md b/ShoppingMerchantInventories/README.md index 4de91a4b3bd0..ce6de8cb1ead 100644 --- a/ShoppingMerchantInventories/README.md +++ b/ShoppingMerchantInventories/README.md @@ -34,6 +34,27 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Shopping\Merchant\Inventories\V1beta\Client\LocalInventoryServiceClient; +Google\Shopping\Merchant\Inventories\V1beta\DeleteLocalInventoryRequest; + +// Create a client. +$localInventoryServiceClient = new LocalInventoryServiceClient(); + +// Prepare the request message. +$request = (new DeleteLocalInventoryRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + $localInventoryServiceClient->deleteLocalInventory($request); + printf('Call completed successfully.' . PHP_EOL); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-shopping-merchant-inventories/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/ShoppingMerchantLfp/README.md b/ShoppingMerchantLfp/README.md index 2efae3e3d91a..2c501b0f502f 100644 --- a/ShoppingMerchantLfp/README.md +++ b/ShoppingMerchantLfp/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Shopping\Merchant\Lfp\V1beta\Client\LfpStoreServiceClient; +Google\Shopping\Merchant\Lfp\V1beta\GetLfpStoreRequest; +Google\Shopping\Merchant\Lfp\V1beta\LfpStore; + +// Create a client. +$lfpStoreServiceClient = new LfpStoreServiceClient(); + +// Prepare the request message. +$request = (new GetLfpStoreRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var LfpStore $response */ + $response = $lfpStoreServiceClient->getLfpStore($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-shopping-merchant-lfp/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/ShoppingMerchantNotifications/README.md b/ShoppingMerchantNotifications/README.md index 3f4c0443a214..cabd7facf00c 100644 --- a/ShoppingMerchantNotifications/README.md +++ b/ShoppingMerchantNotifications/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Shopping\Merchant\Notifications\V1beta\Client\NotificationsApiServiceClient; +Google\Shopping\Merchant\Notifications\V1beta\GetNotificationSubscriptionRequest; +Google\Shopping\Merchant\Notifications\V1beta\NotificationSubscription; + +// Create a client. +$notificationsApiServiceClient = new NotificationsApiServiceClient(); + +// Prepare the request message. +$request = (new GetNotificationSubscriptionRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var NotificationSubscription $response */ + $response = $notificationsApiServiceClient->getNotificationSubscription($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-shopping-merchant-notifications/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/ShoppingMerchantProducts/README.md b/ShoppingMerchantProducts/README.md index 2c14a905ca10..2383a5524b73 100644 --- a/ShoppingMerchantProducts/README.md +++ b/ShoppingMerchantProducts/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Shopping\Merchant\Products\V1beta\Client\ProductsServiceClient; +Google\Shopping\Merchant\Products\V1beta\GetProductRequest; +Google\Shopping\Merchant\Products\V1beta\Product; + +// Create a client. +$productsServiceClient = new ProductsServiceClient(); + +// Prepare the request message. +$request = (new GetProductRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Product $response */ + $response = $productsServiceClient->getProduct($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-shopping-merchant-products/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/ShoppingMerchantPromotions/README.md b/ShoppingMerchantPromotions/README.md index a19cbc418af4..d0f5a23cda5a 100644 --- a/ShoppingMerchantPromotions/README.md +++ b/ShoppingMerchantPromotions/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Shopping\Merchant\Promotions\V1beta\Client\PromotionsServiceClient; +Google\Shopping\Merchant\Promotions\V1beta\GetPromotionRequest; +Google\Shopping\Merchant\Promotions\V1beta\Promotion; + +// Create a client. +$promotionsServiceClient = new PromotionsServiceClient(); + +// Prepare the request message. +$request = (new GetPromotionRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Promotion $response */ + $response = $promotionsServiceClient->getPromotion($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-shopping-merchant-promotions/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/ShoppingMerchantQuota/README.md b/ShoppingMerchantQuota/README.md index 4137cd85f15d..58beacb37eee 100644 --- a/ShoppingMerchantQuota/README.md +++ b/ShoppingMerchantQuota/README.md @@ -34,6 +34,34 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\ApiCore\PagedListResponse; +Google\Shopping\Merchant\Quota\V1beta\Client\QuotaServiceClient; +Google\Shopping\Merchant\Quota\V1beta\ListQuotaGroupsRequest; +Google\Shopping\Merchant\Quota\V1beta\QuotaGroup; + +// Create a client. +$quotaServiceClient = new QuotaServiceClient(); + +// Prepare the request message. +$request = (new ListQuotaGroupsRequest()) + ->setParent($formattedParent); + +// Call the API and handle any network failures. +try { + /** @var PagedListResponse $response */ + $response = $quotaServiceClient->listQuotaGroups($request); + + /** @var QuotaGroup $element */ + foreach ($response as $element) { + printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString()); + } +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-shopping-merchant-quota/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/ShoppingMerchantReports/README.md b/ShoppingMerchantReports/README.md index 87407fd84ba7..44fc0e345d79 100644 --- a/ShoppingMerchantReports/README.md +++ b/ShoppingMerchantReports/README.md @@ -34,6 +34,35 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\ApiCore\PagedListResponse; +Google\Shopping\Merchant\Reports\V1beta\Client\ReportServiceClient; +Google\Shopping\Merchant\Reports\V1beta\ReportRow; +Google\Shopping\Merchant\Reports\V1beta\SearchRequest; + +// Create a client. +$reportServiceClient = new ReportServiceClient(); + +// Prepare the request message. +$request = (new SearchRequest()) + ->setParent($parent) + ->setQuery($query); + +// Call the API and handle any network failures. +try { + /** @var PagedListResponse $response */ + $response = $reportServiceClient->search($request); + + /** @var ReportRow $element */ + foreach ($response as $element) { + printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString()); + } +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-shopping-merchant-reports/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/ShoppingMerchantReviews/README.md b/ShoppingMerchantReviews/README.md index 759d56f51266..36f136e72829 100644 --- a/ShoppingMerchantReviews/README.md +++ b/ShoppingMerchantReviews/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Shopping\Merchant\Reviews\V1beta\Client\MerchantReviewsServiceClient; +Google\Shopping\Merchant\Reviews\V1beta\GetMerchantReviewRequest; +Google\Shopping\Merchant\Reviews\V1beta\MerchantReview; + +// Create a client. +$merchantReviewsServiceClient = new MerchantReviewsServiceClient(); + +// Prepare the request message. +$request = (new GetMerchantReviewRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var MerchantReview $response */ + $response = $merchantReviewsServiceClient->getMerchantReview($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/php-shopping-merchant-reviews/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/StorageControl/README.md b/StorageControl/README.md index d9647a3d7863..48a180eaa7ac 100644 --- a/StorageControl/README.md +++ b/StorageControl/README.md @@ -33,6 +33,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\Storage\Control\V2\Client\StorageControlClient; +Google\Cloud\Storage\Control\V2\Folder; +Google\Cloud\Storage\Control\V2\GetFolderRequest; + +// Create a client. +$storageControlClient = new StorageControlClient(); + +// Prepare the request message. +$request = (new GetFolderRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Folder $response */ + $response = $storageControlClient->getFolder($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-storage-control/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/StorageInsights/README.md b/StorageInsights/README.md index add3086aa4d8..c2a7ec2ca4bf 100644 --- a/StorageInsights/README.md +++ b/StorageInsights/README.md @@ -34,6 +34,28 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\Location\GetLocationRequest; +Google\Cloud\Location\Location; +Google\Cloud\StorageInsights\V1\Client\StorageInsightsClient; + +// Create a client. +$storageInsightsClient = new StorageInsightsClient(); + +// Prepare the request message. +$request = new GetLocationRequest(); + +// Call the API and handle any network failures. +try { + /** @var Location $response */ + $response = $storageInsightsClient->getLocation($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](samples/) for a canonical list of samples. ### Debugging diff --git a/Support/README.md b/Support/README.md index b4155265e1c6..6109e7bb3e0d 100644 --- a/Support/README.md +++ b/Support/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\Support\V2\Client\CaseServiceClient; +Google\Cloud\Support\V2\GetCaseRequest; +Google\Cloud\Support\V2\PBCase; + +// Create a client. +$caseServiceClient = new CaseServiceClient(); + +// Prepare the request message. +$request = (new GetCaseRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var PBCase $response */ + $response = $caseServiceClient->getCase($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](samples/) for a canonical list of samples. ### Debugging diff --git a/TelcoAutomation/README.md b/TelcoAutomation/README.md index b8597f387390..094e4f777721 100644 --- a/TelcoAutomation/README.md +++ b/TelcoAutomation/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +Google\ApiCore\ApiException; +Google\Cloud\TelcoAutomation\V1\Blueprint; +Google\Cloud\TelcoAutomation\V1\Client\TelcoAutomationClient; +Google\Cloud\TelcoAutomation\V1\GetBlueprintRequest; + +// Create a client. +$telcoAutomationClient = new TelcoAutomationClient(); + +// Prepare the request message. +$request = (new GetBlueprintRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Blueprint $response */ + $response = $telcoAutomationClient->getBlueprint($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + See the [samples directory](https://github.com/googleapis/google-cloud-php-telcoautomation/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/Translate/README.md b/Translate/README.md index 711483f4bfb7..4a1fcaff65da 100644 --- a/Translate/README.md +++ b/Translate/README.md @@ -30,7 +30,30 @@ $ composer require google/cloud-translate Please see our [Authentication guide](https://github.com/googleapis/google-cloud-php/blob/main/AUTHENTICATION.md) for more information on authenticating your client. Once authenticated, you'll be ready to start making requests. -### Sample Using the Handwritten Client (Interacts with the V2 API) +### Sample + +```php +Google\ApiCore\ApiException; +Google\Cloud\Translate\V3\AdaptiveMtDataset; +Google\Cloud\Translate\V3\Client\TranslationServiceClient; +Google\Cloud\Translate\V3\GetAdaptiveMtDatasetRequest; + +// Create a client. +$translationServiceClient = new TranslationServiceClient(); + +// Prepare the request message. +$request = (new GetAdaptiveMtDatasetRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var AdaptiveMtDataset $response */ + $response = $translationServiceClient->getAdaptiveMtDataset($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` Using the Handwritten Client (Interacts with the V2 API) ```php require 'vendor/autoload.php'; @@ -71,7 +94,30 @@ foreach ($languages as $language) { } ``` -### Sample Using the Generated Client (Interacts with the V3 API) +### Sample + +```php +Google\ApiCore\ApiException; +Google\Cloud\Translate\V3\AdaptiveMtDataset; +Google\Cloud\Translate\V3\Client\TranslationServiceClient; +Google\Cloud\Translate\V3\GetAdaptiveMtDatasetRequest; + +// Create a client. +$translationServiceClient = new TranslationServiceClient(); + +// Prepare the request message. +$request = (new GetAdaptiveMtDatasetRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var AdaptiveMtDataset $response */ + $response = $translationServiceClient->getAdaptiveMtDataset($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` Using the Generated Client (Interacts with the V3 API) ```php require 'vendor/autoload.php'; diff --git a/dev/google-cloud b/dev/google-cloud index 4683cd760b98..2913c2b3e49c 100755 --- a/dev/google-cloud +++ b/dev/google-cloud @@ -23,6 +23,7 @@ if (!file_exists(__DIR__ . '/vendor/autoload.php')) { require __DIR__ . '/vendor/autoload.php'; use Google\Cloud\Dev\Command\AddComponentCommand; +use Google\Cloud\Dev\Command\AddSampleToReadmeCommand; use Google\Cloud\Dev\Command\ComponentInfoCommand; use Google\Cloud\Dev\Command\DocFxCommand; use Google\Cloud\Dev\Command\RepoInfoCommand; @@ -43,6 +44,7 @@ $rootDirectory = realpath(__DIR__ . '/../') . '/'; $app = new Application; $app->add(new AddComponentCommand($rootDirectory)); +$app->add(new AddSampleToReadmeCommand()); $app->add(new ComponentInfoCommand()); $app->add(new DocFxCommand()); $app->add(new RepoInfoCommand()); diff --git a/dev/src/Command/AddComponentCommand.php b/dev/src/Command/AddComponentCommand.php index ce85171566f8..e2a000fba460 100644 --- a/dev/src/Command/AddComponentCommand.php +++ b/dev/src/Command/AddComponentCommand.php @@ -18,7 +18,6 @@ namespace Google\Cloud\Dev\Command; use Google\Cloud\Dev\Composer; -use Google\Cloud\Dev\Component; use Google\Cloud\Dev\NewComponent; use Google\Cloud\Dev\RunProcess; use Symfony\Component\Console\Command\Command; @@ -30,7 +29,6 @@ use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Process\Process; use Symfony\Component\Yaml\Yaml; use GuzzleHttp\Client; use Twig\Loader\FilesystemLoader; @@ -62,8 +60,6 @@ class AddComponentCommand extends Command private const OWLBOT_CLI_IMAGE = 'gcr.io/cloud-devrel-public-resources/owlbot-cli:latest'; private const OWLBOT_PHP_IMAGE = 'gcr.io/cloud-devrel-public-resources/owlbot-php:latest'; - private $input; - private $output; private $rootPath; private $httpClient; private RunProcess $runProcess; diff --git a/dev/src/Command/AddSampleToReadmeCommand.php b/dev/src/Command/AddSampleToReadmeCommand.php new file mode 100644 index 000000000000..e67cfa1a4bf3 --- /dev/null +++ b/dev/src/Command/AddSampleToReadmeCommand.php @@ -0,0 +1,74 @@ +setName('add-sample-to-readme') + ->setDescription('Add a sample to a component') + ->addOption('component', 'c', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Add to the readme of the specified component', []) + ->addOption('update', '', InputOption::VALUE_NONE, 'updates the sample in the readme if it exists'); + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + // Compile all the component data into rows + $components = Component::getComponents($input->getOption('component')); + + foreach ($components as $component) { + if (!$sample = $component->getSimplestSample()) { + $output->writeln('Unable to retrieve sample in ' . $component->getName() . ''); + continue; + } + $readme = file_get_contents($component->getPath() . '/README.md'); + if (strpos($readme, '### Sample') === false) { + $output->writeln('No "Sample" header found in ' . $component->getName() . ' README.md'); + continue; + } + + $sample = "```php\n" . $sample . "\n```"; + if (preg_match('/### Sample\n\n(```(.|\n)*```)/', $readme, $matches)) { + $output->writeln('Sample already exists in ' . $component->getName() . ' README.md'); + if (!$input->getOption('update')) { + continue; + } + $readme = str_replace($matches[1], $sample, $readme); + } else { + $readme = str_replace('### Sample', "### Sample\n\n" . $sample, $readme); + } + + file_put_contents($component->getPath() . '/README.md', $readme); + $output->writeln('Successfull wrote sample to ' . $component->getName() . ' README.md'); + } + + return 0; + } +} diff --git a/dev/src/Component.php b/dev/src/Component.php index 3ff7554d8f9c..b583b8cba3f6 100644 --- a/dev/src/Component.php +++ b/dev/src/Component.php @@ -365,4 +365,59 @@ public function getComponentDependencies(): array { return $this->componentDependencies; } + + public function getSimplestSample(): string + { + if (!file_exists($this->path . '/samples')) { + return ''; + } + + $result = (new Finder())->files()->in($this->path . '/samples') + ->name('*.php')->sortByName(); + + $preferredFile = array_filter( + iterator_to_array($result), + fn ($f) => str_starts_with($f->getFilename(), 'get') && $f->getFilename() !== 'get_iam_policy.php' + )[0] ?? null; + + // grab the shortest file if no "get" example exists + if ($preferredFile === null) { + foreach ($result as $file) { + if (str_starts_with($file->getFilename(),'get') + && $file->getFilename() !== 'get_iam_policy.php' + ) { + $preferredFile = $file; + break; + } + $preferredFile ??= $file; // set first file to default preferred file + + $preferredFile = count(file($file->getRealPath())) < count(file($preferredFile->getRealPath())) + ? $file + : $preferredFile; + } + } + + if ($preferredFile === null || !preg_match('/^{(.|\n)*?(^})/m', $preferredFile->getContents(), $matches)) { + return ''; + } + + $lines = explode("\n", $matches[0]); + + // remove wrapped parenthesis + array_shift($lines); + array_pop($lines); + + // add imports + $imports = array_filter( + explode("\n", $preferredFile->getContents()), + fn ($line) => str_starts_with($line, 'use Google\\') + ); + + if ($imports) { + $imports[] = "\n"; + $lines = array_merge($imports, $lines); + } + + return implode("\n", array_map(fn ($line) => substr($line, 4), $lines)); + } } diff --git a/dev/src/NewComponent.php b/dev/src/NewComponent.php index 0e5bfa775eb4..dbe811e20a02 100644 --- a/dev/src/NewComponent.php +++ b/dev/src/NewComponent.php @@ -18,6 +18,7 @@ namespace Google\Cloud\Dev; use RuntimeException; +use Symfony\Component\Finder\Finder; /** * @internal diff --git a/dev/tests/Unit/ComponentTest.php b/dev/tests/Unit/ComponentTest.php index f3ae5229eefb..9f4b23ab7962 100644 --- a/dev/tests/Unit/ComponentTest.php +++ b/dev/tests/Unit/ComponentTest.php @@ -92,4 +92,14 @@ public function testGetProtoNamespaces() $this->assertEquals('Google\Cloud\Iam\V1', $allProtoNamespaces['google.iam.v1']); $this->assertEquals('Google\Cloud\Logging\Type', $allProtoNamespaces['google.logging.type']); } + + public function testSimplestSample() + { + $component = new Component('SecretManager'); + + $sample = $component->getSimplestSample(); + + $this->assertNotEmpty($sample); + $this->assertStringContainsString('getSecret', $sample); + } }