From 73694ddaa1e898391d614c1e46068df26bd4889f Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 22 Aug 2025 13:59:48 -0700 Subject: [PATCH 1/5] docs: fix all samples, rename command --- AccessApproval/README.md | 24 +++++ AccessContextManager/README.md | 25 +++++ AdsAdManager/README.md | 16 +-- AdsMarketingPlatformAdmin/README.md | 8 +- AdvisoryNotifications/README.md | 8 +- AiPlatform/README.md | 25 +++++ AlloyDb/README.md | 8 +- AnalyticsAdmin/README.md | 29 +++--- AnalyticsData/README.md | 33 ++++--- ApiGateway/README.md | 25 +++++ ApiHub/README.md | 8 +- ApiKeys/README.md | 25 +++++ ApigeeConnect/README.md | 30 ++++++ ApigeeRegistry/README.md | 25 +++++ AppEngineAdmin/README.md | 24 +++++ AppHub/README.md | 8 +- AppsEventsSubscriptions/README.md | 8 +- AppsMeet/README.md | 8 +- ArtifactRegistry/README.md | 25 +++++ Asset/README.md | 43 ++++---- AssuredWorkloads/README.md | 31 +++--- AutoMl/README.md | 32 +++--- BackupDr/README.md | 8 +- BareMetalSolution/README.md | 25 +++++ Batch/README.md | 25 +++++ BeyondCorpAppConnections/README.md | 25 +++++ BeyondCorpAppConnectors/README.md | 25 +++++ BeyondCorpAppGateways/README.md | 25 +++++ BeyondCorpClientConnectorServices/README.md | 25 +++++ BeyondCorpClientGateways/README.md | 25 +++++ BigQueryAnalyticsHub/README.md | 25 +++++ BigQueryConnection/README.md | 35 ++++--- BigQueryDataExchange/README.md | 25 +++++ BigQueryDataPolicies/README.md | 25 +++++ BigQueryDataTransfer/README.md | 25 +++-- BigQueryMigration/README.md | 25 +++++ BigQueryReservation/README.md | 34 ++++--- BigQueryStorage/README.md | 59 ++++------- Bigtable/README.md | 29 ++++-- Billing/README.md | 28 ++++-- BillingBudgets/README.md | 25 +++++ BinaryAuthorization/README.md | 25 +++++ Build/README.md | 25 +++++ CertificateManager/README.md | 25 +++++ Channel/README.md | 29 ++++-- Chronicle/README.md | 8 +- CommerceConsumerProcurement/README.md | 8 +- Compute/README.md | 28 ++++-- ConfidentialComputing/README.md | 8 +- Config/README.md | 8 +- ConfigDelivery/README.md | 23 +++++ ContactCenterInsights/README.md | 25 +++++ Container/README.md | 24 ++--- ContainerAnalysis/README.md | 25 +++++ ControlsPartner/README.md | 8 +- DataCatalog/README.md | 30 ++++-- DataCatalogLineage/README.md | 8 +- DataFusion/README.md | 25 +++++ DataLabeling/README.md | 25 +++++ Dataflow/README.md | 24 +++++ Dataform/README.md | 25 +++++ Dataplex/README.md | 25 +++++ Dataproc/README.md | 43 ++++---- DataprocMetastore/README.md | 25 +++++ Datastore/README.md | 39 ++++---- DatastoreAdmin/README.md | 25 +++-- Datastream/README.md | 25 +++++ Deploy/README.md | 25 +++++ DeveloperConnect/README.md | 14 +-- DeviceStreaming/README.md | 8 +- Dialogflow/README.md | 37 +++---- DialogflowCx/README.md | 8 +- DiscoveryEngine/README.md | 16 +-- Dlp/README.md | 43 ++++---- Dms/README.md | 25 +++++ DocumentAi/README.md | 25 +++++ Domains/README.md | 25 +++++ EdgeNetwork/README.md | 8 +- ErrorReporting/README.md | 53 +--------- EssentialContacts/README.md | 25 +++++ Eventarc/README.md | 25 +++++ EventarcPublishing/README.md | 24 +++++ Filestore/README.md | 25 +++++ FinancialServices/README.md | 8 +- Firestore/README.md | 31 +++--- Functions/README.md | 25 +++++ GSuiteAddOns/README.md | 25 +++++ GeminiDataAnalytics/README.md | 22 +++++ GkeBackup/README.md | 25 +++++ GkeConnectGateway/README.md | 25 +++++ GkeHub/README.md | 24 +++++ GkeMultiCloud/README.md | 25 +++++ Grafeas/README.md | 22 +++++ Iam/README.md | 25 +++++ IamCredentials/README.md | 26 +++++ Iap/README.md | 25 +++++ Ids/README.md | 25 +++++ Kms/README.md | 60 +++-------- KmsInventory/README.md | 8 +- Language/README.md | 47 ++++----- LicenseManager/README.md | 8 +- LifeSciences/README.md | 24 +++++ Logging/README.md | 38 +++---- Lustre/README.md | 8 +- Maintenance/README.md | 8 +- ManagedIdentities/README.md | 25 +++++ ManagedKafka/README.md | 14 +-- ManagedKafkaSchemaRegistry/README.md | 23 +++++ MapsFleetEngine/README.md | 8 +- MapsFleetEngineDelivery/README.md | 8 +- MapsRouteOptimization/README.md | 8 +- MediaTranslation/README.md | 30 ++++++ Memcache/README.md | 30 +++--- Memorystore/README.md | 14 +-- MigrationCenter/README.md | 8 +- ModelArmor/README.md | 8 +- Monitoring/README.md | 63 ++++-------- NetApp/README.md | 8 +- NetworkConnectivity/README.md | 24 +++++ NetworkManagement/README.md | 25 +++++ NetworkSecurity/README.md | 25 +++++ NetworkServices/README.md | 14 +-- Notebooks/README.md | 25 +++++ Optimization/README.md | 25 +++++ OracleDatabase/README.md | 8 +- OrchestrationAirflow/README.md | 24 +++++ OrgPolicy/README.md | 25 +++++ OsConfig/README.md | 31 +++--- OsLogin/README.md | 24 +++-- Parallelstore/README.md | 8 +- ParameterManager/README.md | 8 +- PolicySimulator/README.md | 16 +-- PolicyTroubleshooter/README.md | 24 +++++ PolicyTroubleshooterIam/README.md | 8 +- PrivateCatalog/README.md | 30 ++++++ PrivilegedAccessManager/README.md | 8 +- Profiler/README.md | 24 +++++ PubSub/README.md | 45 ++++----- Quotas/README.md | 8 +- RapidMigrationAssessment/README.md | 8 +- RecaptchaEnterprise/README.md | 30 ++---- RecommendationEngine/README.md | 34 ++++--- Recommender/README.md | 38 +++---- Redis/README.md | 34 ++++--- RedisCluster/README.md | 14 +-- ResourceManager/README.md | 25 +++++ Retail/README.md | 31 +++--- Run/README.md | 25 +++++ Scheduler/README.md | 47 ++++----- SecretManager/README.md | 41 ++++---- SecureSourceManager/README.md | 8 +- SecurityCenter/README.md | 31 +++--- SecurityCenterManagement/README.md | 8 +- SecurityPrivateCa/README.md | 35 ++++--- SecurityPublicCA/README.md | 27 +++++ ServiceControl/README.md | 24 +++++ ServiceDirectory/README.md | 45 ++++----- ServiceHealth/README.md | 8 +- ServiceManagement/README.md | 25 +++++ ServiceUsage/README.md | 24 +++++ Shell/README.md | 25 +++++ ShoppingCss/README.md | 8 +- ShoppingMerchantAccounts/README.md | 16 +-- ShoppingMerchantConversions/README.md | 8 +- ShoppingMerchantDataSources/README.md | 8 +- ShoppingMerchantInventories/README.md | 6 +- ShoppingMerchantIssueResolution/README.md | 8 +- ShoppingMerchantLfp/README.md | 16 +-- ShoppingMerchantNotifications/README.md | 8 +- ShoppingMerchantOrderTracking/README.md | 16 +-- ShoppingMerchantProducts/README.md | 8 +- ShoppingMerchantPromotions/README.md | 8 +- ShoppingMerchantQuota/README.md | 10 +- ShoppingMerchantReports/README.md | 10 +- ShoppingMerchantReviews/README.md | 8 +- Spanner/README.md | 86 ++++------------ Speech/README.md | 36 +++---- SqlAdmin/README.md | 24 +++++ StorageBatchOperations/README.md | 8 +- StorageControl/README.md | 14 +-- StorageInsights/README.md | 15 +-- StorageTransfer/README.md | 25 +++++ Support/README.md | 8 +- Talent/README.md | 32 +++--- Tasks/README.md | 48 ++++----- TelcoAutomation/README.md | 8 +- TextToSpeech/README.md | 35 +++---- Tpu/README.md | 25 +++++ Trace/README.md | 87 +++++----------- Translate/README.md | 31 +----- VideoIntelligence/README.md | 64 +++++------- VideoLiveStream/README.md | 25 +++++ VideoStitcher/README.md | 25 +++++ VideoTranscoder/README.md | 25 +++++ Vision/README.md | 51 ++++------ VmMigration/README.md | 25 +++++ VmwareEngine/README.md | 25 +++++ VpcAccess/README.md | 25 +++++ WebRisk/README.md | 36 ++++--- WebSecurityScanner/README.md | 38 +++---- Workflows/README.md | 30 +++--- dev/google-cloud | 4 +- dev/src/Command/NewComponentCommand.php | 6 +- ...mand.php => UpdateReadmeSampleCommand.php} | 39 ++++++-- dev/src/Component.php | 70 +++---------- dev/src/ComponentPackage.php | 59 +++++++++++ .../Unit/Command/NewComponentCommandTest.php | 4 +- .../Command/UpdateReadmeSampleCommandTest.php | 99 +++++++++++++++++++ .../component/ClientSnippets/README.md | 50 ++++++++++ 209 files changed, 3612 insertions(+), 1465 deletions(-) rename dev/src/Command/{AddSampleToReadmeCommand.php => UpdateReadmeSampleCommand.php} (63%) create mode 100644 dev/tests/Unit/Command/UpdateReadmeSampleCommandTest.php create mode 100644 dev/tests/fixtures/component/ClientSnippets/README.md diff --git a/AccessApproval/README.md b/AccessApproval/README.md index 42df1f57d4d3..618ce59d0d6e 100644 --- a/AccessApproval/README.md +++ b/AccessApproval/README.md @@ -29,6 +29,30 @@ Please see our [Authentication guide](https://github.com/googleapis/google-cloud on authenticating your client. Once authenticated, you'll be ready to start making requests. +### Sample + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\AccessApproval\V1\AccessApprovalServiceAccount; +use Google\Cloud\AccessApproval\V1\Client\AccessApprovalClient; +use Google\Cloud\AccessApproval\V1\GetAccessApprovalServiceAccountMessage; + +// Create a client. +$accessApprovalClient = new AccessApprovalClient(); + +// Prepare the request message. +$request = new GetAccessApprovalServiceAccountMessage(); + +// Call the API and handle any network failures. +try { + /** @var AccessApprovalServiceAccount $response */ + $response = $accessApprovalClient->getAccessApprovalServiceAccount($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/AccessContextManager/README.md b/AccessContextManager/README.md index fbb10e2cd330..62b0e9321e8d 100644 --- a/AccessContextManager/README.md +++ b/AccessContextManager/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Identity\AccessContextManager\V1\AccessLevel; +use Google\Identity\AccessContextManager\V1\Client\AccessContextManagerClient; +use Google\Identity\AccessContextManager\V1\GetAccessLevelRequest; + +// Create a client. +$accessContextManagerClient = new AccessContextManagerClient(); + +// Prepare the request message. +$request = (new GetAccessLevelRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var AccessLevel $response */ + $response = $accessContextManagerClient->getAccessLevel($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/AdsAdManager/README.md b/AdsAdManager/README.md index b36a2b6d9a07..35bf014fe852 100644 --- a/AdsAdManager/README.md +++ b/AdsAdManager/README.md @@ -35,22 +35,22 @@ 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; +use Google\Ads\AdManager\V1\AdBreak; +use Google\Ads\AdManager\V1\Client\AdBreakServiceClient; +use Google\Ads\AdManager\V1\GetAdBreakRequest; +use Google\ApiCore\ApiException; // Create a client. -$adUnitServiceClient = new AdUnitServiceClient(); +$adBreakServiceClient = new AdBreakServiceClient(); // Prepare the request message. -$request = (new GetAdUnitRequest()) +$request = (new GetAdBreakRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { - /** @var AdUnit $response */ - $response = $adUnitServiceClient->getAdUnit($request); + /** @var AdBreak $response */ + $response = $adBreakServiceClient->getAdBreak($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/AdsMarketingPlatformAdmin/README.md b/AdsMarketingPlatformAdmin/README.md index 227697d1c97a..c7f6998e2d01 100644 --- a/AdsMarketingPlatformAdmin/README.md +++ b/AdsMarketingPlatformAdmin/README.md @@ -35,10 +35,10 @@ 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; +use Google\Ads\MarketingPlatform\Admin\V1alpha\Client\MarketingplatformAdminServiceClient; +use Google\Ads\MarketingPlatform\Admin\V1alpha\GetOrganizationRequest; +use Google\Ads\MarketingPlatform\Admin\V1alpha\Organization; +use Google\ApiCore\ApiException; // Create a client. $marketingplatformAdminServiceClient = new MarketingplatformAdminServiceClient(); diff --git a/AdvisoryNotifications/README.md b/AdvisoryNotifications/README.md index 30a6f475c368..9d74452544e7 100644 --- a/AdvisoryNotifications/README.md +++ b/AdvisoryNotifications/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\AdvisoryNotifications\V1\Client\AdvisoryNotificationsServiceClient; +use Google\Cloud\AdvisoryNotifications\V1\GetNotificationRequest; +use Google\Cloud\AdvisoryNotifications\V1\Notification; // Create a client. $advisoryNotificationsServiceClient = new AdvisoryNotificationsServiceClient(); diff --git a/AiPlatform/README.md b/AiPlatform/README.md index acfe59adaf90..27187346adc4 100644 --- a/AiPlatform/README.md +++ b/AiPlatform/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\AIPlatform\V1\AnnotationSpec; +use Google\Cloud\AIPlatform\V1\Client\DatasetServiceClient; +use Google\Cloud\AIPlatform\V1\GetAnnotationSpecRequest; + +// Create a client. +$datasetServiceClient = new DatasetServiceClient(); + +// Prepare the request message. +$request = (new GetAnnotationSpecRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var AnnotationSpec $response */ + $response = $datasetServiceClient->getAnnotationSpec($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/AlloyDb/README.md b/AlloyDb/README.md index d39fd73990cb..5dcb9c359570 100644 --- a/AlloyDb/README.md +++ b/AlloyDb/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\AlloyDb\V1\Backup; +use Google\Cloud\AlloyDb\V1\Client\AlloyDBAdminClient; +use Google\Cloud\AlloyDb\V1\GetBackupRequest; // Create a client. $alloyDBAdminClient = new AlloyDBAdminClient(); diff --git a/AnalyticsAdmin/README.md b/AnalyticsAdmin/README.md index cceef761d405..bd584e5036ea 100644 --- a/AnalyticsAdmin/README.md +++ b/AnalyticsAdmin/README.md @@ -31,18 +31,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - +use Google\Analytics\Admin\V1beta\Account; use Google\Analytics\Admin\V1beta\Client\AnalyticsAdminServiceClient; -use Google\Analytics\Admin\V1beta\ListAccountsRequest; - -$client = new AnalyticsAdminServiceClient(); - -$request = new ListAccountsRequest(); -$accounts = $client->listAccounts($request); - -foreach ($accounts as $account) { - print 'Found account: ' . $account->getName() . PHP_EOL; +use Google\Analytics\Admin\V1beta\GetAccountRequest; +use Google\ApiCore\ApiException; + +// Create a client. +$analyticsAdminServiceClient = new AnalyticsAdminServiceClient(); + +// Prepare the request message. +$request = (new GetAccountRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Account $response */ + $response = $analyticsAdminServiceClient->getAccount($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/AnalyticsData/README.md b/AnalyticsData/README.md index 54a7c37b680d..3d961a6b9311 100644 --- a/AnalyticsData/README.md +++ b/AnalyticsData/README.md @@ -31,22 +31,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - +use Google\Analytics\Data\V1beta\AudienceExport; use Google\Analytics\Data\V1beta\Client\BetaAnalyticsDataClient; -use Google\Analytics\Data\V1beta\RunReportRequest; - -$client = new BetaAnalyticsDataClient(); - -$request = new RunReportRequest([ - 'property' => 'properties/[YOUR_PROPERTY_ID]' -]); -$response = $client->runReport($request); - -foreach ($response->getRows() as $row) { - foreach ($row->getDimensionValues() as $dimensionValue) { - print 'Dimension Value: ' . $dimensionValue->getValue() . PHP_EOL; - } +use Google\Analytics\Data\V1beta\GetAudienceExportRequest; +use Google\ApiCore\ApiException; + +// Create a client. +$betaAnalyticsDataClient = new BetaAnalyticsDataClient(); + +// Prepare the request message. +$request = (new GetAudienceExportRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var AudienceExport $response */ + $response = $betaAnalyticsDataClient->getAudienceExport($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/ApiGateway/README.md b/ApiGateway/README.md index a158f8563022..8ae4dd0d3795 100644 --- a/ApiGateway/README.md +++ b/ApiGateway/README.md @@ -29,6 +29,31 @@ Please see our [Authentication guide](https://github.com/googleapis/google-cloud on authenticating your client. Once authenticated, you'll be ready to start making requests. +### Sample + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\ApiGateway\V1\Api; +use Google\Cloud\ApiGateway\V1\Client\ApiGatewayServiceClient; +use Google\Cloud\ApiGateway\V1\GetApiRequest; + +// Create a client. +$apiGatewayServiceClient = new ApiGatewayServiceClient(); + +// Prepare the request message. +$request = (new GetApiRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Api $response */ + $response = $apiGatewayServiceClient->getApi($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/ApiHub/README.md b/ApiHub/README.md index 0831b83f10d3..2d09b0c96def 100644 --- a/ApiHub/README.md +++ b/ApiHub/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\ApiHub\V1\Api; +use Google\Cloud\ApiHub\V1\Client\ApiHubClient; +use Google\Cloud\ApiHub\V1\GetApiRequest; // Create a client. $apiHubClient = new ApiHubClient(); diff --git a/ApiKeys/README.md b/ApiKeys/README.md index 758693b8cf46..906bc8b98094 100644 --- a/ApiKeys/README.md +++ b/ApiKeys/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\ApiKeys\V2\Client\ApiKeysClient; +use Google\Cloud\ApiKeys\V2\GetKeyRequest; +use Google\Cloud\ApiKeys\V2\Key; + +// Create a client. +$apiKeysClient = new ApiKeysClient(); + +// Prepare the request message. +$request = (new GetKeyRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Key $response */ + $response = $apiKeysClient->getKey($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/ApigeeConnect/README.md b/ApigeeConnect/README.md index 3768301516d3..bb5d1ef729f0 100644 --- a/ApigeeConnect/README.md +++ b/ApigeeConnect/README.md @@ -29,6 +29,36 @@ Please see our [Authentication guide](https://github.com/googleapis/google-cloud on authenticating your client. Once authenticated, you'll be ready to start making requests. +### Sample + +```php +use Google\ApiCore\ApiException; +use Google\ApiCore\BidiStream; +use Google\Cloud\ApigeeConnect\V1\Client\TetherClient; +use Google\Cloud\ApigeeConnect\V1\EgressRequest; +use Google\Cloud\ApigeeConnect\V1\EgressResponse; + +// Create a client. +$tetherClient = new TetherClient(); + +// Prepare the request message. +$request = new EgressResponse(); + +// Call the API and handle any network failures. +try { + /** @var BidiStream $stream */ + $stream = $tetherClient->egress(); + $stream->writeAll([$request,]); + + /** @var EgressRequest $element */ + foreach ($stream->closeWriteAndReadAll() as $element) { + printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString()); + } +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/ApigeeRegistry/README.md b/ApigeeRegistry/README.md index 8454de7c1285..f44617e8cae7 100644 --- a/ApigeeRegistry/README.md +++ b/ApigeeRegistry/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\ApigeeRegistry\V1\Client\ProvisioningClient; +use Google\Cloud\ApigeeRegistry\V1\GetInstanceRequest; +use Google\Cloud\ApigeeRegistry\V1\Instance; + +// Create a client. +$provisioningClient = new ProvisioningClient(); + +// Prepare the request message. +$request = (new GetInstanceRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Instance $response */ + $response = $provisioningClient->getInstance($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/AppEngineAdmin/README.md b/AppEngineAdmin/README.md index f194dea379fd..4f7d6a56f8af 100644 --- a/AppEngineAdmin/README.md +++ b/AppEngineAdmin/README.md @@ -29,6 +29,30 @@ Please see our [Authentication guide](https://github.com/googleapis/google-cloud on authenticating your client. Once authenticated, you'll be ready to start making requests. +### Sample + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\AppEngine\V1\Application; +use Google\Cloud\AppEngine\V1\Client\ApplicationsClient; +use Google\Cloud\AppEngine\V1\GetApplicationRequest; + +// Create a client. +$applicationsClient = new ApplicationsClient(); + +// Prepare the request message. +$request = new GetApplicationRequest(); + +// Call the API and handle any network failures. +try { + /** @var Application $response */ + $response = $applicationsClient->getApplication($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/AppHub/README.md b/AppHub/README.md index 4bef10c112b1..79eb5a2278a2 100644 --- a/AppHub/README.md +++ b/AppHub/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\AppHub\V1\Application; +use Google\Cloud\AppHub\V1\Client\AppHubClient; +use Google\Cloud\AppHub\V1\GetApplicationRequest; // Create a client. $appHubClient = new AppHubClient(); diff --git a/AppsEventsSubscriptions/README.md b/AppsEventsSubscriptions/README.md index 0cfa6d3cfa74..7840910ce6c6 100644 --- a/AppsEventsSubscriptions/README.md +++ b/AppsEventsSubscriptions/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Apps\Events\Subscriptions\V1\Client\SubscriptionsServiceClient; +use Google\Apps\Events\Subscriptions\V1\GetSubscriptionRequest; +use Google\Apps\Events\Subscriptions\V1\Subscription; // Create a client. $subscriptionsServiceClient = new SubscriptionsServiceClient(); diff --git a/AppsMeet/README.md b/AppsMeet/README.md index 5298347b554b..c57e748634e5 100644 --- a/AppsMeet/README.md +++ b/AppsMeet/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Apps\Meet\V2\Client\ConferenceRecordsServiceClient; +use Google\Apps\Meet\V2\ConferenceRecord; +use Google\Apps\Meet\V2\GetConferenceRecordRequest; // Create a client. $conferenceRecordsServiceClient = new ConferenceRecordsServiceClient(); diff --git a/ArtifactRegistry/README.md b/ArtifactRegistry/README.md index e263267b2792..9772357f91dc 100644 --- a/ArtifactRegistry/README.md +++ b/ArtifactRegistry/README.md @@ -29,6 +29,31 @@ Please see our [Authentication guide](https://github.com/googleapis/google-cloud on authenticating your client. Once authenticated, you'll be ready to start making requests. +### Sample + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\ArtifactRegistry\V1\Attachment; +use Google\Cloud\ArtifactRegistry\V1\Client\ArtifactRegistryClient; +use Google\Cloud\ArtifactRegistry\V1\GetAttachmentRequest; + +// Create a client. +$artifactRegistryClient = new ArtifactRegistryClient(); + +// Prepare the request message. +$request = (new GetAttachmentRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Attachment $response */ + $response = $artifactRegistryClient->getAttachment($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Asset/README.md b/Asset/README.md index 52294481143e..ce147f559bbe 100644 --- a/Asset/README.md +++ b/Asset/README.md @@ -31,30 +31,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require_once __DIR__ . '/vendor/autoload.php'; - -use Google\Cloud\Asset\V1\AssetServiceClient; -use Google\Cloud\Asset\V1\GcsDestination; -use Google\Cloud\Asset\V1\OutputConfig; - -$objectPath = 'gs://your-bucket/cai-export'; -// Now you need to change this with your project number (numeric id) -$project = 'example-project'; - -$client = new AssetServiceClient(); - -$gcsDestination = new GcsDestination(['uri' => $objectPath]); -$outputConfig = new OutputConfig(['gcs_destination' => $gcsDestination]); - -$resp = $client->exportAssets("projects/$project", $outputConfig); - -$resp->pollUntilComplete(); - -if ($resp->operationSucceeded()) { - echo "The result is dumped to $objectPath successfully." . PHP_EOL; -} else { - $error = $resp->getError(); - // handleError($error) +use Google\ApiCore\ApiException; +use Google\Cloud\Asset\V1\Client\AssetServiceClient; +use Google\Cloud\Asset\V1\Feed; +use Google\Cloud\Asset\V1\GetFeedRequest; + +// Create a client. +$assetServiceClient = new AssetServiceClient(); + +// Prepare the request message. +$request = (new GetFeedRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Feed $response */ + $response = $assetServiceClient->getFeed($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/AssuredWorkloads/README.md b/AssuredWorkloads/README.md index 93dd127e2644..9316a6c36fad 100644 --- a/AssuredWorkloads/README.md +++ b/AssuredWorkloads/README.md @@ -31,18 +31,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\AssuredWorkloads\V1beta1\AssuredWorkloadsServiceClient; - -$client = new AssuredWorkloadsServiceClient(); - -$workloads = $client->listWorkloads( - AssuredWorkloadsServiceClient::locationName('[MY_ORGANIZATION]', 'us-west1') -); - -foreach ($workloads as $workload) { - print 'Workload: ' . $workload->getName() . PHP_EOL; +use Google\ApiCore\ApiException; +use Google\Cloud\AssuredWorkloads\V1\Client\AssuredWorkloadsServiceClient; +use Google\Cloud\AssuredWorkloads\V1\GetViolationRequest; +use Google\Cloud\AssuredWorkloads\V1\Violation; + +// Create a client. +$assuredWorkloadsServiceClient = new AssuredWorkloadsServiceClient(); + +// Prepare the request message. +$request = (new GetViolationRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Violation $response */ + $response = $assuredWorkloadsServiceClient->getViolation($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/AutoMl/README.md b/AutoMl/README.md index d065dc5cbba1..a9b956a6ac84 100644 --- a/AutoMl/README.md +++ b/AutoMl/README.md @@ -31,22 +31,26 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\AutoMl\V1\AutoMlClient; -use Google\Cloud\AutoMl\V1\Dataset; -use Google\Cloud\AutoMl\V1\TranslationDatasetMetadata; +use Google\ApiCore\ApiException; +use Google\Cloud\AutoMl\V1\AnnotationSpec; +use Google\Cloud\AutoMl\V1\Client\AutoMlClient; +use Google\Cloud\AutoMl\V1\GetAnnotationSpecRequest; +// Create a client. $autoMlClient = new AutoMlClient(); -$formattedParent = $autoMlClient->locationName('[PROJECT]', '[LOCATION]'); -$dataset = new Dataset([ - 'display_name' => '[DISPLAY_NAME]', - 'translation_dataset_metadata' => new TranslationDatasetMetadata([ - 'source_language_code' => 'en', - 'target_language_code' => 'es' - ]) -]); -$response = $autoMlClient->createDataset($formattedParent, $dataset); + +// Prepare the request message. +$request = (new GetAnnotationSpecRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var AnnotationSpec $response */ + $response = $autoMlClient->getAnnotationSpec($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} ``` ### Debugging diff --git a/BackupDr/README.md b/BackupDr/README.md index 88bda21d7318..b0e803eb4b3e 100644 --- a/BackupDr/README.md +++ b/BackupDr/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\BackupDR\V1\Backup; +use Google\Cloud\BackupDR\V1\Client\BackupDRClient; +use Google\Cloud\BackupDR\V1\GetBackupRequest; // Create a client. $backupDRClient = new BackupDRClient(); diff --git a/BareMetalSolution/README.md b/BareMetalSolution/README.md index dbeb1a4ac91c..2d369d1ed7f9 100644 --- a/BareMetalSolution/README.md +++ b/BareMetalSolution/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\BareMetalSolution\V2\Client\BareMetalSolutionClient; +use Google\Cloud\BareMetalSolution\V2\GetInstanceRequest; +use Google\Cloud\BareMetalSolution\V2\Instance; + +// Create a client. +$bareMetalSolutionClient = new BareMetalSolutionClient(); + +// Prepare the request message. +$request = (new GetInstanceRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Instance $response */ + $response = $bareMetalSolutionClient->getInstance($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Batch/README.md b/Batch/README.md index 800af6c4b02b..b1092919b7d6 100644 --- a/Batch/README.md +++ b/Batch/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Batch\V1\Client\BatchServiceClient; +use Google\Cloud\Batch\V1\GetJobRequest; +use Google\Cloud\Batch\V1\Job; + +// Create a client. +$batchServiceClient = new BatchServiceClient(); + +// Prepare the request message. +$request = (new GetJobRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Job $response */ + $response = $batchServiceClient->getJob($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/BeyondCorpAppConnections/README.md b/BeyondCorpAppConnections/README.md index 92dc5ed4563f..f45eebeae0dc 100644 --- a/BeyondCorpAppConnections/README.md +++ b/BeyondCorpAppConnections/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\BeyondCorp\AppConnections\V1\AppConnection; +use Google\Cloud\BeyondCorp\AppConnections\V1\Client\AppConnectionsServiceClient; +use Google\Cloud\BeyondCorp\AppConnections\V1\GetAppConnectionRequest; + +// Create a client. +$appConnectionsServiceClient = new AppConnectionsServiceClient(); + +// Prepare the request message. +$request = (new GetAppConnectionRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var AppConnection $response */ + $response = $appConnectionsServiceClient->getAppConnection($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/BeyondCorpAppConnectors/README.md b/BeyondCorpAppConnectors/README.md index ddc507ef5125..85b8a3d166b2 100644 --- a/BeyondCorpAppConnectors/README.md +++ b/BeyondCorpAppConnectors/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\BeyondCorp\AppConnectors\V1\AppConnector; +use Google\Cloud\BeyondCorp\AppConnectors\V1\Client\AppConnectorsServiceClient; +use Google\Cloud\BeyondCorp\AppConnectors\V1\GetAppConnectorRequest; + +// Create a client. +$appConnectorsServiceClient = new AppConnectorsServiceClient(); + +// Prepare the request message. +$request = (new GetAppConnectorRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var AppConnector $response */ + $response = $appConnectorsServiceClient->getAppConnector($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/BeyondCorpAppGateways/README.md b/BeyondCorpAppGateways/README.md index d7b8f56dd63d..06a04e44a73c 100644 --- a/BeyondCorpAppGateways/README.md +++ b/BeyondCorpAppGateways/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\BeyondCorp\AppGateways\V1\AppGateway; +use Google\Cloud\BeyondCorp\AppGateways\V1\Client\AppGatewaysServiceClient; +use Google\Cloud\BeyondCorp\AppGateways\V1\GetAppGatewayRequest; + +// Create a client. +$appGatewaysServiceClient = new AppGatewaysServiceClient(); + +// Prepare the request message. +$request = (new GetAppGatewayRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var AppGateway $response */ + $response = $appGatewaysServiceClient->getAppGateway($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/BeyondCorpClientConnectorServices/README.md b/BeyondCorpClientConnectorServices/README.md index d6d5852324ad..1cc41088d109 100644 --- a/BeyondCorpClientConnectorServices/README.md +++ b/BeyondCorpClientConnectorServices/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\ClientConnectorService; +use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\Client\ClientConnectorServicesServiceClient; +use Google\Cloud\BeyondCorp\ClientConnectorServices\V1\GetClientConnectorServiceRequest; + +// Create a client. +$clientConnectorServicesServiceClient = new ClientConnectorServicesServiceClient(); + +// Prepare the request message. +$request = (new GetClientConnectorServiceRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var ClientConnectorService $response */ + $response = $clientConnectorServicesServiceClient->getClientConnectorService($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/BeyondCorpClientGateways/README.md b/BeyondCorpClientGateways/README.md index b3c3b51dfa66..391cc861370c 100644 --- a/BeyondCorpClientGateways/README.md +++ b/BeyondCorpClientGateways/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\BeyondCorp\ClientGateways\V1\ClientGateway; +use Google\Cloud\BeyondCorp\ClientGateways\V1\Client\ClientGatewaysServiceClient; +use Google\Cloud\BeyondCorp\ClientGateways\V1\GetClientGatewayRequest; + +// Create a client. +$clientGatewaysServiceClient = new ClientGatewaysServiceClient(); + +// Prepare the request message. +$request = (new GetClientGatewayRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var ClientGateway $response */ + $response = $clientGatewaysServiceClient->getClientGateway($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/BigQueryAnalyticsHub/README.md b/BigQueryAnalyticsHub/README.md index 2e65732bb003..e3c5a8a602e0 100644 --- a/BigQueryAnalyticsHub/README.md +++ b/BigQueryAnalyticsHub/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\BigQuery\AnalyticsHub\V1\Client\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\AnalyticsHub\V1\DataExchange; +use Google\Cloud\BigQuery\AnalyticsHub\V1\GetDataExchangeRequest; + +// Create a client. +$analyticsHubServiceClient = new AnalyticsHubServiceClient(); + +// Prepare the request message. +$request = (new GetDataExchangeRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var DataExchange $response */ + $response = $analyticsHubServiceClient->getDataExchange($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/BigQueryConnection/README.md b/BigQueryConnection/README.md index 92084602fb12..293e194e01ac 100644 --- a/BigQueryConnection/README.md +++ b/BigQueryConnection/README.md @@ -31,23 +31,26 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\BigQuery\Connection\V1\ConnectionServiceClient; +use Google\ApiCore\ApiException; +use Google\Cloud\BigQuery\Connection\V1\Client\ConnectionServiceClient; use Google\Cloud\BigQuery\Connection\V1\Connection; - -$projectId = '[PROJECT_ID]'; -$locationId = '[LOCATION_ID]'; -$connectionId = '[CONNECTION_ID]'; - -$client = new ConnectionServiceClient(); - -$parent = $client->locationName($projectId, $locationId); -$connection = new Connection([ - 'name' => $client->connectionName($projectId, $locationId, $connectionId), -]); - -$connection = $client->createConnection($parent, $connection); +use Google\Cloud\BigQuery\Connection\V1\GetConnectionRequest; + +// Create a client. +$connectionServiceClient = new ConnectionServiceClient(); + +// Prepare the request message. +$request = (new GetConnectionRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Connection $response */ + $response = $connectionServiceClient->getConnection($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} ``` ### Debugging diff --git a/BigQueryDataExchange/README.md b/BigQueryDataExchange/README.md index 4c4046ca278d..0afc69a91fc5 100644 --- a/BigQueryDataExchange/README.md +++ b/BigQueryDataExchange/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\BigQuery\DataExchange\V1beta1\Client\AnalyticsHubServiceClient; +use Google\Cloud\BigQuery\DataExchange\V1beta1\DataExchange; +use Google\Cloud\BigQuery\DataExchange\V1beta1\GetDataExchangeRequest; + +// Create a client. +$analyticsHubServiceClient = new AnalyticsHubServiceClient(); + +// Prepare the request message. +$request = (new GetDataExchangeRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var DataExchange $response */ + $response = $analyticsHubServiceClient->getDataExchange($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/BigQueryDataPolicies/README.md b/BigQueryDataPolicies/README.md index 2ca36efc93ff..21e38f36e127 100644 --- a/BigQueryDataPolicies/README.md +++ b/BigQueryDataPolicies/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\BigQuery\DataPolicies\V1\Client\DataPolicyServiceClient; +use Google\Cloud\BigQuery\DataPolicies\V1\DataPolicy; +use Google\Cloud\BigQuery\DataPolicies\V1\GetDataPolicyRequest; + +// Create a client. +$dataPolicyServiceClient = new DataPolicyServiceClient(); + +// Prepare the request message. +$request = (new GetDataPolicyRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var DataPolicy $response */ + $response = $dataPolicyServiceClient->getDataPolicy($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/BigQueryDataTransfer/README.md b/BigQueryDataTransfer/README.md index b673d37eb296..bfbe097ad03c 100644 --- a/BigQueryDataTransfer/README.md +++ b/BigQueryDataTransfer/README.md @@ -33,15 +33,26 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\BigQuery\DataTransfer\V1\DataTransferServiceClient; +use Google\ApiCore\ApiException; +use Google\Cloud\BigQuery\DataTransfer\V1\Client\DataTransferServiceClient; +use Google\Cloud\BigQuery\DataTransfer\V1\DataSource; +use Google\Cloud\BigQuery\DataTransfer\V1\GetDataSourceRequest; +// Create a client. $dataTransferServiceClient = new DataTransferServiceClient(); -$projectId = '[MY_PROJECT_ID]'; -$location = 'us-central1'; -$formattedLocation = $dataTransferServiceClient->locationName($projectId, $location); -$dataSources = $dataTransferServiceClient->listDataSources($formattedLocation); + +// Prepare the request message. +$request = (new GetDataSourceRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var DataSource $response */ + $response = $dataTransferServiceClient->getDataSource($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} ``` ### Debugging diff --git a/BigQueryMigration/README.md b/BigQueryMigration/README.md index fb2e85511e63..41cd308e339b 100644 --- a/BigQueryMigration/README.md +++ b/BigQueryMigration/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\BigQuery\Migration\V2\Client\MigrationServiceClient; +use Google\Cloud\BigQuery\Migration\V2\GetMigrationSubtaskRequest; +use Google\Cloud\BigQuery\Migration\V2\MigrationSubtask; + +// Create a client. +$migrationServiceClient = new MigrationServiceClient(); + +// Prepare the request message. +$request = (new GetMigrationSubtaskRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var MigrationSubtask $response */ + $response = $migrationServiceClient->getMigrationSubtask($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/BigQueryReservation/README.md b/BigQueryReservation/README.md index 119c1f78f841..74780c9e6bc4 100644 --- a/BigQueryReservation/README.md +++ b/BigQueryReservation/README.md @@ -31,20 +31,26 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\BigQuery\Reservation\V1\ReservationServiceClient; - -$projectId = '[PROJECT_ID]'; -$locationId = '[LOCATION_ID]'; -$reservationId = '[RESERVATION_ID]'; - -$client = new ReservationServiceClient(); -$parent = $client->locationName($projectId, $locationId); - -$reservation = $client->createReservation($parent, [ - 'reservationId' => $reservationId -]) +use Google\ApiCore\ApiException; +use Google\Cloud\BigQuery\Reservation\V1\BiReservation; +use Google\Cloud\BigQuery\Reservation\V1\Client\ReservationServiceClient; +use Google\Cloud\BigQuery\Reservation\V1\GetBiReservationRequest; + +// Create a client. +$reservationServiceClient = new ReservationServiceClient(); + +// Prepare the request message. +$request = (new GetBiReservationRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var BiReservation $response */ + $response = $reservationServiceClient->getBiReservation($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} ``` ### Debugging diff --git a/BigQueryStorage/README.md b/BigQueryStorage/README.md index ca3c3a6f2b32..c347274708ad 100644 --- a/BigQueryStorage/README.md +++ b/BigQueryStorage/README.md @@ -31,46 +31,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\BigQuery\Storage\V1\BigQueryReadClient; -use Google\Cloud\BigQuery\Storage\V1\DataFormat; -use Google\Cloud\BigQuery\Storage\V1\ReadSession; -use Google\Cloud\BigQuery\Storage\V1\ReadSession\TableReadOptions; - -$client = new BigQueryReadClient(); - -$project = sprintf( - 'projects/%s', - '[MY_PROJECT_ID]' -); -$table = sprintf( - 'projects/%s/datasets/%s/tables/%s', - 'bigquery-public-data', - 'usa_names', - 'usa_1910_current' -); -$readOptions = (new TableReadOptions()) - ->setRowRestriction('state = "WA"'); -$readSession = (new ReadSession()) - ->setTable($table) - ->setDataFormat(DataFormat::AVRO) - ->setReadOptions($readOptions); -$session = $client->createReadSession([ - 'parent' => $project, - 'readSession' => $readSession, - 'maxStreamCount' => 1 -]); - -$stream = $client->readRows([ - 'readStream' => $session->getStreams()[0]->getName() -]); - -foreach ($stream->readAll() as $response) { - printf( - 'Discovered %s rows in response.' . PHP_EOL, - $response->getRowCount() - ); +use Google\ApiCore\ApiException; +use Google\Cloud\BigQuery\Storage\V1\Client\BigQueryWriteClient; +use Google\Cloud\BigQuery\Storage\V1\GetWriteStreamRequest; +use Google\Cloud\BigQuery\Storage\V1\WriteStream; + +// Create a client. +$bigQueryWriteClient = new BigQueryWriteClient(); + +// Prepare the request message. +$request = (new GetWriteStreamRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var WriteStream $response */ + $response = $bigQueryWriteClient->getWriteStream($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/Bigtable/README.md b/Bigtable/README.md index 59f915b6d64a..1b1ab163f152 100644 --- a/Bigtable/README.md +++ b/Bigtable/README.md @@ -48,16 +48,25 @@ outlined for the generated clients. ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Bigtable\BigtableClient; - -$bigtable = new BigtableClient(); -$table = $bigtable->table('my-instance', 'my-table'); -$rows = $table->readRows(); - -foreach ($rows as $row) { - print_r($row) . PHP_EOL; +use Google\ApiCore\ApiException; +use Google\Cloud\Bigtable\V2\Client\BigtableClient; +use Google\Cloud\Bigtable\V2\PingAndWarmRequest; +use Google\Cloud\Bigtable\V2\PingAndWarmResponse; + +// Create a client. +$bigtableClient = new BigtableClient(); + +// Prepare the request message. +$request = (new PingAndWarmRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var PingAndWarmResponse $response */ + $response = $bigtableClient->pingAndWarm($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/Billing/README.md b/Billing/README.md index cd360d2114e4..974f278760e2 100644 --- a/Billing/README.md +++ b/Billing/README.md @@ -31,15 +31,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Billing\V1\CloudBillingClient; - -$client = new CloudBillingClient(); -$accounts = $client->listBillingAccounts(); - -foreach ($accounts as $account) { - print('Billing account: ' . $account->getName() . PHP_EOL); +use Google\ApiCore\ApiException; +use Google\Cloud\Billing\V1\BillingAccount; +use Google\Cloud\Billing\V1\Client\CloudBillingClient; +use Google\Cloud\Billing\V1\GetBillingAccountRequest; + +// Create a client. +$cloudBillingClient = new CloudBillingClient(); + +// Prepare the request message. +$request = (new GetBillingAccountRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var BillingAccount $response */ + $response = $cloudBillingClient->getBillingAccount($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/BillingBudgets/README.md b/BillingBudgets/README.md index 355ffcbe7ec2..5d642e41650e 100644 --- a/BillingBudgets/README.md +++ b/BillingBudgets/README.md @@ -29,6 +29,31 @@ Please see our [Authentication guide](https://github.com/googleapis/google-cloud on authenticating your client. Once authenticated, you'll be ready to start making requests. +### Sample + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Billing\Budgets\V1\Budget; +use Google\Cloud\Billing\Budgets\V1\Client\BudgetServiceClient; +use Google\Cloud\Billing\Budgets\V1\GetBudgetRequest; + +// Create a client. +$budgetServiceClient = new BudgetServiceClient(); + +// Prepare the request message. +$request = (new GetBudgetRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Budget $response */ + $response = $budgetServiceClient->getBudget($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/BinaryAuthorization/README.md b/BinaryAuthorization/README.md index c0cf60c3729f..1402091f926b 100644 --- a/BinaryAuthorization/README.md +++ b/BinaryAuthorization/README.md @@ -29,6 +29,31 @@ Please see our [Authentication guide](https://github.com/googleapis/google-cloud on authenticating your client. Once authenticated, you'll be ready to start making requests. +### Sample + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\BinaryAuthorization\V1\Attestor; +use Google\Cloud\BinaryAuthorization\V1\Client\BinauthzManagementServiceV1Client; +use Google\Cloud\BinaryAuthorization\V1\GetAttestorRequest; + +// Create a client. +$binauthzManagementServiceV1Client = new BinauthzManagementServiceV1Client(); + +// Prepare the request message. +$request = (new GetAttestorRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Attestor $response */ + $response = $binauthzManagementServiceV1Client->getAttestor($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Build/README.md b/Build/README.md index 9b6c85f96718..7cffc6836ceb 100644 --- a/Build/README.md +++ b/Build/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Build\V2\Client\RepositoryManagerClient; +use Google\Cloud\Build\V2\Connection; +use Google\Cloud\Build\V2\GetConnectionRequest; + +// Create a client. +$repositoryManagerClient = new RepositoryManagerClient(); + +// Prepare the request message. +$request = (new GetConnectionRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Connection $response */ + $response = $repositoryManagerClient->getConnection($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/CertificateManager/README.md b/CertificateManager/README.md index cec62ab50aa6..07880100a3cc 100644 --- a/CertificateManager/README.md +++ b/CertificateManager/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\CertificateManager\V1\Certificate; +use Google\Cloud\CertificateManager\V1\Client\CertificateManagerClient; +use Google\Cloud\CertificateManager\V1\GetCertificateRequest; + +// Create a client. +$certificateManagerClient = new CertificateManagerClient(); + +// Prepare the request message. +$request = (new GetCertificateRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Certificate $response */ + $response = $certificateManagerClient->getCertificate($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Channel/README.md b/Channel/README.md index dcf0ff72a271..a3fc8b7d9a36 100644 --- a/Channel/README.md +++ b/Channel/README.md @@ -31,16 +31,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Channel\V1\CloudChannelServiceClient; - -$client = new CloudChannelServiceClient(); - -$customers = $client->listCustomers('accounts/[MY_ACCOUNT_ID]'); - -foreach ($customers as $customer) { - print 'Customer: ' . $customer->getName() . PHP_EOL; +use Google\ApiCore\ApiException; +use Google\Cloud\Channel\V1\ChannelPartnerLink; +use Google\Cloud\Channel\V1\Client\CloudChannelServiceClient; +use Google\Cloud\Channel\V1\GetChannelPartnerLinkRequest; + +// Create a client. +$cloudChannelServiceClient = new CloudChannelServiceClient(); + +// Prepare the request message. +$request = (new GetChannelPartnerLinkRequest()) + ->setName($name); + +// Call the API and handle any network failures. +try { + /** @var ChannelPartnerLink $response */ + $response = $cloudChannelServiceClient->getChannelPartnerLink($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/Chronicle/README.md b/Chronicle/README.md index f8aa7ff92451..de4095fbace1 100644 --- a/Chronicle/README.md +++ b/Chronicle/README.md @@ -35,10 +35,10 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -Google\ApiCore\ApiException; -Google\Cloud\Chronicle\V1\Client\DataAccessControlServiceClient; -Google\Cloud\Chronicle\V1\DataAccessLabel; -Google\Cloud\Chronicle\V1\GetDataAccessLabelRequest; +use Google\ApiCore\ApiException; +use Google\Cloud\Chronicle\V1\Client\DataAccessControlServiceClient; +use Google\Cloud\Chronicle\V1\DataAccessLabel; +use Google\Cloud\Chronicle\V1\GetDataAccessLabelRequest; // Create a client. $dataAccessControlServiceClient = new DataAccessControlServiceClient(); diff --git a/CommerceConsumerProcurement/README.md b/CommerceConsumerProcurement/README.md index ef1f5fe60a90..cabfd4eceedf 100644 --- a/CommerceConsumerProcurement/README.md +++ b/CommerceConsumerProcurement/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\Commerce\Consumer\Procurement\V1\Client\ConsumerProcurementServiceClient; +use Google\Cloud\Commerce\Consumer\Procurement\V1\GetOrderRequest; +use Google\Cloud\Commerce\Consumer\Procurement\V1\Order; // Create a client. $consumerProcurementServiceClient = new ConsumerProcurementServiceClient(); diff --git a/Compute/README.md b/Compute/README.md index 3665c519accf..8275c52e1be5 100644 --- a/Compute/README.md +++ b/Compute/README.md @@ -30,13 +30,27 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Compute\V1\InstancesClient; - -$instances = new InstancesClient(); -foreach ($instances->list('[MY_PROJECT_ID]', 'us-west1') as $instance) { - print($instance->getName() . PHP_EOL); +use Google\ApiCore\ApiException; +use Google\Cloud\Compute\V1\AcceleratorType; +use Google\Cloud\Compute\V1\Client\AcceleratorTypesClient; +use Google\Cloud\Compute\V1\GetAcceleratorTypeRequest; + +// Create a client. +$acceleratorTypesClient = new AcceleratorTypesClient(); + +// Prepare the request message. +$request = (new GetAcceleratorTypeRequest()) + ->setAcceleratorType($acceleratorType) + ->setProject($project) + ->setZone($zone); + +// Call the API and handle any network failures. +try { + /** @var AcceleratorType $response */ + $response = $acceleratorTypesClient->get($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/ConfidentialComputing/README.md b/ConfidentialComputing/README.md index 97739b5534da..adf2137f64ca 100644 --- a/ConfidentialComputing/README.md +++ b/ConfidentialComputing/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\ConfidentialComputing\V1\Client\ConfidentialComputingClient; +use Google\Cloud\Location\GetLocationRequest; +use Google\Cloud\Location\Location; // Create a client. $confidentialComputingClient = new ConfidentialComputingClient(); diff --git a/Config/README.md b/Config/README.md index c19a363e60bb..b6cdfeeae17e 100644 --- a/Config/README.md +++ b/Config/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\Config\V1\Client\ConfigClient; +use Google\Cloud\Config\V1\Deployment; +use Google\Cloud\Config\V1\GetDeploymentRequest; // Create a client. $configClient = new ConfigClient(); diff --git a/ConfigDelivery/README.md b/ConfigDelivery/README.md index ce3f2e0d9589..8c84bc87f663 100644 --- a/ConfigDelivery/README.md +++ b/ConfigDelivery/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +use Google\ApiCore\ApiException; +use Google\Cloud\ConfigDelivery\V1\Client\ConfigDeliveryClient; +use Google\Cloud\ConfigDelivery\V1\FleetPackage; +use Google\Cloud\ConfigDelivery\V1\GetFleetPackageRequest; + +// Create a client. +$configDeliveryClient = new ConfigDeliveryClient(); + +// Prepare the request message. +$request = (new GetFleetPackageRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var FleetPackage $response */ + $response = $configDeliveryClient->getFleetPackage($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-configdelivery/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/ContactCenterInsights/README.md b/ContactCenterInsights/README.md index 417645e8a16c..e0985586a6fb 100644 --- a/ContactCenterInsights/README.md +++ b/ContactCenterInsights/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\ContactCenterInsights\V1\Analysis; +use Google\Cloud\ContactCenterInsights\V1\Client\ContactCenterInsightsClient; +use Google\Cloud\ContactCenterInsights\V1\GetAnalysisRequest; + +// Create a client. +$contactCenterInsightsClient = new ContactCenterInsightsClient(); + +// Prepare the request message. +$request = (new GetAnalysisRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Analysis $response */ + $response = $contactCenterInsightsClient->getAnalysis($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Container/README.md b/Container/README.md index e8bbfd5de472..0a262be308d1 100644 --- a/Container/README.md +++ b/Container/README.md @@ -35,22 +35,24 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Container\V1\ClusterManagerClient; +use Google\ApiCore\ApiException; +use Google\Cloud\Container\V1\Client\ClusterManagerClient; +use Google\Cloud\Container\V1\Cluster; +use Google\Cloud\Container\V1\GetClusterRequest; +// Create a client. $clusterManagerClient = new ClusterManagerClient(); -$projectId = '[MY-PROJECT-ID]'; -$zone = 'us-central1-a'; +// Prepare the request message. +$request = new GetClusterRequest(); +// Call the API and handle any network failures. try { - $clusters = $clusterManagerClient->listClusters($projectId, $zone); - foreach ($clusters->getClusters() as $cluster) { - print('Cluster: ' . $cluster->getName() . PHP_EOL); - } -} finally { - $clusterManagerClient->close(); + /** @var Cluster $response */ + $response = $clusterManagerClient->getCluster($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/ContainerAnalysis/README.md b/ContainerAnalysis/README.md index 65f29500715d..2d03678da394 100644 --- a/ContainerAnalysis/README.md +++ b/ContainerAnalysis/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\ContainerAnalysis\V1\Client\ContainerAnalysisClient; +use Google\Cloud\ContainerAnalysis\V1\GetVulnerabilityOccurrencesSummaryRequest; +use Google\Cloud\ContainerAnalysis\V1\VulnerabilityOccurrencesSummary; + +// Create a client. +$containerAnalysisClient = new ContainerAnalysisClient(); + +// Prepare the request message. +$request = (new GetVulnerabilityOccurrencesSummaryRequest()) + ->setParent($formattedParent); + +// Call the API and handle any network failures. +try { + /** @var VulnerabilityOccurrencesSummary $response */ + $response = $containerAnalysisClient->getVulnerabilityOccurrencesSummary($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/ControlsPartner/README.md b/ControlsPartner/README.md index ebd768aaced0..b6d32d983981 100644 --- a/ControlsPartner/README.md +++ b/ControlsPartner/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\CloudControlsPartner\V1beta\Client\CloudControlsPartnerCoreClient; +use Google\Cloud\CloudControlsPartner\V1beta\Customer; +use Google\Cloud\CloudControlsPartner\V1beta\GetCustomerRequest; // Create a client. $cloudControlsPartnerCoreClient = new CloudControlsPartnerCoreClient(); diff --git a/DataCatalog/README.md b/DataCatalog/README.md index d066f7729cf7..39e597cf9f1c 100644 --- a/DataCatalog/README.md +++ b/DataCatalog/README.md @@ -31,16 +31,26 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\DataCatalog\V1\DataCatalogClient; - -$client = new DataCatalogClient(); -$location = DataCatalogClient::locationName('[MY_PROJECT_ID]', 'us-central1'); - -$entryGroup = $client->createEntryGroup($location, 'sample_entry_group'); - -printf('Created entry group: %s' . PHP_EOL, $entryGroup->getName()); +use Google\ApiCore\ApiException; +use Google\Cloud\DataCatalog\V1\Client\DataCatalogClient; +use Google\Cloud\DataCatalog\V1\Entry; +use Google\Cloud\DataCatalog\V1\GetEntryRequest; + +// Create a client. +$dataCatalogClient = new DataCatalogClient(); + +// Prepare the request message. +$request = (new GetEntryRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Entry $response */ + $response = $dataCatalogClient->getEntry($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} ``` ### Debugging diff --git a/DataCatalogLineage/README.md b/DataCatalogLineage/README.md index fae635a8f79b..7f31165aa5e7 100644 --- a/DataCatalogLineage/README.md +++ b/DataCatalogLineage/README.md @@ -31,10 +31,10 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -Google\ApiCore\ApiException; -Google\Cloud\DataCatalog\Lineage\V1\Client\LineageClient; -Google\Cloud\DataCatalog\Lineage\V1\GetLineageEventRequest; -Google\Cloud\DataCatalog\Lineage\V1\LineageEvent; +use Google\ApiCore\ApiException; +use Google\Cloud\DataCatalog\Lineage\V1\Client\LineageClient; +use Google\Cloud\DataCatalog\Lineage\V1\GetLineageEventRequest; +use Google\Cloud\DataCatalog\Lineage\V1\LineageEvent; // Create a client. $lineageClient = new LineageClient(); diff --git a/DataFusion/README.md b/DataFusion/README.md index 02df22bcc188..844c579b8ebc 100644 --- a/DataFusion/README.md +++ b/DataFusion/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\DataFusion\V1\Client\DataFusionClient; +use Google\Cloud\DataFusion\V1\GetInstanceRequest; +use Google\Cloud\DataFusion\V1\Instance; + +// Create a client. +$dataFusionClient = new DataFusionClient(); + +// Prepare the request message. +$request = (new GetInstanceRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Instance $response */ + $response = $dataFusionClient->getInstance($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/DataLabeling/README.md b/DataLabeling/README.md index dcbf26606833..7842570f417e 100644 --- a/DataLabeling/README.md +++ b/DataLabeling/README.md @@ -29,6 +29,31 @@ Please see our [Authentication guide](https://github.com/googleapis/google-cloud on authenticating your client. Once authenticated, you'll be ready to start making requests. +### Sample + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\DataLabeling\V1beta1\AnnotatedDataset; +use Google\Cloud\DataLabeling\V1beta1\Client\DataLabelingServiceClient; +use Google\Cloud\DataLabeling\V1beta1\GetAnnotatedDatasetRequest; + +// Create a client. +$dataLabelingServiceClient = new DataLabelingServiceClient(); + +// Prepare the request message. +$request = (new GetAnnotatedDatasetRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var AnnotatedDataset $response */ + $response = $dataLabelingServiceClient->getAnnotatedDataset($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Dataflow/README.md b/Dataflow/README.md index 9896c2cd6763..ae8e9a87ecb5 100644 --- a/Dataflow/README.md +++ b/Dataflow/README.md @@ -28,6 +28,30 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Dataflow\V1beta3\Client\JobsV1Beta3Client; +use Google\Cloud\Dataflow\V1beta3\GetJobRequest; +use Google\Cloud\Dataflow\V1beta3\Job; + +// Create a client. +$jobsV1Beta3Client = new JobsV1Beta3Client(); + +// Prepare the request message. +$request = new GetJobRequest(); + +// Call the API and handle any network failures. +try { + /** @var Job $response */ + $response = $jobsV1Beta3Client->getJob($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Dataform/README.md b/Dataform/README.md index b3dad4ac2255..4c60b1797f7a 100644 --- a/Dataform/README.md +++ b/Dataform/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Dataform\V1\Client\DataformClient; +use Google\Cloud\Dataform\V1\CompilationResult; +use Google\Cloud\Dataform\V1\GetCompilationResultRequest; + +// Create a client. +$dataformClient = new DataformClient(); + +// Prepare the request message. +$request = (new GetCompilationResultRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var CompilationResult $response */ + $response = $dataformClient->getCompilationResult($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Dataplex/README.md b/Dataplex/README.md index 8f733c0a2cc5..d4ca3f13c6d0 100644 --- a/Dataplex/README.md +++ b/Dataplex/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Dataplex\V1\AspectType; +use Google\Cloud\Dataplex\V1\Client\CatalogServiceClient; +use Google\Cloud\Dataplex\V1\GetAspectTypeRequest; + +// Create a client. +$catalogServiceClient = new CatalogServiceClient(); + +// Prepare the request message. +$request = (new GetAspectTypeRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var AspectType $response */ + $response = $catalogServiceClient->getAspectType($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Dataproc/README.md b/Dataproc/README.md index 90b8c46592cc..8962bbea26d0 100644 --- a/Dataproc/README.md +++ b/Dataproc/README.md @@ -36,29 +36,26 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Dataproc\V1\JobControllerClient; -use Google\Cloud\Dataproc\V1\Job; -use Google\Cloud\Dataproc\V1\HadoopJob; -use Google\Cloud\Dataproc\V1\JobPlacement; - -$projectId = '[MY_PROJECT_ID]'; -$region = 'global'; -$clusterName = '[MY_CLUSTER]'; - -$jobPlacement = new JobPlacement(); -$jobPlacement->setClusterName($clusterName); - -$hadoopJob = new HadoopJob(); -$hadoopJob->setMainJarFileUri('gs://my-bucket/my-hadoop-job.jar'); - -$job = new Job(); -$job->setPlacement($jobPlacement); -$job->setHadoopJob($hadoopJob); - -$jobControllerClient = new JobControllerClient(); -$submittedJob = $jobControllerClient->submitJob($projectId, $region, $job); +use Google\ApiCore\ApiException; +use Google\Cloud\Dataproc\V1\AutoscalingPolicy; +use Google\Cloud\Dataproc\V1\Client\AutoscalingPolicyServiceClient; +use Google\Cloud\Dataproc\V1\GetAutoscalingPolicyRequest; + +// Create a client. +$autoscalingPolicyServiceClient = new AutoscalingPolicyServiceClient(); + +// Prepare the request message. +$request = (new GetAutoscalingPolicyRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var AutoscalingPolicy $response */ + $response = $autoscalingPolicyServiceClient->getAutoscalingPolicy($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} ``` ### Debugging diff --git a/DataprocMetastore/README.md b/DataprocMetastore/README.md index 864a92eadfc2..b4c9d0c61983 100644 --- a/DataprocMetastore/README.md +++ b/DataprocMetastore/README.md @@ -29,6 +29,31 @@ Please see our [Authentication guide](https://github.com/googleapis/google-cloud on authenticating your client. Once authenticated, you'll be ready to start making requests. +### Sample + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Metastore\V1\Backup; +use Google\Cloud\Metastore\V1\Client\DataprocMetastoreClient; +use Google\Cloud\Metastore\V1\GetBackupRequest; + +// Create a client. +$dataprocMetastoreClient = new DataprocMetastoreClient(); + +// Prepare the request message. +$request = (new GetBackupRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Backup $response */ + $response = $dataprocMetastoreClient->getBackup($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Datastore/README.md b/Datastore/README.md index ac413a65cff0..15637c770e63 100644 --- a/Datastore/README.md +++ b/Datastore/README.md @@ -33,25 +33,26 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Datastore\DatastoreClient; - -$datastore = new DatastoreClient(); - -// Create an entity -$bob = $datastore->entity('Person'); -$bob['firstName'] = 'Bob'; -$bob['email'] = 'bob@example.com'; -$datastore->insert($bob); - -// Update the entity -$bob['email'] = 'bobV2@example.com'; -$datastore->update($bob); - -// If you know the ID of the entity, you can look it up -$key = $datastore->key('Person', '12345328897844'); -$entity = $datastore->lookup($key); +use Google\ApiCore\ApiException; +use Google\Cloud\Datastore\V1\BeginTransactionRequest; +use Google\Cloud\Datastore\V1\BeginTransactionResponse; +use Google\Cloud\Datastore\V1\Client\DatastoreClient; + +// Create a client. +$datastoreClient = new DatastoreClient(); + +// Prepare the request message. +$request = (new BeginTransactionRequest()) + ->setProjectId($projectId); + +// Call the API and handle any network failures. +try { + /** @var BeginTransactionResponse $response */ + $response = $datastoreClient->beginTransaction($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} ``` ### Debugging diff --git a/DatastoreAdmin/README.md b/DatastoreAdmin/README.md index 96764fb0735f..f83064454e94 100644 --- a/DatastoreAdmin/README.md +++ b/DatastoreAdmin/README.md @@ -31,13 +31,24 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -use Google\Cloud\Datastore\Admin\V1\DatastoreAdminClient; - -$admin = new DatastoreAdminClient(); - -$indexes = $admin->listIndexes(); -foreach ($indexes as $index) { - echo "Index ID: " . $index->getIndexId() . PHP_EOL; +use Google\ApiCore\ApiException; +use Google\Cloud\Datastore\Admin\V1\Client\DatastoreAdminClient; +use Google\Cloud\Datastore\Admin\V1\GetIndexRequest; +use Google\Cloud\Datastore\Admin\V1\Index; + +// Create a client. +$datastoreAdminClient = new DatastoreAdminClient(); + +// Prepare the request message. +$request = new GetIndexRequest(); + +// Call the API and handle any network failures. +try { + /** @var Index $response */ + $response = $datastoreAdminClient->getIndex($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/Datastream/README.md b/Datastream/README.md index 7f9700f3b42d..0c4862c34586 100644 --- a/Datastream/README.md +++ b/Datastream/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Datastream\V1\Client\DatastreamClient; +use Google\Cloud\Datastream\V1\ConnectionProfile; +use Google\Cloud\Datastream\V1\GetConnectionProfileRequest; + +// Create a client. +$datastreamClient = new DatastreamClient(); + +// Prepare the request message. +$request = (new GetConnectionProfileRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var ConnectionProfile $response */ + $response = $datastreamClient->getConnectionProfile($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Deploy/README.md b/Deploy/README.md index 8b8b711bea0b..2b28a1466456 100644 --- a/Deploy/README.md +++ b/Deploy/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Deploy\V1\Automation; +use Google\Cloud\Deploy\V1\Client\CloudDeployClient; +use Google\Cloud\Deploy\V1\GetAutomationRequest; + +// Create a client. +$cloudDeployClient = new CloudDeployClient(); + +// Prepare the request message. +$request = (new GetAutomationRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Automation $response */ + $response = $cloudDeployClient->getAutomation($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/DeveloperConnect/README.md b/DeveloperConnect/README.md index 233d40813549..9c7335d008d1 100644 --- a/DeveloperConnect/README.md +++ b/DeveloperConnect/README.md @@ -35,22 +35,22 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\DeveloperConnect\V1\AccountConnector; +use Google\Cloud\DeveloperConnect\V1\Client\DeveloperConnectClient; +use Google\Cloud\DeveloperConnect\V1\GetAccountConnectorRequest; // Create a client. $developerConnectClient = new DeveloperConnectClient(); // Prepare the request message. -$request = (new GetConnectionRequest()) +$request = (new GetAccountConnectorRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { - /** @var Connection $response */ - $response = $developerConnectClient->getConnection($request); + /** @var AccountConnector $response */ + $response = $developerConnectClient->getAccountConnector($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/DeviceStreaming/README.md b/DeviceStreaming/README.md index 90722e59215a..11c8414885bd 100644 --- a/DeviceStreaming/README.md +++ b/DeviceStreaming/README.md @@ -35,10 +35,10 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -Google\ApiCore\ApiException; -Google\Cloud\DeviceStreaming\V1\Client\DirectAccessServiceClient; -Google\Cloud\DeviceStreaming\V1\DeviceSession; -Google\Cloud\DeviceStreaming\V1\GetDeviceSessionRequest; +use Google\ApiCore\ApiException; +use Google\Cloud\DeviceStreaming\V1\Client\DirectAccessServiceClient; +use Google\Cloud\DeviceStreaming\V1\DeviceSession; +use Google\Cloud\DeviceStreaming\V1\GetDeviceSessionRequest; // Create a client. $directAccessServiceClient = new DirectAccessServiceClient(); diff --git a/Dialogflow/README.md b/Dialogflow/README.md index 3be307e0f387..b4650e707b29 100644 --- a/Dialogflow/README.md +++ b/Dialogflow/README.md @@ -36,24 +36,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Dialogflow\V2\EntityTypesClient; - -$entityTypesClient = new EntityTypesClient(); -$projectId = '[MY_PROJECT_ID]'; -$entityTypeId = '[ENTITY_TYPE_ID]'; -$formattedEntityTypeName = $entityTypesClient->entityTypeName($projectId, $entityTypeId); - -$entityType = $entityTypesClient->getEntityType($formattedEntityTypeName); -foreach ($entityType->getEntities() as $entity) { - print(PHP_EOL); - printf('Entity value: %s' . PHP_EOL, $entity->getValue()); - print('Synonyms: '); - foreach ($entity->getSynonyms() as $synonym) { - print($synonym . "\t"); - } - print(PHP_EOL); +use Google\ApiCore\ApiException; +use Google\Cloud\Dialogflow\V2\Agent; +use Google\Cloud\Dialogflow\V2\Client\AgentsClient; +use Google\Cloud\Dialogflow\V2\GetAgentRequest; + +// Create a client. +$agentsClient = new AgentsClient(); + +// Prepare the request message. +$request = (new GetAgentRequest()) + ->setParent($formattedParent); + +// 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()); } ``` diff --git a/DialogflowCx/README.md b/DialogflowCx/README.md index b396e5b4ee96..cec02714c23a 100644 --- a/DialogflowCx/README.md +++ b/DialogflowCx/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\Dialogflow\Cx\V3\Agent; +use Google\Cloud\Dialogflow\Cx\V3\Client\AgentsClient; +use Google\Cloud\Dialogflow\Cx\V3\GetAgentRequest; // Create a client. $agentsClient = new AgentsClient(); diff --git a/DiscoveryEngine/README.md b/DiscoveryEngine/README.md index 22e23380a15c..c790e83c1bf8 100644 --- a/DiscoveryEngine/README.md +++ b/DiscoveryEngine/README.md @@ -35,22 +35,22 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\DiscoveryEngine\V1\Client\CmekConfigServiceClient; +use Google\Cloud\DiscoveryEngine\V1\CmekConfig; +use Google\Cloud\DiscoveryEngine\V1\GetCmekConfigRequest; // Create a client. -$controlServiceClient = new ControlServiceClient(); +$cmekConfigServiceClient = new CmekConfigServiceClient(); // Prepare the request message. -$request = (new GetControlRequest()) +$request = (new GetCmekConfigRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { - /** @var Control $response */ - $response = $controlServiceClient->getControl($request); + /** @var CmekConfig $response */ + $response = $cmekConfigServiceClient->getCmekConfig($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Dlp/README.md b/Dlp/README.md index e0b08fe30947..db27f133934c 100644 --- a/Dlp/README.md +++ b/Dlp/README.md @@ -33,34 +33,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Dlp\V2\DlpServiceClient; -use Google\Cloud\Dlp\V2\ContentItem; -use Google\Cloud\Dlp\V2\InfoType; -use Google\Cloud\Dlp\V2\InspectConfig; +use Google\ApiCore\ApiException; +use Google\Cloud\Dlp\V2\Client\DlpServiceClient; +use Google\Cloud\Dlp\V2\ColumnDataProfile; +use Google\Cloud\Dlp\V2\GetColumnDataProfileRequest; +// Create a client. $dlpServiceClient = new DlpServiceClient(); -$infoTypesElement = (new InfoType()) - ->setName('EMAIL_ADDRESS'); -$inspectConfig = (new InspectConfig()) - ->setInfoTypes([$infoTypesElement]); -$item = (new ContentItem()) - ->setValue('My email is example@example.com.'); -$formattedParent = $dlpServiceClient - ->projectName('[PROJECT_ID]'); - -$response = $dlpServiceClient->inspectContent($formattedParent, [ - 'inspectConfig' => $inspectConfig, - 'item' => $item -]); - -$findings = $response->getResult() - ->getFindings(); - -foreach ($findings as $finding) { - print $finding->getInfoType() - ->getName() . PHP_EOL; + +// Prepare the request message. +$request = (new GetColumnDataProfileRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var ColumnDataProfile $response */ + $response = $dlpServiceClient->getColumnDataProfile($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/Dms/README.md b/Dms/README.md index aeab6cd119f4..fd8528faad9c 100644 --- a/Dms/README.md +++ b/Dms/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\CloudDms\V1\Client\DataMigrationServiceClient; +use Google\Cloud\CloudDms\V1\ConnectionProfile; +use Google\Cloud\CloudDms\V1\GetConnectionProfileRequest; + +// Create a client. +$dataMigrationServiceClient = new DataMigrationServiceClient(); + +// Prepare the request message. +$request = (new GetConnectionProfileRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var ConnectionProfile $response */ + $response = $dataMigrationServiceClient->getConnectionProfile($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/DocumentAi/README.md b/DocumentAi/README.md index 886b22502822..8fd718d8b2a2 100644 --- a/DocumentAi/README.md +++ b/DocumentAi/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\DocumentAI\V1\Client\DocumentProcessorServiceClient; +use Google\Cloud\DocumentAI\V1\Evaluation; +use Google\Cloud\DocumentAI\V1\GetEvaluationRequest; + +// Create a client. +$documentProcessorServiceClient = new DocumentProcessorServiceClient(); + +// Prepare the request message. +$request = (new GetEvaluationRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Evaluation $response */ + $response = $documentProcessorServiceClient->getEvaluation($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Domains/README.md b/Domains/README.md index 22f60448be1a..b6b71df3b9f2 100644 --- a/Domains/README.md +++ b/Domains/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Domains\V1\Client\DomainsClient; +use Google\Cloud\Domains\V1\GetRegistrationRequest; +use Google\Cloud\Domains\V1\Registration; + +// Create a client. +$domainsClient = new DomainsClient(); + +// Prepare the request message. +$request = (new GetRegistrationRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Registration $response */ + $response = $domainsClient->getRegistration($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/EdgeNetwork/README.md b/EdgeNetwork/README.md index b477c58d7e58..ef28ae3e0a91 100644 --- a/EdgeNetwork/README.md +++ b/EdgeNetwork/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\EdgeNetwork\V1\Client\EdgeNetworkClient; +use Google\Cloud\EdgeNetwork\V1\GetInterconnectRequest; +use Google\Cloud\EdgeNetwork\V1\Interconnect; // Create a client. $edgeNetworkClient = new EdgeNetworkClient(); diff --git a/ErrorReporting/README.md b/ErrorReporting/README.md index f3ad070c9ebb..49f2d4dd1547 100644 --- a/ErrorReporting/README.md +++ b/ErrorReporting/README.md @@ -33,10 +33,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\ErrorReporting\V1beta1\Client\ErrorGroupServiceClient; +use Google\Cloud\ErrorReporting\V1beta1\ErrorGroup; +use Google\Cloud\ErrorReporting\V1beta1\GetGroupRequest; // Create a client. $errorGroupServiceClient = new ErrorGroupServiceClient(); @@ -55,51 +55,6 @@ try { } ``` -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: - -```php -require 'vendor/autoload.php'; - -use Google\Cloud\ErrorReporting\Bootstrap; -use Google\Cloud\Logging\LoggingClient; -use Google\Cloud\Core\Report\SimpleMetadataProvider; - -$projectId = '[PROJECT]'; -$service = '[SERVICE_NAME]'; -$version = '[APP_VERSION]'; - -$logging = new LoggingClient(); -$metadata = new SimpleMetadataProvider([], $projectId, $service, $version); -$psrLogger = $logging->psrLogger('error-log', [ - 'metadataProvider' => $metadata -]); - -// Register the logger as a PHP exception and error handler. -// This will begin logging application exceptions and errors to Stackdriver. -Bootstrap::init($psrLogger); -``` - -#### Using the Error Reporting API: - -```php -require 'vendor/autoload.php'; - -use Google\Cloud\ErrorReporting\V1beta1\ReportErrorsServiceClient; -use Google\Cloud\ErrorReporting\V1beta1\ReportedErrorEvent; - -$reportErrorsServiceClient = new ReportErrorsServiceClient(); -$formattedProjectName = $reportErrorsServiceClient->projectName('[PROJECT]'); -$event = new ReportedErrorEvent(); - -try { - $response = $reportErrorsServiceClient->reportErrorEvent($formattedProjectName, $event); -} finally { - $reportErrorsServiceClient->close(); -} -``` - ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/EssentialContacts/README.md b/EssentialContacts/README.md index 6364e330066f..f11248cf9bfa 100644 --- a/EssentialContacts/README.md +++ b/EssentialContacts/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\EssentialContacts\V1\Client\EssentialContactsServiceClient; +use Google\Cloud\EssentialContacts\V1\Contact; +use Google\Cloud\EssentialContacts\V1\GetContactRequest; + +// Create a client. +$essentialContactsServiceClient = new EssentialContactsServiceClient(); + +// Prepare the request message. +$request = (new GetContactRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Contact $response */ + $response = $essentialContactsServiceClient->getContact($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Eventarc/README.md b/Eventarc/README.md index b58e41f1ab14..8bda15d24c0b 100644 --- a/Eventarc/README.md +++ b/Eventarc/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Eventarc\V1\Channel; +use Google\Cloud\Eventarc\V1\Client\EventarcClient; +use Google\Cloud\Eventarc\V1\GetChannelRequest; + +// Create a client. +$eventarcClient = new EventarcClient(); + +// Prepare the request message. +$request = (new GetChannelRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Channel $response */ + $response = $eventarcClient->getChannel($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/EventarcPublishing/README.md b/EventarcPublishing/README.md index 9d790583c6e1..2088306fd67a 100644 --- a/EventarcPublishing/README.md +++ b/EventarcPublishing/README.md @@ -28,6 +28,30 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Eventarc\Publishing\V1\Client\PublisherClient; +use Google\Cloud\Eventarc\Publishing\V1\PublishChannelConnectionEventsRequest; +use Google\Cloud\Eventarc\Publishing\V1\PublishChannelConnectionEventsResponse; + +// Create a client. +$publisherClient = new PublisherClient(); + +// Prepare the request message. +$request = new PublishChannelConnectionEventsRequest(); + +// Call the API and handle any network failures. +try { + /** @var PublishChannelConnectionEventsResponse $response */ + $response = $publisherClient->publishChannelConnectionEvents($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Filestore/README.md b/Filestore/README.md index 6b031d29f98b..ef8ce77edc26 100644 --- a/Filestore/README.md +++ b/Filestore/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Filestore\V1\Backup; +use Google\Cloud\Filestore\V1\Client\CloudFilestoreManagerClient; +use Google\Cloud\Filestore\V1\GetBackupRequest; + +// Create a client. +$cloudFilestoreManagerClient = new CloudFilestoreManagerClient(); + +// Prepare the request message. +$request = (new GetBackupRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Backup $response */ + $response = $cloudFilestoreManagerClient->getBackup($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/FinancialServices/README.md b/FinancialServices/README.md index 63405b10ef50..2316f6ba0129 100644 --- a/FinancialServices/README.md +++ b/FinancialServices/README.md @@ -35,10 +35,10 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -Google\ApiCore\ApiException; -Google\Cloud\FinancialServices\V1\BacktestResult; -Google\Cloud\FinancialServices\V1\Client\AMLClient; -Google\Cloud\FinancialServices\V1\GetBacktestResultRequest; +use Google\ApiCore\ApiException; +use Google\Cloud\FinancialServices\V1\BacktestResult; +use Google\Cloud\FinancialServices\V1\Client\AMLClient; +use Google\Cloud\FinancialServices\V1\GetBacktestResultRequest; // Create a client. $aMLClient = new AMLClient(); diff --git a/Firestore/README.md b/Firestore/README.md index 62dc866de05f..cd75fe245536 100644 --- a/Firestore/README.md +++ b/Firestore/README.md @@ -36,17 +36,26 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Firestore\FirestoreClient; - -$firestore = new FirestoreClient(); - -$collectionReference = $firestore->collection('Users'); -$documentReference = $collectionReference->document($userId); -$snapshot = $documentReference->snapshot(); - -echo "Hello " . $snapshot['firstName']; +use Google\ApiCore\ApiException; +use Google\Cloud\Firestore\V1\Client\FirestoreClient; +use Google\Cloud\Firestore\V1\Document; +use Google\Cloud\Firestore\V1\GetDocumentRequest; + +// Create a client. +$firestoreClient = new FirestoreClient(); + +// Prepare the request message. +$request = (new GetDocumentRequest()) + ->setName($name); + +// Call the API and handle any network failures. +try { + /** @var Document $response */ + $response = $firestoreClient->getDocument($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} ``` ### Debugging diff --git a/Functions/README.md b/Functions/README.md index 605f5908b336..8f8313a9ac48 100644 --- a/Functions/README.md +++ b/Functions/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Functions\V2\Client\FunctionServiceClient; +use Google\Cloud\Functions\V2\GetFunctionRequest; +use Google\Cloud\Functions\V2\PBFunction; + +// Create a client. +$functionServiceClient = new FunctionServiceClient(); + +// Prepare the request message. +$request = (new GetFunctionRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var PBFunction $response */ + $response = $functionServiceClient->getFunction($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/GSuiteAddOns/README.md b/GSuiteAddOns/README.md index 81b2dd013b5d..01e485fcc693 100644 --- a/GSuiteAddOns/README.md +++ b/GSuiteAddOns/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\GSuiteAddOns\V1\Authorization; +use Google\Cloud\GSuiteAddOns\V1\Client\GSuiteAddOnsClient; +use Google\Cloud\GSuiteAddOns\V1\GetAuthorizationRequest; + +// Create a client. +$gSuiteAddOnsClient = new GSuiteAddOnsClient(); + +// Prepare the request message. +$request = (new GetAuthorizationRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Authorization $response */ + $response = $gSuiteAddOnsClient->getAuthorization($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/GeminiDataAnalytics/README.md b/GeminiDataAnalytics/README.md index 803c4225d53d..1a8767c14d7b 100644 --- a/GeminiDataAnalytics/README.md +++ b/GeminiDataAnalytics/README.md @@ -34,6 +34,28 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +use Google\ApiCore\ApiException; +use Google\Cloud\GeminiDataAnalytics\V1beta\Client\ContextRetrievalServiceClient; +use Google\Cloud\Location\GetLocationRequest; +use Google\Cloud\Location\Location; + +// Create a client. +$contextRetrievalServiceClient = new ContextRetrievalServiceClient(); + +// Prepare the request message. +$request = new GetLocationRequest(); + +// Call the API and handle any network failures. +try { + /** @var Location $response */ + $response = $contextRetrievalServiceClient->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-geminidataanalytics/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/GkeBackup/README.md b/GkeBackup/README.md index 02c0ecd6ef7d..e239d2f2b733 100644 --- a/GkeBackup/README.md +++ b/GkeBackup/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\GkeBackup\V1\Backup; +use Google\Cloud\GkeBackup\V1\Client\BackupForGKEClient; +use Google\Cloud\GkeBackup\V1\GetBackupRequest; + +// Create a client. +$backupForGKEClient = new BackupForGKEClient(); + +// Prepare the request message. +$request = (new GetBackupRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Backup $response */ + $response = $backupForGKEClient->getBackup($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/GkeConnectGateway/README.md b/GkeConnectGateway/README.md index 59980fb75504..fb1c1a4911e3 100644 --- a/GkeConnectGateway/README.md +++ b/GkeConnectGateway/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\GkeConnect\Gateway\V1\Client\GatewayControlClient; +use Google\Cloud\GkeConnect\Gateway\V1\GenerateCredentialsRequest; +use Google\Cloud\GkeConnect\Gateway\V1\GenerateCredentialsResponse; + +// Create a client. +$gatewayControlClient = new GatewayControlClient(); + +// Prepare the request message. +$request = (new GenerateCredentialsRequest()) + ->setName($name); + +// Call the API and handle any network failures. +try { + /** @var GenerateCredentialsResponse $response */ + $response = $gatewayControlClient->generateCredentials($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/GkeHub/README.md b/GkeHub/README.md index 79012a541f1b..34ffa20d89d5 100644 --- a/GkeHub/README.md +++ b/GkeHub/README.md @@ -28,6 +28,30 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\GkeHub\V1\Client\GkeHubClient; +use Google\Cloud\GkeHub\V1\Feature; +use Google\Cloud\GkeHub\V1\GetFeatureRequest; + +// Create a client. +$gkeHubClient = new GkeHubClient(); + +// Prepare the request message. +$request = new GetFeatureRequest(); + +// Call the API and handle any network failures. +try { + /** @var Feature $response */ + $response = $gkeHubClient->getFeature($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/GkeMultiCloud/README.md b/GkeMultiCloud/README.md index a5a3295d5ba7..eb419d0c427c 100644 --- a/GkeMultiCloud/README.md +++ b/GkeMultiCloud/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\GkeMultiCloud\V1\AttachedCluster; +use Google\Cloud\GkeMultiCloud\V1\Client\AttachedClustersClient; +use Google\Cloud\GkeMultiCloud\V1\GetAttachedClusterRequest; + +// Create a client. +$attachedClustersClient = new AttachedClustersClient(); + +// Prepare the request message. +$request = (new GetAttachedClusterRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var AttachedCluster $response */ + $response = $attachedClustersClient->getAttachedCluster($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Grafeas/README.md b/Grafeas/README.md index 34b58b957586..6514dd8c9793 100644 --- a/Grafeas/README.md +++ b/Grafeas/README.md @@ -28,6 +28,28 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; + +// Create a client. +$grafeasClient = new GrafeasClient(); + +// Prepare the request message. +$request = (new GetNoteRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Note $response */ + $response = $grafeasClient->getNote($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Iam/README.md b/Iam/README.md index 4ef606571289..6a10a0938d81 100644 --- a/Iam/README.md +++ b/Iam/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Iam\V3\Client\PolicyBindingsClient; +use Google\Cloud\Iam\V3\GetPolicyBindingRequest; +use Google\Cloud\Iam\V3\PolicyBinding; + +// Create a client. +$policyBindingsClient = new PolicyBindingsClient(); + +// Prepare the request message. +$request = (new GetPolicyBindingRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var PolicyBinding $response */ + $response = $policyBindingsClient->getPolicyBinding($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/IamCredentials/README.md b/IamCredentials/README.md index 4030d96c8733..11e5b6d3a728 100644 --- a/IamCredentials/README.md +++ b/IamCredentials/README.md @@ -28,6 +28,32 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Iam\Credentials\V1\Client\IAMCredentialsClient; +use Google\Cloud\Iam\Credentials\V1\SignBlobRequest; +use Google\Cloud\Iam\Credentials\V1\SignBlobResponse; + +// Create a client. +$iAMCredentialsClient = new IAMCredentialsClient(); + +// Prepare the request message. +$request = (new SignBlobRequest()) + ->setName($formattedName) + ->setPayload($payload); + +// Call the API and handle any network failures. +try { + /** @var SignBlobResponse $response */ + $response = $iAMCredentialsClient->signBlob($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Iap/README.md b/Iap/README.md index 244814048fcb..a93ebf6ce640 100644 --- a/Iap/README.md +++ b/Iap/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Iap\V1\Client\IdentityAwareProxyAdminServiceClient; +use Google\Cloud\Iap\V1\GetIapSettingsRequest; +use Google\Cloud\Iap\V1\IapSettings; + +// Create a client. +$identityAwareProxyAdminServiceClient = new IdentityAwareProxyAdminServiceClient(); + +// Prepare the request message. +$request = (new GetIapSettingsRequest()) + ->setName($name); + +// Call the API and handle any network failures. +try { + /** @var IapSettings $response */ + $response = $identityAwareProxyAdminServiceClient->getIapSettings($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Ids/README.md b/Ids/README.md index 85bcf5b15be0..ff7055c304d8 100644 --- a/Ids/README.md +++ b/Ids/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Ids\V1\Client\IDSClient; +use Google\Cloud\Ids\V1\Endpoint; +use Google\Cloud\Ids\V1\GetEndpointRequest; + +// Create a client. +$iDSClient = new IDSClient(); + +// Prepare the request message. +$request = (new GetEndpointRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Endpoint $response */ + $response = $iDSClient->getEndpoint($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Kms/README.md b/Kms/README.md index 1c706f389d11..1a58619f12b2 100644 --- a/Kms/README.md +++ b/Kms/README.md @@ -31,58 +31,26 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require __DIR__ . '/vendor/autoload.php'; - use Google\ApiCore\ApiException; -use Google\Cloud\Kms\V1\CryptoKey; -use Google\Cloud\Kms\V1\CryptoKey\CryptoKeyPurpose; -use Google\Cloud\Kms\V1\KeyManagementServiceClient; -use Google\Cloud\Kms\V1\KeyRing; - -$client = new KeyManagementServiceClient(); - -$projectId = 'example-project'; -$location = 'global'; +use Google\Cloud\Kms\V1\AutokeyConfig; +use Google\Cloud\Kms\V1\Client\AutokeyAdminClient; +use Google\Cloud\Kms\V1\GetAutokeyConfigRequest; -// Create a keyring -$keyRingId = 'example-keyring'; -$locationName = $client::locationName($projectId, $location); -$keyRingName = $client::keyRingName($projectId, $location, $keyRingId); - -try { - $keyRing = $client->getKeyRing($keyRingName); -} catch (ApiException $e) { - if ($e->getStatus() === 'NOT_FOUND') { - $keyRing = new KeyRing(); - $keyRing->setName($keyRingName); - $client->createKeyRing($locationName, $keyRingId, $keyRing); - } -} +// Create a client. +$autokeyAdminClient = new AutokeyAdminClient(); -// Create a cryptokey -$keyId = 'example-key'; -$keyName = $client::cryptoKeyName($projectId, $location, $keyRingId, $keyId); +// Prepare the request message. +$request = (new GetAutokeyConfigRequest()) + ->setName($formattedName); +// Call the API and handle any network failures. try { - $cryptoKey = $client->getCryptoKey($keyName); -} catch (ApiException $e) { - if ($e->getStatus() === 'NOT_FOUND') { - $cryptoKey = new CryptoKey(); - $cryptoKey->setPurpose(CryptoKeyPurpose::ENCRYPT_DECRYPT); - $cryptoKey = $client->createCryptoKey($keyRingName, $keyId, $cryptoKey); - } + /** @var AutokeyConfig $response */ + $response = $autokeyAdminClient->getAutokeyConfig($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } - -// Encrypt and decrypt -$secret = 'My secret text'; -$response = $client->encrypt($keyName, $secret); -$cipherText = $response->getCiphertext(); - -$response = $client->decrypt($keyName, $cipherText); - -$plainText = $response->getPlaintext(); - -assert($secret === $plainText); ``` ### Debugging diff --git a/KmsInventory/README.md b/KmsInventory/README.md index d60089dbe197..43fc1616a8a7 100644 --- a/KmsInventory/README.md +++ b/KmsInventory/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\Kms\Inventory\V1\Client\KeyTrackingServiceClient; +use Google\Cloud\Kms\Inventory\V1\GetProtectedResourcesSummaryRequest; +use Google\Cloud\Kms\Inventory\V1\ProtectedResourcesSummary; // Create a client. $keyTrackingServiceClient = new KeyTrackingServiceClient(); diff --git a/Language/README.md b/Language/README.md index bb990bd7ac2a..846318d814c3 100644 --- a/Language/README.md +++ b/Language/README.md @@ -31,32 +31,27 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Language\LanguageClient; - -$language = new LanguageClient(); - -// Analyze a sentence. -$annotation = $language->annotateText('Greetings from Michigan!'); - -// Check the sentiment. -if ($annotation->sentiment() > 0) { - echo "This is a positive message.\n"; -} - -// Detect entities. -$entities = $annotation->entitiesByType('LOCATION'); - -foreach ($entities as $entity) { - echo $entity['name'] . "\n"; -} - -// Parse the syntax. -$tokens = $annotation->tokensByTag('NOUN'); - -foreach ($tokens as $token) { - echo $token['text']['content'] . "\n"; +use Google\ApiCore\ApiException; +use Google\Cloud\Language\V2\AnalyzeSentimentRequest; +use Google\Cloud\Language\V2\AnalyzeSentimentResponse; +use Google\Cloud\Language\V2\Client\LanguageServiceClient; +use Google\Cloud\Language\V2\Document; + +// Create a client. +$languageServiceClient = new LanguageServiceClient(); + +// Prepare the request message. +$document = new Document(); +$request = (new AnalyzeSentimentRequest()) + ->setDocument($document); + +// Call the API and handle any network failures. +try { + /** @var AnalyzeSentimentResponse $response */ + $response = $languageServiceClient->analyzeSentiment($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/LicenseManager/README.md b/LicenseManager/README.md index 10cf78520804..72645a044592 100644 --- a/LicenseManager/README.md +++ b/LicenseManager/README.md @@ -35,10 +35,10 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -Google\ApiCore\ApiException; -Google\Cloud\LicenseManager\V1\Client\LicenseManagerClient; -Google\Cloud\LicenseManager\V1\Configuration; -Google\Cloud\LicenseManager\V1\GetConfigurationRequest; +use Google\ApiCore\ApiException; +use Google\Cloud\LicenseManager\V1\Client\LicenseManagerClient; +use Google\Cloud\LicenseManager\V1\Configuration; +use Google\Cloud\LicenseManager\V1\GetConfigurationRequest; // Create a client. $licenseManagerClient = new LicenseManagerClient(); diff --git a/LifeSciences/README.md b/LifeSciences/README.md index 059f4070e868..8247fa79e658 100644 --- a/LifeSciences/README.md +++ b/LifeSciences/README.md @@ -28,6 +28,30 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\LifeSciences\V2beta\Client\WorkflowsServiceV2BetaClient; +use Google\Cloud\Location\GetLocationRequest; +use Google\Cloud\Location\Location; + +// Create a client. +$workflowsServiceV2BetaClient = new WorkflowsServiceV2BetaClient(); + +// Prepare the request message. +$request = new GetLocationRequest(); + +// Call the API and handle any network failures. +try { + /** @var Location $response */ + $response = $workflowsServiceV2BetaClient->getLocation($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Logging/README.md b/Logging/README.md index 24fe5fdd8efa..fac38224f896 100644 --- a/Logging/README.md +++ b/Logging/README.md @@ -34,25 +34,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Logging\LoggingClient; - -$logging = new LoggingClient(); - -// Get a logger instance. -$logger = $logging->logger('my_log'); - -// Write a log entry. -$logger->write('my message'); - -// List log entries from a specific log. -$entries = $logging->entries([ - 'filter' => 'logName = projects/my_project/logs/my_log' -]); - -foreach ($entries as $entry) { - echo $entry->info()['textPayload'] . "\n"; +use Google\ApiCore\ApiException; +use Google\Cloud\Logging\V2\Client\ConfigServiceV2Client; +use Google\Cloud\Logging\V2\GetBucketRequest; +use Google\Cloud\Logging\V2\LogBucket; + +// Create a client. +$configServiceV2Client = new ConfigServiceV2Client(); + +// Prepare the request message. +$request = (new GetBucketRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var LogBucket $response */ + $response = $configServiceV2Client->getBucket($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/Lustre/README.md b/Lustre/README.md index 478ddc47cb9b..ea7ce1c667ac 100644 --- a/Lustre/README.md +++ b/Lustre/README.md @@ -35,10 +35,10 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -Google\ApiCore\ApiException; -Google\Cloud\Lustre\V1\Client\LustreClient; -Google\Cloud\Lustre\V1\GetInstanceRequest; -Google\Cloud\Lustre\V1\Instance; +use Google\ApiCore\ApiException; +use Google\Cloud\Lustre\V1\Client\LustreClient; +use Google\Cloud\Lustre\V1\GetInstanceRequest; +use Google\Cloud\Lustre\V1\Instance; // Create a client. $lustreClient = new LustreClient(); diff --git a/Maintenance/README.md b/Maintenance/README.md index f88b96fbd65c..f761debecd9f 100644 --- a/Maintenance/README.md +++ b/Maintenance/README.md @@ -35,10 +35,10 @@ 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\Maintenance\Api\V1beta\Client\MaintenanceClient; +use Google\ApiCore\ApiException; +use Google\Cloud\Location\GetLocationRequest; +use Google\Cloud\Location\Location; +use Google\Cloud\Maintenance\Api\V1beta\Client\MaintenanceClient; // Create a client. $maintenanceClient = new MaintenanceClient(); diff --git a/ManagedIdentities/README.md b/ManagedIdentities/README.md index fa0084370877..3fa4ad8956fd 100644 --- a/ManagedIdentities/README.md +++ b/ManagedIdentities/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\ManagedIdentities\V1\Client\ManagedIdentitiesServiceClient; +use Google\Cloud\ManagedIdentities\V1\Domain; +use Google\Cloud\ManagedIdentities\V1\GetDomainRequest; + +// Create a client. +$managedIdentitiesServiceClient = new ManagedIdentitiesServiceClient(); + +// Prepare the request message. +$request = (new GetDomainRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Domain $response */ + $response = $managedIdentitiesServiceClient->getDomain($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/ManagedKafka/README.md b/ManagedKafka/README.md index 93ac69ea3da2..b13ed3937a5e 100644 --- a/ManagedKafka/README.md +++ b/ManagedKafka/README.md @@ -35,22 +35,22 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\ManagedKafka\V1\Acl; +use Google\Cloud\ManagedKafka\V1\Client\ManagedKafkaClient; +use Google\Cloud\ManagedKafka\V1\GetAclRequest; // Create a client. $managedKafkaClient = new ManagedKafkaClient(); // Prepare the request message. -$request = (new GetClusterRequest()) +$request = (new GetAclRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { - /** @var Cluster $response */ - $response = $managedKafkaClient->getCluster($request); + /** @var Acl $response */ + $response = $managedKafkaClient->getAcl($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ManagedKafkaSchemaRegistry/README.md b/ManagedKafkaSchemaRegistry/README.md index a867bf43810c..04daf685b90c 100644 --- a/ManagedKafkaSchemaRegistry/README.md +++ b/ManagedKafkaSchemaRegistry/README.md @@ -34,6 +34,29 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample +```php +use Google\ApiCore\ApiException; +use Google\Cloud\ManagedKafka\SchemaRegistry\V1\Client\ManagedSchemaRegistryClient; +use Google\Cloud\ManagedKafka\SchemaRegistry\V1\Context; +use Google\Cloud\ManagedKafka\SchemaRegistry\V1\GetContextRequest; + +// Create a client. +$managedSchemaRegistryClient = new ManagedSchemaRegistryClient(); + +// Prepare the request message. +$request = (new GetContextRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Context $response */ + $response = $managedSchemaRegistryClient->getContext($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-schemaregistry/tree/main/samples) for a canonical list of samples. ### Debugging diff --git a/MapsFleetEngine/README.md b/MapsFleetEngine/README.md index d61465af85e4..042ec6a7e909 100644 --- a/MapsFleetEngine/README.md +++ b/MapsFleetEngine/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Maps\FleetEngine\V1\Client\TripServiceClient; +use Google\Maps\FleetEngine\V1\GetTripRequest; +use Google\Maps\FleetEngine\V1\Trip; // Create a client. $tripServiceClient = new TripServiceClient(); diff --git a/MapsFleetEngineDelivery/README.md b/MapsFleetEngineDelivery/README.md index 5c711f4532ba..aaa9c2f9ee3a 100644 --- a/MapsFleetEngineDelivery/README.md +++ b/MapsFleetEngineDelivery/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Maps\FleetEngine\Delivery\V1\Client\DeliveryServiceClient; +use Google\Maps\FleetEngine\Delivery\V1\DeliveryVehicle; +use Google\Maps\FleetEngine\Delivery\V1\GetDeliveryVehicleRequest; // Create a client. $deliveryServiceClient = new DeliveryServiceClient(); diff --git a/MapsRouteOptimization/README.md b/MapsRouteOptimization/README.md index 8cbd5ef6e516..de2314dc820c 100644 --- a/MapsRouteOptimization/README.md +++ b/MapsRouteOptimization/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Maps\RouteOptimization\V1\Client\RouteOptimizationClient; +use Google\Maps\RouteOptimization\V1\OptimizeToursRequest; +use Google\Maps\RouteOptimization\V1\OptimizeToursResponse; // Create a client. $routeOptimizationClient = new RouteOptimizationClient(); diff --git a/MediaTranslation/README.md b/MediaTranslation/README.md index 1b7a45098cfd..1bb65abbda55 100644 --- a/MediaTranslation/README.md +++ b/MediaTranslation/README.md @@ -28,6 +28,36 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\ApiCore\BidiStream; +use Google\Cloud\MediaTranslation\V1beta1\Client\SpeechTranslationServiceClient; +use Google\Cloud\MediaTranslation\V1beta1\StreamingTranslateSpeechRequest; +use Google\Cloud\MediaTranslation\V1beta1\StreamingTranslateSpeechResponse; + +// Create a client. +$speechTranslationServiceClient = new SpeechTranslationServiceClient(); + +// Prepare the request message. +$request = new StreamingTranslateSpeechRequest(); + +// Call the API and handle any network failures. +try { + /** @var BidiStream $stream */ + $stream = $speechTranslationServiceClient->streamingTranslateSpeech(); + $stream->writeAll([$request,]); + + /** @var StreamingTranslateSpeechResponse $element */ + foreach ($stream->closeWriteAndReadAll() as $element) { + printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString()); + } +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Memcache/README.md b/Memcache/README.md index e4695f07c796..5ef21b2337e6 100644 --- a/Memcache/README.md +++ b/Memcache/README.md @@ -31,17 +31,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Memcache\V1\CloudMemcacheClient; - -$client = new CloudMemcacheClient(); -$location = CloudMemcacheClient::locationName('[MY_PROJECT_ID]', '-'); - -foreach ($client->listInstances($location) as $response) { - foreach ($response->getResources() as $instance) { - printf('Discovered instance: %s', $instance->getDisplayName()); - } +use Google\ApiCore\ApiException; +use Google\Cloud\Memcache\V1\Client\CloudMemcacheClient; +use Google\Cloud\Memcache\V1\GetInstanceRequest; +use Google\Cloud\Memcache\V1\Instance; + +// Create a client. +$cloudMemcacheClient = new CloudMemcacheClient(); + +// Prepare the request message. +$request = (new GetInstanceRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Instance $response */ + $response = $cloudMemcacheClient->getInstance($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/Memorystore/README.md b/Memorystore/README.md index f7ded83ba871..d4708b72d64c 100644 --- a/Memorystore/README.md +++ b/Memorystore/README.md @@ -35,22 +35,22 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\Memorystore\V1\Backup; +use Google\Cloud\Memorystore\V1\Client\MemorystoreClient; +use Google\Cloud\Memorystore\V1\GetBackupRequest; // Create a client. $memorystoreClient = new MemorystoreClient(); // Prepare the request message. -$request = (new GetCertificateAuthorityRequest()) +$request = (new GetBackupRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { - /** @var CertificateAuthority $response */ - $response = $memorystoreClient->getCertificateAuthority($request); + /** @var Backup $response */ + $response = $memorystoreClient->getBackup($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/MigrationCenter/README.md b/MigrationCenter/README.md index a2929e93e267..bc72f67cbe34 100644 --- a/MigrationCenter/README.md +++ b/MigrationCenter/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\MigrationCenter\V1\Asset; +use Google\Cloud\MigrationCenter\V1\Client\MigrationCenterClient; +use Google\Cloud\MigrationCenter\V1\GetAssetRequest; // Create a client. $migrationCenterClient = new MigrationCenterClient(); diff --git a/ModelArmor/README.md b/ModelArmor/README.md index c8275bf113c4..78647c399571 100644 --- a/ModelArmor/README.md +++ b/ModelArmor/README.md @@ -35,10 +35,10 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -Google\ApiCore\ApiException; -Google\Cloud\ModelArmor\V1\Client\ModelArmorClient; -Google\Cloud\ModelArmor\V1\FloorSetting; -Google\Cloud\ModelArmor\V1\GetFloorSettingRequest; +use Google\ApiCore\ApiException; +use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient; +use Google\Cloud\ModelArmor\V1\FloorSetting; +use Google\Cloud\ModelArmor\V1\GetFloorSettingRequest; // Create a client. $modelArmorClient = new ModelArmorClient(); diff --git a/Monitoring/README.md b/Monitoring/README.md index 3b59cce93acf..8aa53d65309e 100644 --- a/Monitoring/README.md +++ b/Monitoring/README.md @@ -31,54 +31,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -use Google\Api\Metric; -use Google\Api\MonitoredResource; -use Google\Cloud\Monitoring\V3\MetricServiceClient; -use Google\Cloud\Monitoring\V3\Point; -use Google\Cloud\Monitoring\V3\TimeInterval; -use Google\Cloud\Monitoring\V3\TimeSeries; -use Google\Cloud\Monitoring\V3\TypedValue; -use Google\Protobuf\Timestamp; - -$metricServiceClient = new MetricServiceClient(); -$formattedProjectName = $metricServiceClient->projectName($projectId); -$labels = [ - 'instance_id' => $instanceId, - 'zone' => $zone, -]; - -$m = new Metric(); -$m->setType('custom.googleapis.com/my_metric'); - -$r = new MonitoredResource(); -$r->setType('gce_instance'); -$r->setLabels($labels); - -$value = new TypedValue(); -$value->setDoubleValue(3.14); - -$timestamp = new Timestamp(); -$timestamp->setSeconds(time()); - -$interval = new TimeInterval(); -$interval->setStartTime($timestamp); -$interval->setEndTime($timestamp); - -$point = new Point(); -$point->setValue($value); -$point->setInterval($interval); -$points = [$point]; - -$timeSeries = new TimeSeries(); -$timeSeries->setMetric($m); -$timeSeries->setResource($r); -$timeSeries->setPoints($points); +use Google\ApiCore\ApiException; +use Google\Cloud\Monitoring\V3\AlertPolicy; +use Google\Cloud\Monitoring\V3\Client\AlertPolicyServiceClient; +use Google\Cloud\Monitoring\V3\GetAlertPolicyRequest; +// Create a client. +$alertPolicyServiceClient = new AlertPolicyServiceClient(); + +// Prepare the request message. +$request = (new GetAlertPolicyRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. try { - $metricServiceClient->createTimeSeries($formattedProjectName, [$timeSeries]); - print('Successfully submitted a time series' . PHP_EOL); -} finally { - $metricServiceClient->close(); + /** @var AlertPolicy $response */ + $response = $alertPolicyServiceClient->getAlertPolicy($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/NetApp/README.md b/NetApp/README.md index c2141b61543e..85b320c5bd5f 100644 --- a/NetApp/README.md +++ b/NetApp/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\NetApp\V1\ActiveDirectory; +use Google\Cloud\NetApp\V1\Client\NetAppClient; +use Google\Cloud\NetApp\V1\GetActiveDirectoryRequest; // Create a client. $netAppClient = new NetAppClient(); diff --git a/NetworkConnectivity/README.md b/NetworkConnectivity/README.md index 3bf0f5208081..1c0221b7fa15 100644 --- a/NetworkConnectivity/README.md +++ b/NetworkConnectivity/README.md @@ -28,6 +28,30 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Location\GetLocationRequest; +use Google\Cloud\Location\Location; +use Google\Cloud\NetworkConnectivity\V1\Client\CrossNetworkAutomationServiceClient; + +// Create a client. +$crossNetworkAutomationServiceClient = new CrossNetworkAutomationServiceClient(); + +// Prepare the request message. +$request = new GetLocationRequest(); + +// Call the API and handle any network failures. +try { + /** @var Location $response */ + $response = $crossNetworkAutomationServiceClient->getLocation($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/NetworkManagement/README.md b/NetworkManagement/README.md index 62a8c3a6c581..190cca1f4523 100644 --- a/NetworkManagement/README.md +++ b/NetworkManagement/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\NetworkManagement\V1\Client\ReachabilityServiceClient; +use Google\Cloud\NetworkManagement\V1\ConnectivityTest; +use Google\Cloud\NetworkManagement\V1\GetConnectivityTestRequest; + +// Create a client. +$reachabilityServiceClient = new ReachabilityServiceClient(); + +// Prepare the request message. +$request = (new GetConnectivityTestRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var ConnectivityTest $response */ + $response = $reachabilityServiceClient->getConnectivityTest($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/NetworkSecurity/README.md b/NetworkSecurity/README.md index 4729e0227c18..c8424a90a189 100644 --- a/NetworkSecurity/README.md +++ b/NetworkSecurity/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\NetworkSecurity\V1\AuthorizationPolicy; +use Google\Cloud\NetworkSecurity\V1\Client\NetworkSecurityClient; +use Google\Cloud\NetworkSecurity\V1\GetAuthorizationPolicyRequest; + +// Create a client. +$networkSecurityClient = new NetworkSecurityClient(); + +// Prepare the request message. +$request = (new GetAuthorizationPolicyRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var AuthorizationPolicy $response */ + $response = $networkSecurityClient->getAuthorizationPolicy($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/NetworkServices/README.md b/NetworkServices/README.md index 2bc1f68294fe..56789cd77e75 100644 --- a/NetworkServices/README.md +++ b/NetworkServices/README.md @@ -35,22 +35,22 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\NetworkServices\V1\AuthzExtension; +use Google\Cloud\NetworkServices\V1\Client\DepServiceClient; +use Google\Cloud\NetworkServices\V1\GetAuthzExtensionRequest; // Create a client. $depServiceClient = new DepServiceClient(); // Prepare the request message. -$request = (new GetLbRouteExtensionRequest()) +$request = (new GetAuthzExtensionRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { - /** @var LbRouteExtension $response */ - $response = $depServiceClient->getLbRouteExtension($request); + /** @var AuthzExtension $response */ + $response = $depServiceClient->getAuthzExtension($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/Notebooks/README.md b/Notebooks/README.md index 07d437581f41..54e24083bb12 100644 --- a/Notebooks/README.md +++ b/Notebooks/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Notebooks\V2\Client\NotebookServiceClient; +use Google\Cloud\Notebooks\V2\GetInstanceRequest; +use Google\Cloud\Notebooks\V2\Instance; + +// Create a client. +$notebookServiceClient = new NotebookServiceClient(); + +// Prepare the request message. +$request = (new GetInstanceRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Instance $response */ + $response = $notebookServiceClient->getInstance($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Optimization/README.md b/Optimization/README.md index badd51f62522..8ea62c27841f 100644 --- a/Optimization/README.md +++ b/Optimization/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Optimization\V1\Client\FleetRoutingClient; +use Google\Cloud\Optimization\V1\OptimizeToursRequest; +use Google\Cloud\Optimization\V1\OptimizeToursResponse; + +// Create a client. +$fleetRoutingClient = new FleetRoutingClient(); + +// Prepare the request message. +$request = (new OptimizeToursRequest()) + ->setParent($parent); + +// Call the API and handle any network failures. +try { + /** @var OptimizeToursResponse $response */ + $response = $fleetRoutingClient->optimizeTours($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/OracleDatabase/README.md b/OracleDatabase/README.md index b65427d514c4..a66e52c167bf 100644 --- a/OracleDatabase/README.md +++ b/OracleDatabase/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\OracleDatabase\V1\AutonomousDatabase; +use Google\Cloud\OracleDatabase\V1\Client\OracleDatabaseClient; +use Google\Cloud\OracleDatabase\V1\GetAutonomousDatabaseRequest; // Create a client. $oracleDatabaseClient = new OracleDatabaseClient(); diff --git a/OrchestrationAirflow/README.md b/OrchestrationAirflow/README.md index e8ac627aed1d..10183e897e0a 100644 --- a/OrchestrationAirflow/README.md +++ b/OrchestrationAirflow/README.md @@ -28,6 +28,30 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Orchestration\Airflow\Service\V1\Client\EnvironmentsClient; +use Google\Cloud\Orchestration\Airflow\Service\V1\Environment; +use Google\Cloud\Orchestration\Airflow\Service\V1\GetEnvironmentRequest; + +// Create a client. +$environmentsClient = new EnvironmentsClient(); + +// Prepare the request message. +$request = new GetEnvironmentRequest(); + +// Call the API and handle any network failures. +try { + /** @var Environment $response */ + $response = $environmentsClient->getEnvironment($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/OrgPolicy/README.md b/OrgPolicy/README.md index c86c21c1fd35..f5cb90127fe6 100644 --- a/OrgPolicy/README.md +++ b/OrgPolicy/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\OrgPolicy\V2\Client\OrgPolicyClient; +use Google\Cloud\OrgPolicy\V2\CustomConstraint; +use Google\Cloud\OrgPolicy\V2\GetCustomConstraintRequest; + +// Create a client. +$orgPolicyClient = new OrgPolicyClient(); + +// Prepare the request message. +$request = (new GetCustomConstraintRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var CustomConstraint $response */ + $response = $orgPolicyClient->getCustomConstraint($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/OsConfig/README.md b/OsConfig/README.md index b940e2e857ff..b944afbaa6af 100644 --- a/OsConfig/README.md +++ b/OsConfig/README.md @@ -31,18 +31,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\OsConfig\V1\OsConfigServiceClient; - -$client = new OsConfigServiceClient(); - -$jobs = $client->listPatchJobs( - OsConfigServiceClient::projectName('[MY_PROJECT_ID]') -); - -foreach ($jobs as $job) { - print $job->getName() . ': ' . $job->getDescription() . PHP_EOL; +use Google\ApiCore\ApiException; +use Google\Cloud\OsConfig\V1\Client\OsConfigServiceClient; +use Google\Cloud\OsConfig\V1\GetPatchDeploymentRequest; +use Google\Cloud\OsConfig\V1\PatchDeployment; + +// Create a client. +$osConfigServiceClient = new OsConfigServiceClient(); + +// Prepare the request message. +$request = (new GetPatchDeploymentRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var PatchDeployment $response */ + $response = $osConfigServiceClient->getPatchDeployment($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/OsLogin/README.md b/OsLogin/README.md index 34999794690c..0d0bef6fad47 100644 --- a/OsLogin/README.md +++ b/OsLogin/README.md @@ -34,14 +34,26 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\OsLogin\V1\OsLoginServiceClient; +use Google\ApiCore\ApiException; +use Google\Cloud\OsLogin\V1\Client\OsLoginServiceClient; +use Google\Cloud\OsLogin\V1\GetLoginProfileRequest; +use Google\Cloud\OsLogin\V1\LoginProfile; +// Create a client. $osLoginServiceClient = new OsLoginServiceClient(); -$userId = '[MY_USER_ID]'; -$formattedName = $osLoginServiceClient->userName($userId); -$loginProfile = $osLoginServiceClient->getLoginProfile($formattedName); + +// Prepare the request message. +$request = (new GetLoginProfileRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var LoginProfile $response */ + $response = $osLoginServiceClient->getLoginProfile($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} ``` ### Debugging diff --git a/Parallelstore/README.md b/Parallelstore/README.md index 425de3129692..c3c6ccadb9a3 100644 --- a/Parallelstore/README.md +++ b/Parallelstore/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\Parallelstore\V1\Client\ParallelstoreClient; +use Google\Cloud\Parallelstore\V1\GetInstanceRequest; +use Google\Cloud\Parallelstore\V1\Instance; // Create a client. $parallelstoreClient = new ParallelstoreClient(); diff --git a/ParameterManager/README.md b/ParameterManager/README.md index 4a139d869a16..23dcfbb5d6c4 100644 --- a/ParameterManager/README.md +++ b/ParameterManager/README.md @@ -35,10 +35,10 @@ 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\ParameterManager\V1\Client\ParameterManagerClient; +use Google\ApiCore\ApiException; +use Google\Cloud\Location\GetLocationRequest; +use Google\Cloud\Location\Location; +use Google\Cloud\ParameterManager\V1\Client\ParameterManagerClient; // Create a client. $parameterManagerClient = new ParameterManagerClient(); diff --git a/PolicySimulator/README.md b/PolicySimulator/README.md index 98438432fefa..aa7f7181b7a2 100644 --- a/PolicySimulator/README.md +++ b/PolicySimulator/README.md @@ -35,22 +35,22 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\PolicySimulator\V1\Client\OrgPolicyViolationsPreviewServiceClient; +use Google\Cloud\PolicySimulator\V1\GetOrgPolicyViolationsPreviewRequest; +use Google\Cloud\PolicySimulator\V1\OrgPolicyViolationsPreview; // Create a client. -$simulatorClient = new SimulatorClient(); +$orgPolicyViolationsPreviewServiceClient = new OrgPolicyViolationsPreviewServiceClient(); // Prepare the request message. -$request = (new GetReplayRequest()) +$request = (new GetOrgPolicyViolationsPreviewRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { - /** @var Replay $response */ - $response = $simulatorClient->getReplay($request); + /** @var OrgPolicyViolationsPreview $response */ + $response = $orgPolicyViolationsPreviewServiceClient->getOrgPolicyViolationsPreview($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/PolicyTroubleshooter/README.md b/PolicyTroubleshooter/README.md index 03d040b1834f..a8f43a1ee796 100644 --- a/PolicyTroubleshooter/README.md +++ b/PolicyTroubleshooter/README.md @@ -28,6 +28,30 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\PolicyTroubleshooter\V1\Client\IamCheckerClient; +use Google\Cloud\PolicyTroubleshooter\V1\TroubleshootIamPolicyRequest; +use Google\Cloud\PolicyTroubleshooter\V1\TroubleshootIamPolicyResponse; + +// Create a client. +$iamCheckerClient = new IamCheckerClient(); + +// Prepare the request message. +$request = new TroubleshootIamPolicyRequest(); + +// Call the API and handle any network failures. +try { + /** @var TroubleshootIamPolicyResponse $response */ + $response = $iamCheckerClient->troubleshootIamPolicy($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/PolicyTroubleshooterIam/README.md b/PolicyTroubleshooterIam/README.md index 23216b51c816..262c4366eb6a 100644 --- a/PolicyTroubleshooterIam/README.md +++ b/PolicyTroubleshooterIam/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\PolicyTroubleshooter\Iam\V3\Client\PolicyTroubleshooterClient; +use Google\Cloud\PolicyTroubleshooter\Iam\V3\TroubleshootIamPolicyRequest; +use Google\Cloud\PolicyTroubleshooter\Iam\V3\TroubleshootIamPolicyResponse; // Create a client. $policyTroubleshooterClient = new PolicyTroubleshooterClient(); diff --git a/PrivateCatalog/README.md b/PrivateCatalog/README.md index 61be005f9d4a..355dce06b3b9 100644 --- a/PrivateCatalog/README.md +++ b/PrivateCatalog/README.md @@ -28,6 +28,36 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\ApiCore\PagedListResponse; +use Google\Cloud\PrivateCatalog\V1beta1\Client\PrivateCatalogClient; +use Google\Cloud\PrivateCatalog\V1beta1\Product; +use Google\Cloud\PrivateCatalog\V1beta1\SearchProductsRequest; + +// Create a client. +$privateCatalogClient = new PrivateCatalogClient(); + +// Prepare the request message. +$request = (new SearchProductsRequest()) + ->setResource($resource); + +// Call the API and handle any network failures. +try { + /** @var PagedListResponse $response */ + $response = $privateCatalogClient->searchProducts($request); + + /** @var Product $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()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/PrivilegedAccessManager/README.md b/PrivilegedAccessManager/README.md index 88d6519890d2..340bab2210c5 100644 --- a/PrivilegedAccessManager/README.md +++ b/PrivilegedAccessManager/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\PrivilegedAccessManager\V1\Client\PrivilegedAccessManagerClient; +use Google\Cloud\PrivilegedAccessManager\V1\Entitlement; +use Google\Cloud\PrivilegedAccessManager\V1\GetEntitlementRequest; // Create a client. $privilegedAccessManagerClient = new PrivilegedAccessManagerClient(); diff --git a/Profiler/README.md b/Profiler/README.md index 6a9a1cafb080..55222aff9007 100644 --- a/Profiler/README.md +++ b/Profiler/README.md @@ -28,6 +28,30 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Profiler\V2\Client\ProfilerServiceClient; +use Google\Cloud\Profiler\V2\CreateOfflineProfileRequest; +use Google\Cloud\Profiler\V2\Profile; + +// Create a client. +$profilerServiceClient = new ProfilerServiceClient(); + +// Prepare the request message. +$request = new CreateOfflineProfileRequest(); + +// Call the API and handle any network failures. +try { + /** @var Profile $response */ + $response = $profilerServiceClient->createOfflineProfile($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/PubSub/README.md b/PubSub/README.md index 4e3ed2afb876..7de0bd43f4bd 100644 --- a/PubSub/README.md +++ b/PubSub/README.md @@ -33,32 +33,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\PubSub\PubSubClient; - -$pubSub = new PubSubClient(); - -// Get an instance of a previously created topic. -$topic = $pubSub->topic('my_topic'); - -// Publish a message to the topic. -$topic->publish([ - 'data' => 'My new message.', - 'attributes' => [ - 'location' => 'Detroit' - ] -]); - -// Get an instance of a previously created subscription. -$subscription = $pubSub->subscription('my_subscription'); - -// Pull all available messages. -$messages = $subscription->pull(); - -foreach ($messages as $message) { - echo $message->data() . "\n"; - echo $message->attribute('location'); +use Google\ApiCore\ApiException; +use Google\Cloud\PubSub\V1\Client\PublisherClient; +use Google\Cloud\PubSub\V1\GetTopicRequest; +use Google\Cloud\PubSub\V1\Topic; + +// Create a client. +$publisherClient = new PublisherClient(); + +// Prepare the request message. +$request = (new GetTopicRequest()) + ->setTopic($formattedTopic); + +// Call the API and handle any network failures. +try { + /** @var Topic $response */ + $response = $publisherClient->getTopic($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/Quotas/README.md b/Quotas/README.md index e300d5c57bfe..b45199de5007 100644 --- a/Quotas/README.md +++ b/Quotas/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\CloudQuotas\V1\Client\CloudQuotasClient; +use Google\Cloud\CloudQuotas\V1\GetQuotaInfoRequest; +use Google\Cloud\CloudQuotas\V1\QuotaInfo; // Create a client. $cloudQuotasClient = new CloudQuotasClient(); diff --git a/RapidMigrationAssessment/README.md b/RapidMigrationAssessment/README.md index 7c3c2855bcf8..3df6751e3206 100644 --- a/RapidMigrationAssessment/README.md +++ b/RapidMigrationAssessment/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\RapidMigrationAssessment\V1\Annotation; +use Google\Cloud\RapidMigrationAssessment\V1\Client\RapidMigrationAssessmentClient; +use Google\Cloud\RapidMigrationAssessment\V1\GetAnnotationRequest; // Create a client. $rapidMigrationAssessmentClient = new RapidMigrationAssessmentClient(); diff --git a/RecaptchaEnterprise/README.md b/RecaptchaEnterprise/README.md index e8d30a07be5c..8c168522729d 100644 --- a/RecaptchaEnterprise/README.md +++ b/RecaptchaEnterprise/README.md @@ -31,39 +31,23 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - use Google\ApiCore\ApiException; use Google\Cloud\RecaptchaEnterprise\V1\Client\RecaptchaEnterpriseServiceClient; -use Google\Cloud\RecaptchaEnterprise\V1\CreateKeyRequest; -use Google\Cloud\RecaptchaEnterprise\V1\Key; -use Google\Cloud\RecaptchaEnterprise\V1\WebKeySettings; -use Google\Cloud\RecaptchaEnterprise\V1\WebKeySettings\IntegrationType; - -$formattedParent = RecaptchaEnterpriseServiceClient::projectName('[PROJECT]'); -$keyDisplayName = '[DISPLAY_NAME]'; +use Google\Cloud\RecaptchaEnterprise\V1\FirewallPolicy; +use Google\Cloud\RecaptchaEnterprise\V1\GetFirewallPolicyRequest; // Create a client. $recaptchaEnterpriseServiceClient = new RecaptchaEnterpriseServiceClient(); // Prepare the request message. -$webKeySettings = (new WebKeySettings()) - ->setAllowedDomains(['example.com']) - ->setAllowAmpTraffic(false) - ->setIntegrationType(IntegrationType::CHECKBOX); -$key = (new Key()) - ->setWebSettings($webKeySettings) - ->setDisplayName($keyDisplayName) - ->setName('my_key'); -$request = (new CreateKeyRequest()) - ->setParent($formattedParent) - ->setKey($key); +$request = (new GetFirewallPolicyRequest()) + ->setName($formattedName); // Call the API and handle any network failures. try { - /** @var Key $response */ - $response = $recaptchaEnterpriseServiceClient->createKey($request); - printf('Created key: %s' . PHP_EOL, $response->getName()); + /** @var FirewallPolicy $response */ + $response = $recaptchaEnterpriseServiceClient->getFirewallPolicy($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } diff --git a/RecommendationEngine/README.md b/RecommendationEngine/README.md index c856e3758c59..1eb159d3830a 100644 --- a/RecommendationEngine/README.md +++ b/RecommendationEngine/README.md @@ -31,20 +31,26 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -use Google\Cloud\RecommendationEngine\V1beta1\PredictionServiceClient; -use Google\Cloud\RecommendationEngine\V1beta1\UserEvent; - -$client = new PredictionServiceClient(); -$formattedName = $predictionServiceClient->placementName( - '[PROJECT]', - '[LOCATION]', - '[CATALOG]', - '[EVENT_STORE]', - '[PLACEMENT]' -); -$userEvent = new UserEvent(); - -$predictions = $predictionServiceClient->predict($formattedName, $userEvent); +use Google\ApiCore\ApiException; +use Google\Cloud\RecommendationEngine\V1beta1\CatalogItem; +use Google\Cloud\RecommendationEngine\V1beta1\Client\CatalogServiceClient; +use Google\Cloud\RecommendationEngine\V1beta1\GetCatalogItemRequest; + +// Create a client. +$catalogServiceClient = new CatalogServiceClient(); + +// Prepare the request message. +$request = (new GetCatalogItemRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var CatalogItem $response */ + $response = $catalogServiceClient->getCatalogItem($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} ``` ### Debugging diff --git a/Recommender/README.md b/Recommender/README.md index b79fbe20bcc7..ee31287f36ba 100644 --- a/Recommender/README.md +++ b/Recommender/README.md @@ -31,25 +31,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Recommender\V1\RecommenderClient; - -$client = new RecommenderClient(); - -$recommendations = $client->listRecommendations( - RecommenderClient::recommenderName( - '[MY_PROJECT_ID]', - 'us-central1', - 'google.compute.instance.MachineTypeRecommender' - ) -); - -foreach ($recommendations as $recommendation) { - printf( - 'Found recommendation: %s' . PHP_EOL, - $recommendation->getName() - ); +use Google\ApiCore\ApiException; +use Google\Cloud\Recommender\V1\Client\RecommenderClient; +use Google\Cloud\Recommender\V1\GetInsightRequest; +use Google\Cloud\Recommender\V1\Insight; + +// Create a client. +$recommenderClient = new RecommenderClient(); + +// Prepare the request message. +$request = (new GetInsightRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Insight $response */ + $response = $recommenderClient->getInsight($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/Redis/README.md b/Redis/README.md index 68d1b6673bbf..be5f963c3011 100644 --- a/Redis/README.md +++ b/Redis/README.md @@ -34,21 +34,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Redis\V1\CloudRedisClient; - -$client = new CloudRedisClient(); - -$projectId = '[MY_PROJECT_ID]'; -$location = '-'; // The '-' wildcard refers to all regions available to the project for the listInstances method -$formattedLocationName = $client->locationName($projectId, $location); -$response = $client->listInstances($formattedLocationName); -foreach ($response->iterateAllElements() as $instance) { - printf('Instance: %s : %s' . PHP_EOL, - $instance->getDisplayName(), - $instance->getName() - ); +use Google\ApiCore\ApiException; +use Google\Cloud\Redis\V1\Client\CloudRedisClient; +use Google\Cloud\Redis\V1\GetInstanceRequest; +use Google\Cloud\Redis\V1\Instance; + +// Create a client. +$cloudRedisClient = new CloudRedisClient(); + +// Prepare the request message. +$request = (new GetInstanceRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Instance $response */ + $response = $cloudRedisClient->getInstance($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/RedisCluster/README.md b/RedisCluster/README.md index 13b6abe16283..a549a48060f6 100644 --- a/RedisCluster/README.md +++ b/RedisCluster/README.md @@ -35,22 +35,22 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\Redis\Cluster\V1\Backup; +use Google\Cloud\Redis\Cluster\V1\Client\CloudRedisClusterClient; +use Google\Cloud\Redis\Cluster\V1\GetBackupRequest; // Create a client. $cloudRedisClusterClient = new CloudRedisClusterClient(); // Prepare the request message. -$request = (new GetClusterRequest()) +$request = (new GetBackupRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { - /** @var Cluster $response */ - $response = $cloudRedisClusterClient->getCluster($request); + /** @var Backup $response */ + $response = $cloudRedisClusterClient->getBackup($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ResourceManager/README.md b/ResourceManager/README.md index 719c2df36551..333a6995b033 100644 --- a/ResourceManager/README.md +++ b/ResourceManager/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\ResourceManager\V3\Client\FoldersClient; +use Google\Cloud\ResourceManager\V3\Folder; +use Google\Cloud\ResourceManager\V3\GetFolderRequest; + +// Create a client. +$foldersClient = new FoldersClient(); + +// Prepare the request message. +$request = (new GetFolderRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Folder $response */ + $response = $foldersClient->getFolder($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Retail/README.md b/Retail/README.md index 31f6d37c9ef3..ea2fc6195641 100644 --- a/Retail/README.md +++ b/Retail/README.md @@ -31,18 +31,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Retail\V2\CatalogServiceClient; - -$client = new CatalogServiceClient(); - -$catalogs = $client->listCatalogs( - CatalogServiceClient::locationName('[MY_PROJECT_ID]', 'global') -); - -foreach ($catalogs as $catalog) { - print 'Catalog: ' . $catalog->getName() . PHP_EOL; +use Google\ApiCore\ApiException; +use Google\Cloud\Retail\V2\AttributesConfig; +use Google\Cloud\Retail\V2\Client\CatalogServiceClient; +use Google\Cloud\Retail\V2\GetAttributesConfigRequest; + +// Create a client. +$catalogServiceClient = new CatalogServiceClient(); + +// Prepare the request message. +$request = (new GetAttributesConfigRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var AttributesConfig $response */ + $response = $catalogServiceClient->getAttributesConfig($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/Run/README.md b/Run/README.md index 0fea7de30293..e0e08c3d3407 100644 --- a/Run/README.md +++ b/Run/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Run\V2\Client\ExecutionsClient; +use Google\Cloud\Run\V2\Execution; +use Google\Cloud\Run\V2\GetExecutionRequest; + +// Create a client. +$executionsClient = new ExecutionsClient(); + +// Prepare the request message. +$request = (new GetExecutionRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Execution $response */ + $response = $executionsClient->getExecution($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Scheduler/README.md b/Scheduler/README.md index 2c80b09a0d97..259dd1df2e5f 100644 --- a/Scheduler/README.md +++ b/Scheduler/README.md @@ -31,36 +31,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Scheduler\V1\AppEngineHttpTarget; -use Google\Cloud\Scheduler\V1\CloudSchedulerClient; +use Google\ApiCore\ApiException; +use Google\Cloud\Scheduler\V1\Client\CloudSchedulerClient; +use Google\Cloud\Scheduler\V1\GetJobRequest; use Google\Cloud\Scheduler\V1\Job; -use Google\Cloud\Scheduler\V1\Job\State; - -$client = new CloudSchedulerClient(); -$projectId = '[MY_PROJECT_ID]'; -$location = 'us-central1'; -$parent = CloudSchedulerClient::locationName($projectId, $location); -$job = new Job([ - 'name' => CloudSchedulerClient::jobName( - $projectId, - $location, - uniqid() - ), - 'app_engine_http_target' => new AppEngineHttpTarget([ - 'relative_uri' => '/' - ]), - 'schedule' => '* * * * *' -]); -$client->createJob($parent, $job); - -foreach ($client->listJobs($parent) as $job) { - printf( - 'Job: %s : %s' . PHP_EOL, - $job->getName(), - State::name($job->getState()) - ); + +// Create a client. +$cloudSchedulerClient = new CloudSchedulerClient(); + +// Prepare the request message. +$request = (new GetJobRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Job $response */ + $response = $cloudSchedulerClient->getJob($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/SecretManager/README.md b/SecretManager/README.md index dab5f064a50e..7e8d794d2b3b 100644 --- a/SecretManager/README.md +++ b/SecretManager/README.md @@ -31,29 +31,26 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\SecretManager\V1\Replication; -use Google\Cloud\SecretManager\V1\Replication\Automatic; +use Google\ApiCore\ApiException; +use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient; +use Google\Cloud\SecretManager\V1\GetSecretRequest; use Google\Cloud\SecretManager\V1\Secret; -use Google\Cloud\SecretManager\V1\SecretManagerServiceClient; - -$client = new SecretManagerServiceClient(); - -$secret = $client->createSecret( - SecretManagerServiceClient::projectName('[MY_PROJECT_ID]'), - '[MY_SECRET_ID]', - new Secret([ - 'replication' => new Replication([ - 'automatic' => new Automatic() - ]) - ]) -); - -printf( - 'Created secret: %s' . PHP_EOL, - $secret->getName() -); + +// Create a client. +$secretManagerServiceClient = new SecretManagerServiceClient(); + +// Prepare the request message. +$request = (new GetSecretRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Secret $response */ + $response = $secretManagerServiceClient->getSecret($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} ``` ### Debugging diff --git a/SecureSourceManager/README.md b/SecureSourceManager/README.md index 0e45d3fff312..a7b59ab892e4 100644 --- a/SecureSourceManager/README.md +++ b/SecureSourceManager/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\SecureSourceManager\V1\BranchRule; +use Google\Cloud\SecureSourceManager\V1\Client\SecureSourceManagerClient; +use Google\Cloud\SecureSourceManager\V1\GetBranchRuleRequest; // Create a client. $secureSourceManagerClient = new SecureSourceManagerClient(); diff --git a/SecurityCenter/README.md b/SecurityCenter/README.md index 332c3f5c2173..c6ca2f48614c 100644 --- a/SecurityCenter/README.md +++ b/SecurityCenter/README.md @@ -28,17 +28,26 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -use Google\Cloud\SecurityCenter\V1\SecurityCenterClient; -use Google\Cloud\SecurityCenter\V1\Source; - -$security = new SecurityCenterClient(); -$parent = SecurityCenterClient::organizationName('[YOUR ORGANIZATION]'); -$source = new Source([ - 'name' => SecurityCenterClient::sourceName('[YOUR ORGANIZATION]', '[YOUR SOURCE]'), - 'displayName' => '[YOUR SOURCE]' -]); - -$res = $security->createSource($parent, $source); +use Google\ApiCore\ApiException; +use Google\Cloud\SecurityCenter\V2\BigQueryExport; +use Google\Cloud\SecurityCenter\V2\Client\SecurityCenterClient; +use Google\Cloud\SecurityCenter\V2\GetBigQueryExportRequest; + +// Create a client. +$securityCenterClient = new SecurityCenterClient(); + +// Prepare the request message. +$request = (new GetBigQueryExportRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var BigQueryExport $response */ + $response = $securityCenterClient->getBigQueryExport($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} ``` ### Debugging diff --git a/SecurityCenterManagement/README.md b/SecurityCenterManagement/README.md index f202c4501ecd..3c201f0f8ce5 100644 --- a/SecurityCenterManagement/README.md +++ b/SecurityCenterManagement/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\SecurityCenterManagement\V1\Client\SecurityCenterManagementClient; +use Google\Cloud\SecurityCenterManagement\V1\EffectiveEventThreatDetectionCustomModule; +use Google\Cloud\SecurityCenterManagement\V1\GetEffectiveEventThreatDetectionCustomModuleRequest; // Create a client. $securityCenterManagementClient = new SecurityCenterManagementClient(); diff --git a/SecurityPrivateCa/README.md b/SecurityPrivateCa/README.md index 8f31a6b69caf..6514650b6400 100644 --- a/SecurityPrivateCa/README.md +++ b/SecurityPrivateCa/README.md @@ -31,22 +31,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Security\PrivateCA\V1\CertificateAuthorityServiceClient; - -$client = new CertificateAuthorityServiceClient(); - -$parent = CertificateAuthorityServiceClient::locationName( - '[MY_PROJECT]', - 'us-west1', -); -$authorities = $client->listCertificateAuthorities( - $parent, -); - -foreach ($authorities as $authority) { - print 'Found authority: ' . $authority->getName() . PHP_EOL; +use Google\ApiCore\ApiException; +use Google\Cloud\Security\PrivateCA\V1\CaPool; +use Google\Cloud\Security\PrivateCA\V1\Client\CertificateAuthorityServiceClient; +use Google\Cloud\Security\PrivateCA\V1\GetCaPoolRequest; + +// Create a client. +$certificateAuthorityServiceClient = new CertificateAuthorityServiceClient(); + +// Prepare the request message. +$request = (new GetCaPoolRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var CaPool $response */ + $response = $certificateAuthorityServiceClient->getCaPool($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/SecurityPublicCA/README.md b/SecurityPublicCA/README.md index c7b82072c1ab..9459a240a3af 100644 --- a/SecurityPublicCA/README.md +++ b/SecurityPublicCA/README.md @@ -28,6 +28,33 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Security\PublicCA\V1\Client\PublicCertificateAuthorityServiceClient; +use Google\Cloud\Security\PublicCA\V1\CreateExternalAccountKeyRequest; +use Google\Cloud\Security\PublicCA\V1\ExternalAccountKey; + +// Create a client. +$publicCertificateAuthorityServiceClient = new PublicCertificateAuthorityServiceClient(); + +// Prepare the request message. +$externalAccountKey = new ExternalAccountKey(); +$request = (new CreateExternalAccountKeyRequest()) + ->setParent($formattedParent) + ->setExternalAccountKey($externalAccountKey); + +// Call the API and handle any network failures. +try { + /** @var ExternalAccountKey $response */ + $response = $publicCertificateAuthorityServiceClient->createExternalAccountKey($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/ServiceControl/README.md b/ServiceControl/README.md index 5b75fc9c4885..cccfc2665d65 100644 --- a/ServiceControl/README.md +++ b/ServiceControl/README.md @@ -28,6 +28,30 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\ServiceControl\V1\AllocateQuotaRequest; +use Google\Cloud\ServiceControl\V1\AllocateQuotaResponse; +use Google\Cloud\ServiceControl\V1\Client\QuotaControllerClient; + +// Create a client. +$quotaControllerClient = new QuotaControllerClient(); + +// Prepare the request message. +$request = new AllocateQuotaRequest(); + +// Call the API and handle any network failures. +try { + /** @var AllocateQuotaResponse $response */ + $response = $quotaControllerClient->allocateQuota($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/ServiceDirectory/README.md b/ServiceDirectory/README.md index a03d7345203b..ad8a6b8ed72d 100644 --- a/ServiceDirectory/README.md +++ b/ServiceDirectory/README.md @@ -31,32 +31,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\ServiceDirectory\V1\RegistrationServiceClient; -use Google\Cloud\ServiceDirectory\V1\Service; - -$client = new RegistrationServiceClient(); - -$projectId = '[YOUR_PROJECT_ID]'; -$location = 'us-central1'; -$serviceId = '[YOUR_SERVICE_ID]'; -$namespace = '[YOUR_NAMESPACE]'; - -$service = $client->createService( - RegistrationServiceClient::namespaceName( - $projectId, - $location, - $namespace - ), - $serviceId, - new Service() -); - -printf( - 'Created service: %s' . PHP_EOL, - $service->getName() -); +use Google\ApiCore\ApiException; +use Google\Cloud\Location\GetLocationRequest; +use Google\Cloud\Location\Location; +use Google\Cloud\ServiceDirectory\V1\Client\LookupServiceClient; + +// Create a client. +$lookupServiceClient = new LookupServiceClient(); + +// Prepare the request message. +$request = new GetLocationRequest(); + +// Call the API and handle any network failures. +try { + /** @var Location $response */ + $response = $lookupServiceClient->getLocation($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} ``` ### Debugging diff --git a/ServiceHealth/README.md b/ServiceHealth/README.md index a5a5c67484de..88d42b87f4b5 100644 --- a/ServiceHealth/README.md +++ b/ServiceHealth/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\ServiceHealth\V1\Client\ServiceHealthClient; +use Google\Cloud\ServiceHealth\V1\Event; +use Google\Cloud\ServiceHealth\V1\GetEventRequest; // Create a client. $serviceHealthClient = new ServiceHealthClient(); diff --git a/ServiceManagement/README.md b/ServiceManagement/README.md index 5ad80d34b621..4821154d4bb6 100644 --- a/ServiceManagement/README.md +++ b/ServiceManagement/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\ServiceManagement\V1\Client\ServiceManagerClient; +use Google\Cloud\ServiceManagement\V1\GetServiceRequest; +use Google\Cloud\ServiceManagement\V1\ManagedService; + +// Create a client. +$serviceManagerClient = new ServiceManagerClient(); + +// Prepare the request message. +$request = (new GetServiceRequest()) + ->setServiceName($serviceName); + +// Call the API and handle any network failures. +try { + /** @var ManagedService $response */ + $response = $serviceManagerClient->getService($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/ServiceUsage/README.md b/ServiceUsage/README.md index 9253fefd9a8f..2c9fd6ba554d 100644 --- a/ServiceUsage/README.md +++ b/ServiceUsage/README.md @@ -28,6 +28,30 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\ServiceUsage\V1\Client\ServiceUsageClient; +use Google\Cloud\ServiceUsage\V1\GetServiceRequest; +use Google\Cloud\ServiceUsage\V1\Service; + +// Create a client. +$serviceUsageClient = new ServiceUsageClient(); + +// Prepare the request message. +$request = new GetServiceRequest(); + +// Call the API and handle any network failures. +try { + /** @var Service $response */ + $response = $serviceUsageClient->getService($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Shell/README.md b/Shell/README.md index 6e05370f32a2..c88971e587a2 100644 --- a/Shell/README.md +++ b/Shell/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Shell\V1\Client\CloudShellServiceClient; +use Google\Cloud\Shell\V1\Environment; +use Google\Cloud\Shell\V1\GetEnvironmentRequest; + +// Create a client. +$cloudShellServiceClient = new CloudShellServiceClient(); + +// Prepare the request message. +$request = (new GetEnvironmentRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Environment $response */ + $response = $cloudShellServiceClient->getEnvironment($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/ShoppingCss/README.md b/ShoppingCss/README.md index 302127c3c39b..5b5e2f39ac10 100644 --- a/ShoppingCss/README.md +++ b/ShoppingCss/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Shopping\Css\V1\Account; +use Google\Shopping\Css\V1\Client\AccountsServiceClient; +use Google\Shopping\Css\V1\GetAccountRequest; // Create a client. $accountsServiceClient = new AccountsServiceClient(); diff --git a/ShoppingMerchantAccounts/README.md b/ShoppingMerchantAccounts/README.md index 2410fe8d173f..386ce8d240c9 100644 --- a/ShoppingMerchantAccounts/README.md +++ b/ShoppingMerchantAccounts/README.md @@ -35,22 +35,22 @@ 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; +use Google\ApiCore\ApiException; +use Google\Shopping\Merchant\Accounts\V1\AccountRelationship; +use Google\Shopping\Merchant\Accounts\V1\Client\AccountRelationshipsServiceClient; +use Google\Shopping\Merchant\Accounts\V1\GetAccountRelationshipRequest; // Create a client. -$accountTaxServiceClient = new AccountTaxServiceClient(); +$accountRelationshipsServiceClient = new AccountRelationshipsServiceClient(); // Prepare the request message. -$request = (new GetAccountTaxRequest()) +$request = (new GetAccountRelationshipRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { - /** @var AccountTax $response */ - $response = $accountTaxServiceClient->getAccountTax($request); + /** @var AccountRelationship $response */ + $response = $accountRelationshipsServiceClient->getAccountRelationship($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ShoppingMerchantConversions/README.md b/ShoppingMerchantConversions/README.md index a47bc9d8cd3d..5d27cc60299c 100644 --- a/ShoppingMerchantConversions/README.md +++ b/ShoppingMerchantConversions/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Shopping\Merchant\Conversions\V1\Client\ConversionSourcesServiceClient; +use Google\Shopping\Merchant\Conversions\V1\ConversionSource; +use Google\Shopping\Merchant\Conversions\V1\GetConversionSourceRequest; // Create a client. $conversionSourcesServiceClient = new ConversionSourcesServiceClient(); diff --git a/ShoppingMerchantDataSources/README.md b/ShoppingMerchantDataSources/README.md index 8112ec1b9f00..8cb6d2134856 100644 --- a/ShoppingMerchantDataSources/README.md +++ b/ShoppingMerchantDataSources/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Shopping\Merchant\DataSources\V1\Client\DataSourcesServiceClient; +use Google\Shopping\Merchant\DataSources\V1\DataSource; +use Google\Shopping\Merchant\DataSources\V1\GetDataSourceRequest; // Create a client. $dataSourcesServiceClient = new DataSourcesServiceClient(); diff --git a/ShoppingMerchantInventories/README.md b/ShoppingMerchantInventories/README.md index ce6de8cb1ead..1d107aac8de4 100644 --- a/ShoppingMerchantInventories/README.md +++ b/ShoppingMerchantInventories/README.md @@ -35,9 +35,9 @@ 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; +use Google\ApiCore\ApiException; +use Google\Shopping\Merchant\Inventories\V1\Client\LocalInventoryServiceClient; +use Google\Shopping\Merchant\Inventories\V1\DeleteLocalInventoryRequest; // Create a client. $localInventoryServiceClient = new LocalInventoryServiceClient(); diff --git a/ShoppingMerchantIssueResolution/README.md b/ShoppingMerchantIssueResolution/README.md index 11aa4643d681..c096f3df753d 100644 --- a/ShoppingMerchantIssueResolution/README.md +++ b/ShoppingMerchantIssueResolution/README.md @@ -35,10 +35,10 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -Google\ApiCore\ApiException; -Google\Shopping\Merchant\IssueResolution\V1\Client\IssueResolutionServiceClient; -Google\Shopping\Merchant\IssueResolution\V1\RenderAccountIssuesRequest; -Google\Shopping\Merchant\IssueResolution\V1\RenderAccountIssuesResponse; +use Google\ApiCore\ApiException; +use Google\Shopping\Merchant\IssueResolution\V1\Client\IssueResolutionServiceClient; +use Google\Shopping\Merchant\IssueResolution\V1\RenderAccountIssuesRequest; +use Google\Shopping\Merchant\IssueResolution\V1\RenderAccountIssuesResponse; // Create a client. $issueResolutionServiceClient = new IssueResolutionServiceClient(); diff --git a/ShoppingMerchantLfp/README.md b/ShoppingMerchantLfp/README.md index 2c501b0f502f..173c7e3117cc 100644 --- a/ShoppingMerchantLfp/README.md +++ b/ShoppingMerchantLfp/README.md @@ -35,22 +35,22 @@ 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; +use Google\ApiCore\ApiException; +use Google\Shopping\Merchant\Lfp\V1\Client\LfpMerchantStateServiceClient; +use Google\Shopping\Merchant\Lfp\V1\GetLfpMerchantStateRequest; +use Google\Shopping\Merchant\Lfp\V1\LfpMerchantState; // Create a client. -$lfpStoreServiceClient = new LfpStoreServiceClient(); +$lfpMerchantStateServiceClient = new LfpMerchantStateServiceClient(); // Prepare the request message. -$request = (new GetLfpStoreRequest()) +$request = (new GetLfpMerchantStateRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { - /** @var LfpStore $response */ - $response = $lfpStoreServiceClient->getLfpStore($request); + /** @var LfpMerchantState $response */ + $response = $lfpMerchantStateServiceClient->getLfpMerchantState($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/ShoppingMerchantNotifications/README.md b/ShoppingMerchantNotifications/README.md index cabd7facf00c..622630e16ef5 100644 --- a/ShoppingMerchantNotifications/README.md +++ b/ShoppingMerchantNotifications/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Shopping\Merchant\Notifications\V1\Client\NotificationsApiServiceClient; +use Google\Shopping\Merchant\Notifications\V1\GetNotificationSubscriptionRequest; +use Google\Shopping\Merchant\Notifications\V1\NotificationSubscription; // Create a client. $notificationsApiServiceClient = new NotificationsApiServiceClient(); diff --git a/ShoppingMerchantOrderTracking/README.md b/ShoppingMerchantOrderTracking/README.md index d6e754f74977..62f23ba04f39 100644 --- a/ShoppingMerchantOrderTracking/README.md +++ b/ShoppingMerchantOrderTracking/README.md @@ -35,14 +35,14 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -Google\ApiCore\ApiException; -Google\Shopping\Merchant\OrderTracking\V1beta\Client\OrderTrackingSignalsServiceClient; -Google\Shopping\Merchant\OrderTracking\V1beta\CreateOrderTrackingSignalRequest; -Google\Shopping\Merchant\OrderTracking\V1beta\OrderTrackingSignal; -Google\Shopping\Merchant\OrderTracking\V1beta\OrderTrackingSignal\LineItemDetails; -Google\Shopping\Merchant\OrderTracking\V1beta\OrderTrackingSignal\ShippingInfo; -Google\Shopping\Merchant\OrderTracking\V1beta\OrderTrackingSignal\ShippingInfo\ShippingState; -Google\Type\DateTime; +use Google\ApiCore\ApiException; +use Google\Shopping\Merchant\OrderTracking\V1\Client\OrderTrackingSignalsServiceClient; +use Google\Shopping\Merchant\OrderTracking\V1\CreateOrderTrackingSignalRequest; +use Google\Shopping\Merchant\OrderTracking\V1\OrderTrackingSignal; +use Google\Shopping\Merchant\OrderTracking\V1\OrderTrackingSignal\LineItemDetails; +use Google\Shopping\Merchant\OrderTracking\V1\OrderTrackingSignal\ShippingInfo; +use Google\Shopping\Merchant\OrderTracking\V1\OrderTrackingSignal\ShippingInfo\ShippingState; +use Google\Type\DateTime; $formattedParent = OrderTrackingSignalsServiceClient::accountName('[ACCOUNT]'); $orderTrackingSignalOrderId = '[ORDER_ID]'; diff --git a/ShoppingMerchantProducts/README.md b/ShoppingMerchantProducts/README.md index 2383a5524b73..771acb001508 100644 --- a/ShoppingMerchantProducts/README.md +++ b/ShoppingMerchantProducts/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Shopping\Merchant\Products\V1\Client\ProductsServiceClient; +use Google\Shopping\Merchant\Products\V1\GetProductRequest; +use Google\Shopping\Merchant\Products\V1\Product; // Create a client. $productsServiceClient = new ProductsServiceClient(); diff --git a/ShoppingMerchantPromotions/README.md b/ShoppingMerchantPromotions/README.md index d0f5a23cda5a..ea53befd2847 100644 --- a/ShoppingMerchantPromotions/README.md +++ b/ShoppingMerchantPromotions/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Shopping\Merchant\Promotions\V1\Client\PromotionsServiceClient; +use Google\Shopping\Merchant\Promotions\V1\GetPromotionRequest; +use Google\Shopping\Merchant\Promotions\V1\Promotion; // Create a client. $promotionsServiceClient = new PromotionsServiceClient(); diff --git a/ShoppingMerchantQuota/README.md b/ShoppingMerchantQuota/README.md index 58beacb37eee..dd13c73ed8d4 100644 --- a/ShoppingMerchantQuota/README.md +++ b/ShoppingMerchantQuota/README.md @@ -35,11 +35,11 @@ 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; +use Google\ApiCore\ApiException; +use Google\ApiCore\PagedListResponse; +use Google\Shopping\Merchant\Quota\V1\Client\QuotaServiceClient; +use Google\Shopping\Merchant\Quota\V1\ListQuotaGroupsRequest; +use Google\Shopping\Merchant\Quota\V1\QuotaGroup; // Create a client. $quotaServiceClient = new QuotaServiceClient(); diff --git a/ShoppingMerchantReports/README.md b/ShoppingMerchantReports/README.md index 44fc0e345d79..47ad8635efe8 100644 --- a/ShoppingMerchantReports/README.md +++ b/ShoppingMerchantReports/README.md @@ -35,11 +35,11 @@ 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; +use Google\ApiCore\ApiException; +use Google\ApiCore\PagedListResponse; +use Google\Shopping\Merchant\Reports\V1\Client\ReportServiceClient; +use Google\Shopping\Merchant\Reports\V1\ReportRow; +use Google\Shopping\Merchant\Reports\V1\SearchRequest; // Create a client. $reportServiceClient = new ReportServiceClient(); diff --git a/ShoppingMerchantReviews/README.md b/ShoppingMerchantReviews/README.md index 36f136e72829..1590498c9634 100644 --- a/ShoppingMerchantReviews/README.md +++ b/ShoppingMerchantReviews/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Shopping\Merchant\Reviews\V1beta\Client\MerchantReviewsServiceClient; +use Google\Shopping\Merchant\Reviews\V1beta\GetMerchantReviewRequest; +use Google\Shopping\Merchant\Reviews\V1beta\MerchantReview; // Create a client. $merchantReviewsServiceClient = new MerchantReviewsServiceClient(); diff --git a/Spanner/README.md b/Spanner/README.md index 7bafed0715e2..ee81b9f62aef 100644 --- a/Spanner/README.md +++ b/Spanner/README.md @@ -34,72 +34,26 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Spanner\SpannerClient; - -$spanner = new SpannerClient(); - -$db = $spanner->connect('my-instance', 'my-database'); - -$userQuery = $db->execute('SELECT * FROM Users WHERE id = @id', [ - 'parameters' => [ - 'id' => $userId - ] -]); - -$user = $userQuery->rows()->current(); - -echo 'Hello ' . $user['firstName']; -``` - -### Session warmup - -To issue a query against the Spanner service, the client library needs to request a session id from the server under the cover. This API call will add significant latency to your program. The Spanner client library provides a handy way to alleviate this problem by having a cached session pool. - -For more details, see: https://github.com/googleapis/google-cloud-php/blob/main/Spanner/src/Session/CacheSessionPool.php#L30 - -The following example shows how to use the `CacheSessionPool` with `SysVCacheItemPool` as well as how to configure a proper cache for authentication: - -```php -require __DIR__ . '/vendor/autoload.php'; - -use Google\Cloud\Spanner\SpannerClient; -use Google\Cloud\Spanner\Session\CacheSessionPool; -use Google\Auth\Cache\SysVCacheItemPool; - -$authCache = new SysVCacheItemPool(); -$sessionCache = new SysVCacheItemPool([ - // Use a different project identifier for ftok than the default - 'proj' => 'B', - // We highly recommend using 250kb as it should safely contain the default - // 500 maximum sessions the pool can handle. Please modify this value - // accordingly depending on the number of maximum sessions you would like - // for the pool to handle. - 'memsize' => 250000 -]); - -$spanner = new SpannerClient([ - 'authCache' => $authCache -]); - -$sessionPool = new CacheSessionPool( - $sessionCache, - [ - 'minSessions' => 10, - 'maxSessions' => 10 // Here it will create 10 sessions under the cover. - ] -); - -$database = $spanner->connect( - 'my-instance', - 'my-db', - [ - 'sessionPool' => $sessionPool - ] -); -// `warmup` will actually create the sessions for the first time. -$sessionPool->warmup(); +use Google\ApiCore\ApiException; +use Google\Cloud\Spanner\V1\Client\SpannerClient; +use Google\Cloud\Spanner\V1\GetSessionRequest; +use Google\Cloud\Spanner\V1\Session; + +// Create a client. +$spannerClient = new SpannerClient(); + +// Prepare the request message. +$request = (new GetSessionRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Session $response */ + $response = $spannerClient->getSession($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} ``` By using a cache implementation like `SysVCacheItemPool`, you can share the cached sessions among multiple processes, so that for example, you can warmup the session upon the server startup, then all the other PHP processes will benefit from the warmed up sessions. diff --git a/Speech/README.md b/Speech/README.md index 36060b56aae2..0bbe96b96b00 100644 --- a/Speech/README.md +++ b/Speech/README.md @@ -38,23 +38,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding; -use Google\Cloud\Speech\V1\RecognitionConfig; -use Google\Cloud\Speech\V1\StreamingRecognitionConfig; - -$recognitionConfig = new RecognitionConfig(); -$recognitionConfig->setEncoding(AudioEncoding::FLAC); -$recognitionConfig->setSampleRateHertz(44100); -$recognitionConfig->setLanguageCode('en-US'); -$config = new StreamingRecognitionConfig(); -$config->setConfig($recognitionConfig); - -$audioResource = fopen('path/to/audio.flac', 'r'); - -$responses = $speechClient->recognizeAudioStream($config, $audioResource); - -foreach ($responses as $element) { - // doSomethingWith($element); +use Google\ApiCore\ApiException; +use Google\Cloud\Speech\V2\Client\SpeechClient; +use Google\Cloud\Speech\V2\Config; +use Google\Cloud\Speech\V2\GetConfigRequest; + +// Create a client. +$speechClient = new SpeechClient(); + +// Prepare the request message. +$request = (new GetConfigRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Config $response */ + $response = $speechClient->getConfig($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/SqlAdmin/README.md b/SqlAdmin/README.md index c154d0cd8d82..67e8f1620c5b 100644 --- a/SqlAdmin/README.md +++ b/SqlAdmin/README.md @@ -28,6 +28,30 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Sql\V1\BackupRun; +use Google\Cloud\Sql\V1\Client\SqlBackupRunsServiceClient; +use Google\Cloud\Sql\V1\SqlBackupRunsGetRequest; + +// Create a client. +$sqlBackupRunsServiceClient = new SqlBackupRunsServiceClient(); + +// Prepare the request message. +$request = new SqlBackupRunsGetRequest(); + +// Call the API and handle any network failures. +try { + /** @var BackupRun $response */ + $response = $sqlBackupRunsServiceClient->get($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/StorageBatchOperations/README.md b/StorageBatchOperations/README.md index e11e693b23ea..6559b67a2531 100644 --- a/StorageBatchOperations/README.md +++ b/StorageBatchOperations/README.md @@ -35,10 +35,10 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -Google\ApiCore\ApiException; -Google\Cloud\StorageBatchOperations\V1\Client\StorageBatchOperationsClient; -Google\Cloud\StorageBatchOperations\V1\GetJobRequest; -Google\Cloud\StorageBatchOperations\V1\Job; +use Google\ApiCore\ApiException; +use Google\Cloud\StorageBatchOperations\V1\Client\StorageBatchOperationsClient; +use Google\Cloud\StorageBatchOperations\V1\GetJobRequest; +use Google\Cloud\StorageBatchOperations\V1\Job; // Create a client. $storageBatchOperationsClient = new StorageBatchOperationsClient(); diff --git a/StorageControl/README.md b/StorageControl/README.md index 48a180eaa7ac..a8bbb132872b 100644 --- a/StorageControl/README.md +++ b/StorageControl/README.md @@ -34,22 +34,22 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\Storage\Control\V2\AnywhereCache; +use Google\Cloud\Storage\Control\V2\Client\StorageControlClient; +use Google\Cloud\Storage\Control\V2\GetAnywhereCacheRequest; // Create a client. $storageControlClient = new StorageControlClient(); // Prepare the request message. -$request = (new GetFolderRequest()) +$request = (new GetAnywhereCacheRequest()) ->setName($formattedName); // Call the API and handle any network failures. try { - /** @var Folder $response */ - $response = $storageControlClient->getFolder($request); + /** @var AnywhereCache $response */ + $response = $storageControlClient->getAnywhereCache($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/StorageInsights/README.md b/StorageInsights/README.md index c2a7ec2ca4bf..1e9a5da1bf34 100644 --- a/StorageInsights/README.md +++ b/StorageInsights/README.md @@ -35,21 +35,22 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\StorageInsights\V1\Client\StorageInsightsClient; +use Google\Cloud\StorageInsights\V1\DatasetConfig; +use Google\Cloud\StorageInsights\V1\GetDatasetConfigRequest; // Create a client. $storageInsightsClient = new StorageInsightsClient(); // Prepare the request message. -$request = new GetLocationRequest(); +$request = (new GetDatasetConfigRequest()) + ->setName($formattedName); // Call the API and handle any network failures. try { - /** @var Location $response */ - $response = $storageInsightsClient->getLocation($request); + /** @var DatasetConfig $response */ + $response = $storageInsightsClient->getDatasetConfig($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/StorageTransfer/README.md b/StorageTransfer/README.md index 5a01d4942cab..d20e061bcc90 100644 --- a/StorageTransfer/README.md +++ b/StorageTransfer/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\StorageTransfer\V1\AgentPool; +use Google\Cloud\StorageTransfer\V1\Client\StorageTransferServiceClient; +use Google\Cloud\StorageTransfer\V1\GetAgentPoolRequest; + +// Create a client. +$storageTransferServiceClient = new StorageTransferServiceClient(); + +// Prepare the request message. +$request = (new GetAgentPoolRequest()) + ->setName($name); + +// Call the API and handle any network failures. +try { + /** @var AgentPool $response */ + $response = $storageTransferServiceClient->getAgentPool($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Support/README.md b/Support/README.md index 6109e7bb3e0d..8eb550d6e754 100644 --- a/Support/README.md +++ b/Support/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\Support\V2\Client\CaseServiceClient; +use Google\Cloud\Support\V2\GetCaseRequest; +use Google\Cloud\Support\V2\PBCase; // Create a client. $caseServiceClient = new CaseServiceClient(); diff --git a/Talent/README.md b/Talent/README.md index d441caa6133f..426b131f10e3 100644 --- a/Talent/README.md +++ b/Talent/README.md @@ -31,20 +31,26 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - +use Google\ApiCore\ApiException; +use Google\Cloud\Talent\V4\Client\CompanyServiceClient; use Google\Cloud\Talent\V4\Company; -use Google\Cloud\Talent\V4\CompanyServiceClient; - -$client = new CompanyServiceClient(); -$response = $client->createCompany( - CompanyServiceClient::projectName('spaceman-spiff2'), - new Company([ - 'display_name' => 'Google, LLC', - 'external_id' => 1, - 'headquarters_address' => '1600 Amphitheatre Parkway, Mountain View, CA' - ]) -); +use Google\Cloud\Talent\V4\GetCompanyRequest; + +// Create a client. +$companyServiceClient = new CompanyServiceClient(); + +// Prepare the request message. +$request = (new GetCompanyRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Company $response */ + $response = $companyServiceClient->getCompany($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} ``` ### Debugging diff --git a/Tasks/README.md b/Tasks/README.md index 1c4b45742dc5..ca18edeb05a3 100644 --- a/Tasks/README.md +++ b/Tasks/README.md @@ -32,37 +32,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require_once __DIR__ . '/vendor/autoload.php'; - -use Google\Cloud\Tasks\V2\CloudTasksClient; -use Google\Cloud\Tasks\V2\Queue; - -$client = new CloudTasksClient(); - -$project = 'example-project'; -$location = 'us-central1'; -$queue = uniqid('example-queue-'); -$queueName = $client::queueName($project, $location, $queue); - -// Create a queue -$locationName = $client::locationName($project, $location); -$queue = new Queue([ - 'name' => $queueName -]); -$queue->setName($queueName); -$client->createQueue($locationName, $queue); - -echo "$queueName created." . PHP_EOL; - -// List queues -echo 'Listing the queues' . PHP_EOL; -$resp = $client->listQueues($locationName); -foreach ($resp->iterateAllElements() as $q) { - echo $q->getName() . PHP_EOL; +use Google\ApiCore\ApiException; +use Google\Cloud\Location\GetLocationRequest; +use Google\Cloud\Location\Location; +use Google\Cloud\Tasks\V2\Client\CloudTasksClient; + +// Create a client. +$cloudTasksClient = new CloudTasksClient(); + +// Prepare the request message. +$request = new GetLocationRequest(); + +// Call the API and handle any network failures. +try { + /** @var Location $response */ + $response = $cloudTasksClient->getLocation($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } - -// Delete the queue -$client->deleteQueue($queueName); ``` ### Debugging diff --git a/TelcoAutomation/README.md b/TelcoAutomation/README.md index 094e4f777721..0a0bb7424835 100644 --- a/TelcoAutomation/README.md +++ b/TelcoAutomation/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Cloud\TelcoAutomation\V1\Blueprint; +use Google\Cloud\TelcoAutomation\V1\Client\TelcoAutomationClient; +use Google\Cloud\TelcoAutomation\V1\GetBlueprintRequest; // Create a client. $telcoAutomationClient = new TelcoAutomationClient(); diff --git a/TextToSpeech/README.md b/TextToSpeech/README.md index fa5e12cfd2d1..7db119cd0d4d 100644 --- a/TextToSpeech/README.md +++ b/TextToSpeech/README.md @@ -28,30 +28,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require __DIR__ . '/vendor/autoload.php'; - -use Google\Cloud\TextToSpeech\V1\AudioConfig; -use Google\Cloud\TextToSpeech\V1\AudioEncoding; -use Google\Cloud\TextToSpeech\V1\SynthesisInput; +use Google\ApiCore\ApiException; use Google\Cloud\TextToSpeech\V1\Client\TextToSpeechClient; -use Google\Cloud\TextToSpeech\V1\VoiceSelectionParams; -use Google\Cloud\TextToSpeech\V1\SynthesizeSpeechRequest; +use Google\Cloud\TextToSpeech\V1\ListVoicesRequest; +use Google\Cloud\TextToSpeech\V1\ListVoicesResponse; +// Create a client. $textToSpeechClient = new TextToSpeechClient(); -$input = new SynthesisInput(); -$input->setText('Japan\'s national soccer team won against Colombia!'); -$voice = new VoiceSelectionParams(); -$voice->setLanguageCode('en-US'); -$audioConfig = new AudioConfig(); -$audioConfig->setAudioEncoding(AudioEncoding::MP3); -$request = (new SynthesizeSpeechRequest()) - ->setInput($input) - ->setVoice($voice) - ->setAudioConfig($audioConfig); - -$resp = $textToSpeechClient->synthesizeSpeech($request); -file_put_contents('test.mp3', $resp->getAudioContent()); +// Prepare the request message. +$request = new ListVoicesRequest(); + +// Call the API and handle any network failures. +try { + /** @var ListVoicesResponse $response */ + $response = $textToSpeechClient->listVoices($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} ``` ### Debugging diff --git a/Tpu/README.md b/Tpu/README.md index 0332c8a3ae64..bb8f020e84f1 100644 --- a/Tpu/README.md +++ b/Tpu/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Tpu\V2\AcceleratorType; +use Google\Cloud\Tpu\V2\Client\TpuClient; +use Google\Cloud\Tpu\V2\GetAcceleratorTypeRequest; + +// Create a client. +$tpuClient = new TpuClient(); + +// Prepare the request message. +$request = (new GetAcceleratorTypeRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var AcceleratorType $response */ + $response = $tpuClient->getAcceleratorType($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Trace/README.md b/Trace/README.md index 538cc7abbcee..003bfc5eb900 100644 --- a/Trace/README.md +++ b/Trace/README.md @@ -38,69 +38,36 @@ be ready to start making requests. ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Trace\TraceClient; - -$traceClient = new TraceClient(); - -// Create a Trace -$trace = $traceClient->trace(); -$span = $trace->span([ - 'name' => 'main' -]); -$span->setStartTime(); -// some expensive operation -$span->setEndTime(); - -$trace->setSpans([$span]); -$traceClient->insert($trace); - -// List recent Traces -foreach($traceClient->traces() as $trace) { - var_dump($trace->traceId()); +use Google\ApiCore\ApiException; +use Google\Cloud\Trace\V2\Client\TraceServiceClient; +use Google\Cloud\Trace\V2\Span; +use Google\Cloud\Trace\V2\TruncatableString; +use Google\Protobuf\Timestamp; + +// Create a client. +$traceServiceClient = new TraceServiceClient(); + +// Prepare the request message. +$displayName = new TruncatableString(); +$startTime = new Timestamp(); +$endTime = new Timestamp(); +$request = (new Span()) + ->setName($name) + ->setSpanId($spanId) + ->setDisplayName($displayName) + ->setStartTime($startTime) + ->setEndTime($endTime); + +// Call the API and handle any network failures. +try { + /** @var Span $response */ + $response = $traceServiceClient->createSpan($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` -### Creating a Trace - -```php -use Google\Cloud\Trace\TraceClient; - -$client = new TraceClient(); -$trace = $client->trace(); -$span = $trace->span(['name' => 'main']); -$trace->setSpans([$span]); - -$client->insert($trace); -``` - -### Using OpenCensus - -We highly recommend using the [OpenCensus][opencensus] project to instrument -your application. OpenCensus is an open source, distributed tracing framework -that maintains integrations with popular frameworks and tools. OpenCensus -provides a data exporter for Stackdriver Trace which uses this library. If you -were using google/cloud-trace <= v0.3.3 or google/cloud <= 0.46.0, then check -out the [migration guide to OpenCensus][opencensus-migration]. - -Install with `composer` or add to your `composer.json`. - -```sh -$ composer require opencensus/opencensus opencensus/opencensus-exporter-stackdriver -``` - -`opencensus/opencensus` provides a service-agnostic implementation. Be sure to -also require `opencensus/opencensus-exporter-stackdriver` to enable exporting of -traces to Stackdriver Trace. - -```php -use OpenCensus\Trace\Exporter\StackdriverExporter; -use OpenCensus\Trace\Tracer; - -Tracer::start(new StackdriverExporter()); -``` - See the [OpenCensus documentation][opencensus-php] for more configuration options and features. diff --git a/Translate/README.md b/Translate/README.md index 6c6401908ba6..7df8e7d483a5 100644 --- a/Translate/README.md +++ b/Translate/README.md @@ -33,10 +33,10 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -Google\ApiCore\ApiException; -Google\Cloud\Translate\V3\AdaptiveMtDataset; -Google\Cloud\Translate\V3\Client\TranslationServiceClient; -Google\Cloud\Translate\V3\GetAdaptiveMtDatasetRequest; +use Google\ApiCore\ApiException; +use Google\Cloud\Translate\V3\AdaptiveMtDataset; +use Google\Cloud\Translate\V3\Client\TranslationServiceClient; +use Google\Cloud\Translate\V3\GetAdaptiveMtDatasetRequest; // Create a client. $translationServiceClient = new TranslationServiceClient(); @@ -53,29 +53,6 @@ try { } 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'; - -use Google\Cloud\Translate\V3\TranslationServiceClient; - -$translationClient = new TranslationServiceClient(); -$content = ['one', 'two', 'three']; -$targetLanguage = 'es'; -$response = $translationClient->translateText( - $content, - $targetLanguage, - TranslationServiceClient::locationName('[PROJECT_ID]', 'global') -); - -foreach ($response->getTranslations() as $key => $translation) { - $separator = $key === 2 - ? '!' - : ', '; - echo $translation->getTranslatedText() . $separator; -} ``` ### Choosing the Right Client for You diff --git a/VideoIntelligence/README.md b/VideoIntelligence/README.md index c332fdefe480..03466e876964 100644 --- a/VideoIntelligence/README.md +++ b/VideoIntelligence/README.md @@ -40,46 +40,36 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require __DIR__ . '/vendor/autoload.php'; - -use Google\Cloud\VideoIntelligence\V1\VideoIntelligenceServiceClient; -use Google\Cloud\VideoIntelligence\V1\Feature; - +use Google\ApiCore\ApiException; +use Google\ApiCore\OperationResponse; +use Google\Cloud\VideoIntelligence\V1\AnnotateVideoRequest; +use Google\Cloud\VideoIntelligence\V1\AnnotateVideoResponse; +use Google\Cloud\VideoIntelligence\V1\Client\VideoIntelligenceServiceClient; +use Google\Rpc\Status; + +// Create a client. $videoIntelligenceServiceClient = new VideoIntelligenceServiceClient(); -$inputUri = "gs://example-bucket/example-video.mp4"; - -$features = [ - Feature::LABEL_DETECTION, -]; -$operationResponse = $videoIntelligenceServiceClient->annotateVideo([ - 'inputUri' => $inputUri, - 'features' => $features -]); -$operationResponse->pollUntilComplete(); -if ($operationResponse->operationSucceeded()) { - $results = $operationResponse->getResult(); - foreach ($results->getAnnotationResults() as $result) { - echo 'Segment labels' . PHP_EOL; - foreach ($result->getSegmentLabelAnnotations() as $labelAnnotation) { - echo "Label: " . $labelAnnotation->getEntity()->getDescription() - . PHP_EOL; - } - echo 'Shot labels' . PHP_EOL; - foreach ($result->getShotLabelAnnotations() as $labelAnnotation) { - echo "Label: " . $labelAnnotation->getEntity()->getDescription() - . PHP_EOL; - } - echo 'Frame labels' . PHP_EOL; - foreach ($result->getFrameLabelAnnotations() as $labelAnnotation) { - echo "Label: " . $labelAnnotation->getEntity()->getDescription() - . PHP_EOL; - } +// Prepare the request message. +$request = new AnnotateVideoRequest(); + +// Call the API and handle any network failures. +try { + /** @var OperationResponse $response */ + $response = $videoIntelligenceServiceClient->annotateVideo($request); + $response->pollUntilComplete(); + + if ($response->operationSucceeded()) { + /** @var AnnotateVideoResponse $result */ + $result = $response->getResult(); + printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString()); + } else { + /** @var Status $error */ + $error = $response->getError(); + printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString()); } -} else { - $error = $operationResponse->getError(); - echo "error: " . $error->getMessage() . PHP_EOL; - +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/VideoLiveStream/README.md b/VideoLiveStream/README.md index 97b01021d7d6..34a0b092b70f 100644 --- a/VideoLiveStream/README.md +++ b/VideoLiveStream/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Video\LiveStream\V1\Asset; +use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient; +use Google\Cloud\Video\LiveStream\V1\GetAssetRequest; + +// Create a client. +$livestreamServiceClient = new LivestreamServiceClient(); + +// Prepare the request message. +$request = (new GetAssetRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Asset $response */ + $response = $livestreamServiceClient->getAsset($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/VideoStitcher/README.md b/VideoStitcher/README.md index ddf14f202bb6..6283f32573a7 100644 --- a/VideoStitcher/README.md +++ b/VideoStitcher/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Video\Stitcher\V1\CdnKey; +use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient; +use Google\Cloud\Video\Stitcher\V1\GetCdnKeyRequest; + +// Create a client. +$videoStitcherServiceClient = new VideoStitcherServiceClient(); + +// Prepare the request message. +$request = (new GetCdnKeyRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var CdnKey $response */ + $response = $videoStitcherServiceClient->getCdnKey($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/VideoTranscoder/README.md b/VideoTranscoder/README.md index 9c08f9cd3023..d65f549a5109 100644 --- a/VideoTranscoder/README.md +++ b/VideoTranscoder/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\Video\Transcoder\V1\Client\TranscoderServiceClient; +use Google\Cloud\Video\Transcoder\V1\GetJobRequest; +use Google\Cloud\Video\Transcoder\V1\Job; + +// Create a client. +$transcoderServiceClient = new TranscoderServiceClient(); + +// Prepare the request message. +$request = (new GetJobRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Job $response */ + $response = $transcoderServiceClient->getJob($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/Vision/README.md b/Vision/README.md index 65eff20939f1..5630390cb0b9 100644 --- a/Vision/README.md +++ b/Vision/README.md @@ -31,38 +31,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Vision\V1\AnnotateImageRequest; -use Google\Cloud\Vision\V1\BatchAnnotateImagesRequest; -use Google\Cloud\Vision\V1\Client\ImageAnnotatorClient; -use Google\Cloud\Vision\V1\Feature; -use Google\Cloud\Vision\V1\Image; -use Google\Cloud\Vision\V1\Likelihood; - -$client = new ImageAnnotatorClient(); - -// Prepare the request -$content = file_get_contents('/data/photos/family-photo.jpg', 'r'); -$image = (new Image()) - ->setContent($content); -$feature = (new Feature()) - ->setType(Feature\Type::FACE_DETECTION); -$request = (new AnnotateImageRequest()) - ->setImage($image) - ->setFeatures([$feature]); -$batchRequest = (new BatchAnnotateImagesRequest()) - ->setRequests([$request]); - -// Annotate an image, detecting faces. -$batchResponse = $client->batchAnnotateImages($batchRequest); - -// Determine if the detected faces have headwear. -foreach ($batchResponse->getResponses() as $response) { - foreach ($response->getFaceAnnotations() as $faceAnnotation) { - $likelihood = Likelihood::name($faceAnnotation->getHeadwearLikelihood()); - echo "Likelihood of headwear: $likelihood" . PHP_EOL; - } +use Google\ApiCore\ApiException; +use Google\Cloud\Vision\V1\Client\ProductSearchClient; +use Google\Cloud\Vision\V1\GetProductRequest; +use Google\Cloud\Vision\V1\Product; + +// Create a client. +$productSearchClient = new ProductSearchClient(); + +// Prepare the request message. +$request = (new GetProductRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Product $response */ + $response = $productSearchClient->getProduct($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/VmMigration/README.md b/VmMigration/README.md index 34bc9aba17b2..72bf9078ee5d 100644 --- a/VmMigration/README.md +++ b/VmMigration/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\VMMigration\V1\Client\VmMigrationClient; +use Google\Cloud\VMMigration\V1\CloneJob; +use Google\Cloud\VMMigration\V1\GetCloneJobRequest; + +// Create a client. +$vmMigrationClient = new VmMigrationClient(); + +// Prepare the request message. +$request = (new GetCloneJobRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var CloneJob $response */ + $response = $vmMigrationClient->getCloneJob($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/VmwareEngine/README.md b/VmwareEngine/README.md index 712daa70d67f..d060c23beb4f 100644 --- a/VmwareEngine/README.md +++ b/VmwareEngine/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\VmwareEngine\V1\Client\VmwareEngineClient; +use Google\Cloud\VmwareEngine\V1\Cluster; +use Google\Cloud\VmwareEngine\V1\GetClusterRequest; + +// Create a client. +$vmwareEngineClient = new VmwareEngineClient(); + +// Prepare the request message. +$request = (new GetClusterRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Cluster $response */ + $response = $vmwareEngineClient->getCluster($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/VpcAccess/README.md b/VpcAccess/README.md index 238fd25e6855..254320573623 100644 --- a/VpcAccess/README.md +++ b/VpcAccess/README.md @@ -28,6 +28,31 @@ please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 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 + +```php +use Google\ApiCore\ApiException; +use Google\Cloud\VpcAccess\V1\Client\VpcAccessServiceClient; +use Google\Cloud\VpcAccess\V1\Connector; +use Google\Cloud\VpcAccess\V1\GetConnectorRequest; + +// Create a client. +$vpcAccessServiceClient = new VpcAccessServiceClient(); + +// Prepare the request message. +$request = (new GetConnectorRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Connector $response */ + $response = $vpcAccessServiceClient->getConnector($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + ### Debugging Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) diff --git a/WebRisk/README.md b/WebRisk/README.md index e8a03b6da133..67728b4c7709 100644 --- a/WebRisk/README.md +++ b/WebRisk/README.md @@ -31,23 +31,27 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php +use Google\ApiCore\ApiException; +use Google\Cloud\WebRisk\V1\Client\WebRiskServiceClient; +use Google\Cloud\WebRisk\V1\SearchHashesRequest; +use Google\Cloud\WebRisk\V1\SearchHashesResponse; use Google\Cloud\WebRisk\V1\ThreatType; -use Google\Cloud\WebRisk\V1\WebRiskServiceClient; - -$webrisk = new WebRiskServiceClient(); - -$uri = 'http://testsafebrowsing.appspot.com/s/malware.html'; -$response = $webrisk->searchUris($uri, [ - ThreatType::MALWARE, - ThreatType::SOCIAL_ENGINEERING -]); - -$threats = $response->getThreat(); -if ($threats) { - echo $uri . ' has the following threats:' . PHP_EOL; - foreach ($threats->getThreatTypes() as $threat) { - echo ThreatType::name($threat) . PHP_EOL; - } + +// Create a client. +$webRiskServiceClient = new WebRiskServiceClient(); + +// Prepare the request message. +$threatTypes = [$threatTypesElement,]; +$request = (new SearchHashesRequest()) + ->setThreatTypes($threatTypes); + +// Call the API and handle any network failures. +try { + /** @var SearchHashesResponse $response */ + $response = $webRiskServiceClient->searchHashes($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/WebSecurityScanner/README.md b/WebSecurityScanner/README.md index 9c8fb6cc1202..f106aead2687 100644 --- a/WebSecurityScanner/README.md +++ b/WebSecurityScanner/README.md @@ -31,25 +31,25 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\WebSecurityScanner\V1beta\ScanConfig; -use Google\Cloud\WebSecurityScanner\V1beta\ScanConfig\UserAgent; -use Google\Cloud\WebSecurityScanner\V1beta\ScanRun\ExecutionState; -use Google\Cloud\WebSecurityScanner\V1beta\WebSecurityScannerClient; - -$client = new WebSecurityScannerClient(); -$scanConfig = $client->createScanConfig( - WebSecurityScannerClient::projectName('[MY_PROJECT_ID'), - new ScanConfig([ - 'display_name' => 'Test Scan', - 'starting_urls' => ['https://[MY_APPLICATION_ID].appspot.com/'], - 'user_agent' => UserAgent::CHROME_LINUX - ]) -); -$scanRun = $client->startScanRun($scanConfig->getName()); - -echo 'Scan execution state: ' . ExecutionState::name($scanRun->getExecutionState()) . PHP_EOL; +use Google\ApiCore\ApiException; +use Google\Cloud\WebSecurityScanner\V1\Client\WebSecurityScannerClient; +use Google\Cloud\WebSecurityScanner\V1\Finding; +use Google\Cloud\WebSecurityScanner\V1\GetFindingRequest; + +// Create a client. +$webSecurityScannerClient = new WebSecurityScannerClient(); + +// Prepare the request message. +$request = new GetFindingRequest(); + +// Call the API and handle any network failures. +try { + /** @var Finding $response */ + $response = $webSecurityScannerClient->getFinding($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} ``` ### Debugging diff --git a/Workflows/README.md b/Workflows/README.md index 018008d9656b..e0a79509c84e 100644 --- a/Workflows/README.md +++ b/Workflows/README.md @@ -31,18 +31,24 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -require 'vendor/autoload.php'; - -use Google\Cloud\Workflows\V1beta\WorkflowsClient; - -$client = new WorkflowsClient(); - -$workflows = $client->listWorkflows( - WorkflowsClient::locationName('[MY_PROJECT_ID]', 'us-central1') -); - -foreach ($workflows as $workflow) { - print 'Found workflow: ' . $workflow->getName() . PHP_EOL; +use Google\ApiCore\ApiException; +use Google\Cloud\Location\GetLocationRequest; +use Google\Cloud\Location\Location; +use Google\Cloud\Workflows\V1\Client\WorkflowsClient; + +// Create a client. +$workflowsClient = new WorkflowsClient(); + +// Prepare the request message. +$request = new GetLocationRequest(); + +// Call the API and handle any network failures. +try { + /** @var Location $response */ + $response = $workflowsClient->getLocation($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } ``` diff --git a/dev/google-cloud b/dev/google-cloud index fb2b7dbbbe62..b35433b040f9 100755 --- a/dev/google-cloud +++ b/dev/google-cloud @@ -22,7 +22,6 @@ if (!file_exists(__DIR__ . '/vendor/autoload.php')) { require __DIR__ . '/vendor/autoload.php'; -use Google\Cloud\Dev\Command\AddSampleToReadmeCommand; use Google\Cloud\Dev\Command\ComponentInfoCommand; use Google\Cloud\Dev\Command\DocFxCommand; use Google\Cloud\Dev\Command\NewComponentCommand; @@ -31,6 +30,7 @@ use Google\Cloud\Dev\Command\ReleaseInfoCommand; use Google\Cloud\Dev\Command\SplitCommand; use Google\Cloud\Dev\Command\UpdateComponentCommand; use Google\Cloud\Dev\Command\UpdateDepsCommand; +use Google\Cloud\Dev\Command\UpdateReadmeSampleCommand; use Symfony\Component\Console\Application; if (!class_exists(Application::class)) { @@ -44,7 +44,6 @@ if (!class_exists(Application::class)) { $rootDirectory = realpath(__DIR__ . '/../') . '/'; $app = new Application; -$app->add(new AddSampleToReadmeCommand()); $app->add(new ComponentInfoCommand()); $app->add(new DocFxCommand()); $app->add(new NewComponentCommand($rootDirectory)); @@ -53,4 +52,5 @@ $app->add(new ReleaseInfoCommand()); $app->add(new SplitCommand($rootDirectory)); $app->add(new UpdateComponentCommand($rootDirectory)); $app->add(new UpdateDepsCommand()); +$app->add(new UpdateReadmeSampleCommand($rootDirectory)); $app->run(); diff --git a/dev/src/Command/NewComponentCommand.php b/dev/src/Command/NewComponentCommand.php index f017c829575c..fc4bdd615d67 100644 --- a/dev/src/Command/NewComponentCommand.php +++ b/dev/src/Command/NewComponentCommand.php @@ -243,9 +243,9 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($returnCode !== Command::SUCCESS) { return $returnCode; } - $addSamplesArgs = ['--component' => [$new->componentName]]; - $addSampleCommand = $this->getApplication()->find('add-sample-to-readme'); - $returnCode = $addSampleCommand->run(new ArrayInput($addSamplesArgs), $output); + $updateReadmeSampleArgs = ['--component' => [$new->componentName]]; + $updateReadmeSampleCommand = $this->getApplication()->find('update-readme-sample'); + $returnCode = $updateReadmeSampleCommand->run(new ArrayInput($updateReadmeSampleArgs), $output); if ($returnCode !== Command::SUCCESS) { return $returnCode; } diff --git a/dev/src/Command/AddSampleToReadmeCommand.php b/dev/src/Command/UpdateReadmeSampleCommand.php similarity index 63% rename from dev/src/Command/AddSampleToReadmeCommand.php rename to dev/src/Command/UpdateReadmeSampleCommand.php index e67cfa1a4bf3..a12c067f26b7 100644 --- a/dev/src/Command/AddSampleToReadmeCommand.php +++ b/dev/src/Command/UpdateReadmeSampleCommand.php @@ -27,11 +27,23 @@ * Add a Component * @internal */ -class AddSampleToReadmeCommand extends Command +class UpdateReadmeSampleCommand extends Command { + private $rootPath; + + /** + * @param string $rootPath The path to the repository root directory. + * @param Client $httpClient specify the HTTP client, useful for tests. + */ + public function __construct(string $rootPath) + { + $this->rootPath = realpath($rootPath); + parent::__construct(); + } + protected function configure() { - $this->setName('add-sample-to-readme') + $this->setName('update-readme-sample') ->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'); @@ -41,17 +53,24 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { // Compile all the component data into rows - $components = Component::getComponents($input->getOption('component')); + $components = Component::getComponents($input->getOption('component'), $this->rootPath); foreach ($components as $component) { if (!$sample = $component->getSimplestSample()) { - $output->writeln('Unable to retrieve sample in ' . $component->getName() . ''); + $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; + $output->writeln('Trying to insert above "Debugging" header instead...'); + if (strpos($readme, '### Debugging') === false) { + $output->writeln(sprintf( + 'No "Debugging" header found, unable to add sample to %s README.md', + $component->getName() + )); + continue; + } } $sample = "```php\n" . $sample . "\n```"; @@ -60,9 +79,17 @@ protected function execute(InputInterface $input, OutputInterface $output) if (!$input->getOption('update')) { continue; } + if ($matches[1] === $sample) { + $output->writeln('Nothing to update.'); + continue; + } $readme = str_replace($matches[1], $sample, $readme); } else { - $readme = str_replace('### Sample', "### Sample\n\n" . $sample, $readme); + if (strpos($readme, '### Sample') === false) { + $readme = str_replace('### Debugging', "### Sample\n\n" . $sample . "\n\n### Debugging", $readme); + } else { + $readme = str_replace('### Sample', "### Sample\n\n" . $sample, $readme); + } } file_put_contents($component->getPath() . '/README.md', $readme); diff --git a/dev/src/Component.php b/dev/src/Component.php index 5670af423851..d33acd5860d8 100644 --- a/dev/src/Component.php +++ b/dev/src/Component.php @@ -47,9 +47,9 @@ public function __construct(private string $name, ?string $path = null) $this->validateComponentFiles(); } - private static function getComponentNames(): array + private static function getComponentNames(string $rootDir): array { - $components = scandir(self::ROOT_DIR); + $components = scandir($rootDir); foreach ($components as $i => $name) { if (!is_dir(self::ROOT_DIR . $name) || !preg_match('/^[A-Z]/', $name)) { unset($components[$i]); @@ -59,11 +59,14 @@ private static function getComponentNames(): array return $components; } - public static function getComponents(array $componentNames = []): array + public static function getComponents(array $componentNames = [], ?string $rootDir = null): array { + if (is_null($rootDir)) { + $rootDir = realpath(self::ROOT_DIR); + } $components = []; - foreach ($componentNames ?: self::getComponentNames() as $name) { - $components[] = new Component($name); + foreach ($componentNames ?: self::getComponentNames($rootDir) as $name) { + $components[] = new Component($name, $rootDir . '/' . $name); } return $components; @@ -144,7 +147,7 @@ public function getReferenceDocumentationUid(): string private function getComponentPath(string $component): string { - $components = $this->getComponentNames(); + $components = $this->getComponentNames(self::ROOT_DIR); if (!in_array($component, $components)) { throw new \Exception('Invalid component name provided: ' . $component); @@ -164,7 +167,7 @@ private function validateComponentFiles(): void $composerPath = $this->path . '/composer.json'; if (!file_exists($composerPath)) { throw new RuntimeException( - sprintf('composer.json not found for component "%s"', $this->name) + sprintf('composer.json not found in path "%s"', $composerPath) ); } $composerJson = json_decode(file_get_contents($composerPath), true); @@ -373,56 +376,13 @@ public function getComponentDependencies(): array 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; + // Sorted by most recent + foreach ($this->getComponentPackages() as $version) { + if ($sample = $version->getSimplestSample()) { + return $sample; } } - 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)); + return ''; } } diff --git a/dev/src/ComponentPackage.php b/dev/src/ComponentPackage.php index b24109de792c..cbb62a572015 100644 --- a/dev/src/ComponentPackage.php +++ b/dev/src/ComponentPackage.php @@ -162,4 +162,63 @@ private function getClassFromFile(string $filePath): string } throw new \Exception('No class found in ' . $filePath); } + + public function getSimplestSample(): string + { + $samplesPath = $this->component->getPath() . '/samples/' . $this->name; + if (!file_exists($samplesPath)) { + return ''; + } + + $result = (new Finder())->files()->in($samplesPath) + ->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); + + // remove indent + $sampleText = implode("\n", array_map(fn ($line) => substr($line, 4), $lines)); + + // add imports + $imports = array_filter( + explode("\n", $preferredFile->getContents()), + fn ($line) => str_starts_with($line, 'use Google\\') + ); + + if ($imports) { + $imports[] = "\n"; + $sampleText = implode("\n", $imports) . $sampleText; + } + + return $sampleText; + } } diff --git a/dev/tests/Unit/Command/NewComponentCommandTest.php b/dev/tests/Unit/Command/NewComponentCommandTest.php index 7d9c973082b1..ed0c2a5cce7b 100644 --- a/dev/tests/Unit/Command/NewComponentCommandTest.php +++ b/dev/tests/Unit/Command/NewComponentCommandTest.php @@ -172,10 +172,10 @@ public function testNewComponentWithUpdateComponent() $application = new Application(); $application->add(new NewComponentCommand(self::$tmpDir)); - // Add dummy command for update-command and add-sample-to-readme to ensure they're called + // Add dummy command for update-command and update-readme-sample to ensure they're called $dummyCommand->getName()->willReturn('update-component'); $application->add($dummyCommand->reveal()); - $dummyCommand->getName()->willReturn('add-sample-to-readme'); + $dummyCommand->getName()->willReturn('update-readme-sample'); $application->add($dummyCommand->reveal()); $dummyCommand->run(Argument::cetera()) ->willReturn(0) diff --git a/dev/tests/Unit/Command/UpdateReadmeSampleCommandTest.php b/dev/tests/Unit/Command/UpdateReadmeSampleCommandTest.php new file mode 100644 index 000000000000..72a402085274 --- /dev/null +++ b/dev/tests/Unit/Command/UpdateReadmeSampleCommandTest.php @@ -0,0 +1,99 @@ +root = sys_get_temp_dir() . '/google-cloud-php-tests-' . rand(); + $componentDir = $this->root . '/ClientSnippets'; + $filesystem = new Filesystem(); + $filesystem->mirror(__DIR__ . '/../../fixtures/component/ClientSnippets', $componentDir); + + // Write minimum composer.json + file_put_contents($componentDir . '/composer.json', json_encode([ + 'name' => 'ClientSnippets', + 'description' => 'Component for testing', + 'autoload' => ['psr-4' => ['TestComponent' => 'src']], + 'homepage' => 'https://github.com/googleapis/google-cloud-php-client-snippet', + ])); + // Write minimum repo-metadata.json + file_put_contents($componentDir . '/.repo-metadata.json', json_encode([ + 'release_level' => 'preview', + 'client_documentation' => 'https://github.com/googleapis/google-cloud-php', + 'library_type' => 'GAPIC_AUTO', + ])); + + $application = new Application(); + $application->add(new UpdateReadmeSampleCommand($this->root)); + self::$commandTester = new CommandTester($application->get('update-readme-sample')); + } + + public function testUpdateReadmeSample() + { + self::$commandTester->execute([ + '--component' => ['ClientSnippets'], + ]); + + $this->assertStringContainsString( + "use Google\Cloud\ClientSnippets\V1\Client\ClientSnippetsClient;", + file_get_contents($this->root . '/ClientSnippets/README.md') + ); + } + + public function testUpdateSampleWithNewVersion() + { + $v1SamplePath = $this->root . '/ClientSnippets/samples/v1/ClientSnippetsClient/an_rpc_method.php'; + $v2SampleDir = $this->root . '/ClientSnippets/samples/v2/ClientSnippetsClient'; + $v2Sample = str_replace('V1', 'V2', file_get_contents($v1SamplePath)); + if (!is_dir($v2SampleDir)) { + mkdir($v2SampleDir, 0777, true); + } + file_put_contents($v2SampleDir . '/a_v2_rpc_method.php', $v2Sample); + + // Create mock component so the version shows up + $v2SrcDir = $this->root . '/ClientSnippets/src/V2'; + if (!is_dir($v2SrcDir)) { + mkdir($v2SrcDir, 0777, true); + } + file_put_contents($v2SrcDir . '/.keep', ''); + + self::$commandTester->execute([ + '--component' => ['ClientSnippets'], + ]); + + $readme = file_get_contents($this->root . '/ClientSnippets/README.md'); + $this->assertStringContainsString( + "use Google\Cloud\ClientSnippets\V2\Client\ClientSnippetsClient;", + $readme + ); + } +} diff --git a/dev/tests/fixtures/component/ClientSnippets/README.md b/dev/tests/fixtures/component/ClientSnippets/README.md new file mode 100644 index 000000000000..f8fcbcc58697 --- /dev/null +++ b/dev/tests/fixtures/component/ClientSnippets/README.md @@ -0,0 +1,50 @@ +# Client Snippets for PHP + +> Idiomatic PHP client for [ClientSnippets](https://client-snippets-url.com). + +[![Latest Stable Version](https://poser.pugx.org/google/cloud-client-snippets/v/stable)](https://packagist.org/packages/google/cloud-client-snippets) [![Packagist](https://img.shields.io/packagist/dm/google/cloud-client-snippets.svg)](https://packagist.org/packages/google/cloud-client-snippets) + +* [API documentation](https://client-snippets-url.com/docs) + +**NOTE:** This repository is part of [Google Cloud PHP](https://github.com/googleapis/google-cloud-php). Any +support requests, bug reports, or development contributions should be directed to +that project. + +### Installation + +To begin, install the preferred dependency manager for PHP, [Composer](https://getcomposer.org/). + +Now, install this component: + +```sh +$ composer require google/cloud-client-snippets +``` + +> Browse the complete list of [Google Cloud APIs](https://cloud.google.com/php/docs/reference) +> for PHP + +This component supports both REST over HTTP/1.1 and gRPC. In order to take advantage of the benefits +offered by gRPC (such as streaming methods) please see our +[gRPC installation guide](https://cloud.google.com/php/grpc). + +### Authentication + +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 + +See the [samples directory](https://github.com/googleapis/google-cloud-php-client-snippets/tree/main/samples) for a canonical list of samples. + +### Debugging + +Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) +for more information about the debugging tools. + +### Version + +This component is considered alpha. As such, it is still a work-in-progress and is more likely to get backwards-incompatible updates. + +### Next Steps + +1. Understand the [official documentation](https://client-snippets-url.com). From 05be50379b3c09f1a51c0737d130e2047b6c61c2 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 22 Aug 2025 14:07:52 -0700 Subject: [PATCH 2/5] test cleanup --- .../Command/UpdateReadmeSampleCommandTest.php | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/dev/tests/Unit/Command/UpdateReadmeSampleCommandTest.php b/dev/tests/Unit/Command/UpdateReadmeSampleCommandTest.php index 72a402085274..e0a79f5d9ca7 100644 --- a/dev/tests/Unit/Command/UpdateReadmeSampleCommandTest.php +++ b/dev/tests/Unit/Command/UpdateReadmeSampleCommandTest.php @@ -29,31 +29,30 @@ class UpdateReadmeSampleCommandTest extends TestCase { private static CommandTester $commandTester; - private $root; + private $componentDir; public function setUp(): void { - $this->root = sys_get_temp_dir() . '/google-cloud-php-tests-' . rand(); - $componentDir = $this->root . '/ClientSnippets'; + $this->componentDir = sys_get_temp_dir() . '/google-cloud-php-tests-' . rand() . '/ClientSnippets'; $filesystem = new Filesystem(); - $filesystem->mirror(__DIR__ . '/../../fixtures/component/ClientSnippets', $componentDir); + $filesystem->mirror(__DIR__ . '/../../fixtures/component/ClientSnippets', $this->componentDir); // Write minimum composer.json - file_put_contents($componentDir . '/composer.json', json_encode([ + file_put_contents($this->componentDir . '/composer.json', json_encode([ 'name' => 'ClientSnippets', 'description' => 'Component for testing', 'autoload' => ['psr-4' => ['TestComponent' => 'src']], 'homepage' => 'https://github.com/googleapis/google-cloud-php-client-snippet', ])); // Write minimum repo-metadata.json - file_put_contents($componentDir . '/.repo-metadata.json', json_encode([ + file_put_contents($this->componentDir . '/.repo-metadata.json', json_encode([ 'release_level' => 'preview', 'client_documentation' => 'https://github.com/googleapis/google-cloud-php', 'library_type' => 'GAPIC_AUTO', ])); $application = new Application(); - $application->add(new UpdateReadmeSampleCommand($this->root)); + $application->add(new UpdateReadmeSampleCommand($this->componentDir . '/..')); self::$commandTester = new CommandTester($application->get('update-readme-sample')); } @@ -65,14 +64,14 @@ public function testUpdateReadmeSample() $this->assertStringContainsString( "use Google\Cloud\ClientSnippets\V1\Client\ClientSnippetsClient;", - file_get_contents($this->root . '/ClientSnippets/README.md') + file_get_contents($this->componentDir . '/README.md') ); } public function testUpdateSampleWithNewVersion() { - $v1SamplePath = $this->root . '/ClientSnippets/samples/v1/ClientSnippetsClient/an_rpc_method.php'; - $v2SampleDir = $this->root . '/ClientSnippets/samples/v2/ClientSnippetsClient'; + $v1SamplePath = $this->componentDir . '/samples/v1/ClientSnippetsClient/an_rpc_method.php'; + $v2SampleDir = $this->componentDir . '/samples/v2/ClientSnippetsClient'; $v2Sample = str_replace('V1', 'V2', file_get_contents($v1SamplePath)); if (!is_dir($v2SampleDir)) { mkdir($v2SampleDir, 0777, true); @@ -80,7 +79,7 @@ public function testUpdateSampleWithNewVersion() file_put_contents($v2SampleDir . '/a_v2_rpc_method.php', $v2Sample); // Create mock component so the version shows up - $v2SrcDir = $this->root . '/ClientSnippets/src/V2'; + $v2SrcDir = $this->componentDir . '/src/V2'; if (!is_dir($v2SrcDir)) { mkdir($v2SrcDir, 0777, true); } @@ -90,7 +89,7 @@ public function testUpdateSampleWithNewVersion() '--component' => ['ClientSnippets'], ]); - $readme = file_get_contents($this->root . '/ClientSnippets/README.md'); + $readme = file_get_contents($this->componentDir . '/README.md'); $this->assertStringContainsString( "use Google\Cloud\ClientSnippets\V2\Client\ClientSnippetsClient;", $readme From 14c8efe50edaed06b367ebce3a1f3e0bc38f255d Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 22 Aug 2025 21:21:15 +0000 Subject: [PATCH 3/5] fix file casing in tests --- dev/tests/Unit/Command/UpdateReadmeSampleCommandTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/Unit/Command/UpdateReadmeSampleCommandTest.php b/dev/tests/Unit/Command/UpdateReadmeSampleCommandTest.php index e0a79f5d9ca7..1d7a210c4996 100644 --- a/dev/tests/Unit/Command/UpdateReadmeSampleCommandTest.php +++ b/dev/tests/Unit/Command/UpdateReadmeSampleCommandTest.php @@ -70,8 +70,8 @@ public function testUpdateReadmeSample() public function testUpdateSampleWithNewVersion() { - $v1SamplePath = $this->componentDir . '/samples/v1/ClientSnippetsClient/an_rpc_method.php'; - $v2SampleDir = $this->componentDir . '/samples/v2/ClientSnippetsClient'; + $v1SamplePath = $this->componentDir . '/samples/V1/ClientSnippetsClient/an_rpc_method.php'; + $v2SampleDir = $this->componentDir . '/samples/V2/ClientSnippetsClient'; $v2Sample = str_replace('V1', 'V2', file_get_contents($v1SamplePath)); if (!is_dir($v2SampleDir)) { mkdir($v2SampleDir, 0777, true); From c5b74ae44934047f6a0d7d0ade6511a19da0841f Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 22 Aug 2025 15:57:06 -0700 Subject: [PATCH 4/5] updates from main --- dev/src/Command/AddVersionCommand.php | 8 ++++---- dev/src/Component.php | 9 +++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/dev/src/Command/AddVersionCommand.php b/dev/src/Command/AddVersionCommand.php index d68643726467..18858c6161d2 100644 --- a/dev/src/Command/AddVersionCommand.php +++ b/dev/src/Command/AddVersionCommand.php @@ -117,11 +117,11 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($returnCode !== Command::SUCCESS) { return $returnCode; } - // Run "add-sample-to-readme" command to ensure our README contains the latest version's sample. - $addSamplesArgs = ['--component' => [$componentName], '--update' => true]; - if (!$addSampleCommand = $this->getApplication()->find('add-sample-to-readme')) { + // Run "update-readme-sample" command to ensure our README contains the latest version's sample. + $updateReadmeSampleArgs = ['--component' => [$componentName], '--update' => true]; + if (!$updateReadmeSampleCommand = $this->getApplication()->find('update-readme-sample')) { throw new \RuntimeException('Application does not have an add-samples-to-readme command.'); } - return $addSampleCommand->run(new ArrayInput($addSamplesArgs), $output); + return $updateReadmeSampleCommand->run(new ArrayInput($updateReadmeSampleArgs), $output); } } diff --git a/dev/src/Component.php b/dev/src/Component.php index d33acd5860d8..e3bd9d4d6b3a 100644 --- a/dev/src/Component.php +++ b/dev/src/Component.php @@ -47,9 +47,9 @@ public function __construct(private string $name, ?string $path = null) $this->validateComponentFiles(); } - private static function getComponentNames(string $rootDir): array + private static function getComponentNames(?string $rootDir): array { - $components = scandir($rootDir); + $components = scandir($rootDir ?? self::ROOT_DIR); foreach ($components as $i => $name) { if (!is_dir(self::ROOT_DIR . $name) || !preg_match('/^[A-Z]/', $name)) { unset($components[$i]); @@ -61,12 +61,9 @@ private static function getComponentNames(string $rootDir): array public static function getComponents(array $componentNames = [], ?string $rootDir = null): array { - if (is_null($rootDir)) { - $rootDir = realpath(self::ROOT_DIR); - } $components = []; foreach ($componentNames ?: self::getComponentNames($rootDir) as $name) { - $components[] = new Component($name, $rootDir . '/' . $name); + $components[] = new Component($name, $rootDir ? $rootDir . '/' . $name : null); } return $components; From cbd02c521bf9445b7eb3e19acce82528095e6320 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Mon, 6 Oct 2025 11:41:40 -0700 Subject: [PATCH 5/5] update READMEs for new components --- AppsChat/README.md | 8 ++++---- LocationFinder/README.md | 8 ++++---- SecurityCompliance/README.md | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/AppsChat/README.md b/AppsChat/README.md index 8941e889c5e6..df90b814ce50 100644 --- a/AppsChat/README.md +++ b/AppsChat/README.md @@ -35,10 +35,10 @@ 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; +use Google\ApiCore\ApiException; +use Google\Apps\Chat\V1\Attachment; +use Google\Apps\Chat\V1\Client\ChatServiceClient; +use Google\Apps\Chat\V1\GetAttachmentRequest; // Create a client. $chatServiceClient = new ChatServiceClient(); diff --git a/LocationFinder/README.md b/LocationFinder/README.md index a08d915fd4aa..9a38d2c330f0 100644 --- a/LocationFinder/README.md +++ b/LocationFinder/README.md @@ -35,10 +35,10 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -Google\ApiCore\ApiException; -Google\Cloud\LocationFinder\V1\Client\CloudLocationFinderClient; -Google\Cloud\LocationFinder\V1\CloudLocation; -Google\Cloud\LocationFinder\V1\GetCloudLocationRequest; +use Google\ApiCore\ApiException; +use Google\Cloud\LocationFinder\V1\Client\CloudLocationFinderClient; +use Google\Cloud\LocationFinder\V1\CloudLocation; +use Google\Cloud\LocationFinder\V1\GetCloudLocationRequest; // Create a client. $cloudLocationFinderClient = new CloudLocationFinderClient(); diff --git a/SecurityCompliance/README.md b/SecurityCompliance/README.md index 1569cc9b6b9d..9ba1dd137555 100644 --- a/SecurityCompliance/README.md +++ b/SecurityCompliance/README.md @@ -35,10 +35,10 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Sample ```php -Google\ApiCore\ApiException; -Google\Cloud\CloudSecurityCompliance\V1\Client\ConfigClient; -Google\Cloud\CloudSecurityCompliance\V1\CloudControl; -Google\Cloud\CloudSecurityCompliance\V1\GetCloudControlRequest; +use Google\ApiCore\ApiException; +use Google\Cloud\CloudSecurityCompliance\V1\Client\ConfigClient; +use Google\Cloud\CloudSecurityCompliance\V1\CloudControl; +use Google\Cloud\CloudSecurityCompliance\V1\GetCloudControlRequest; // Create a client. $configClient = new ConfigClient();