Skip to content

Commit

Permalink
chore: introduce functions samples
Browse files Browse the repository at this point in the history
  • Loading branch information
dwsupplee committed Jun 23, 2022
1 parent a603318 commit fd5386a
Show file tree
Hide file tree
Showing 11 changed files with 497 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Functions/samples/V1/CloudFunctionsServiceClient/call_function.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once '../../../vendor/autoload.php';

// [START cloudfunctions_v1_generated_CloudFunctionsService_CallFunction_sync]
use Google\Cloud\Functions\V1\CloudFunctionsServiceClient;

$cloudFunctionsServiceClient = new CloudFunctionsServiceClient();
try {
$formattedName = $cloudFunctionsServiceClient->cloudFunctionName('[PROJECT]', '[LOCATION]', '[FUNCTION]');
$data = 'data';
$response = $cloudFunctionsServiceClient->callFunction($formattedName, $data);
} finally {
$cloudFunctionsServiceClient->close();
}

// [END cloudfunctions_v1_generated_CloudFunctionsService_CallFunction_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once '../../../vendor/autoload.php';

// [START cloudfunctions_v1_generated_CloudFunctionsService_CreateFunction_sync]
use Google\Cloud\Functions\V1\CloudFunction;
use Google\Cloud\Functions\V1\CloudFunctionsServiceClient;

$cloudFunctionsServiceClient = new CloudFunctionsServiceClient();
try {
$formattedLocation = $cloudFunctionsServiceClient->locationName('[PROJECT]', '[LOCATION]');
$function = new CloudFunction();
$operationResponse = $cloudFunctionsServiceClient->createFunction($formattedLocation, $function);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
$result = $operationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $operationResponse->getError();
// handleError($error)
}

// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $cloudFunctionsServiceClient->createFunction($formattedLocation, $function);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $cloudFunctionsServiceClient->resumeOperation($operationName, 'createFunction');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}

if ($newOperationResponse->operationSucceeded()) {
$result = $newOperationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}

} finally {
$cloudFunctionsServiceClient->close();
}

// [END cloudfunctions_v1_generated_CloudFunctionsService_CreateFunction_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once '../../../vendor/autoload.php';

// [START cloudfunctions_v1_generated_CloudFunctionsService_DeleteFunction_sync]
use Google\Cloud\Functions\V1\CloudFunctionsServiceClient;

$cloudFunctionsServiceClient = new CloudFunctionsServiceClient();
try {
$formattedName = $cloudFunctionsServiceClient->cloudFunctionName('[PROJECT]', '[LOCATION]', '[FUNCTION]');
$operationResponse = $cloudFunctionsServiceClient->deleteFunction($formattedName);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// operation succeeded and returns no value
} else {
$error = $operationResponse->getError();
// handleError($error)
}

// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $cloudFunctionsServiceClient->deleteFunction($formattedName);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $cloudFunctionsServiceClient->resumeOperation($operationName, 'deleteFunction');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}

if ($newOperationResponse->operationSucceeded()) {
// operation succeeded and returns no value
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}

} finally {
$cloudFunctionsServiceClient->close();
}

// [END cloudfunctions_v1_generated_CloudFunctionsService_DeleteFunction_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once '../../../vendor/autoload.php';

// [START cloudfunctions_v1_generated_CloudFunctionsService_GenerateDownloadUrl_sync]
use Google\Cloud\Functions\V1\CloudFunctionsServiceClient;

$cloudFunctionsServiceClient = new CloudFunctionsServiceClient();
try {
$response = $cloudFunctionsServiceClient->generateDownloadUrl();
} finally {
$cloudFunctionsServiceClient->close();
}

// [END cloudfunctions_v1_generated_CloudFunctionsService_GenerateDownloadUrl_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once '../../../vendor/autoload.php';

// [START cloudfunctions_v1_generated_CloudFunctionsService_GenerateUploadUrl_sync]
use Google\Cloud\Functions\V1\CloudFunctionsServiceClient;

$cloudFunctionsServiceClient = new CloudFunctionsServiceClient();
try {
$response = $cloudFunctionsServiceClient->generateUploadUrl();
} finally {
$cloudFunctionsServiceClient->close();
}

// [END cloudfunctions_v1_generated_CloudFunctionsService_GenerateUploadUrl_sync]
36 changes: 36 additions & 0 deletions Functions/samples/V1/CloudFunctionsServiceClient/get_function.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once '../../../vendor/autoload.php';

// [START cloudfunctions_v1_generated_CloudFunctionsService_GetFunction_sync]
use Google\Cloud\Functions\V1\CloudFunctionsServiceClient;

$cloudFunctionsServiceClient = new CloudFunctionsServiceClient();
try {
$formattedName = $cloudFunctionsServiceClient->cloudFunctionName('[PROJECT]', '[LOCATION]', '[FUNCTION]');
$response = $cloudFunctionsServiceClient->getFunction($formattedName);
} finally {
$cloudFunctionsServiceClient->close();
}

// [END cloudfunctions_v1_generated_CloudFunctionsService_GetFunction_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once '../../../vendor/autoload.php';

// [START cloudfunctions_v1_generated_CloudFunctionsService_GetIamPolicy_sync]
use Google\Cloud\Functions\V1\CloudFunctionsServiceClient;

$cloudFunctionsServiceClient = new CloudFunctionsServiceClient();
try {
$resource = 'resource';
$response = $cloudFunctionsServiceClient->getIamPolicy($resource);
} finally {
$cloudFunctionsServiceClient->close();
}

// [END cloudfunctions_v1_generated_CloudFunctionsService_GetIamPolicy_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once '../../../vendor/autoload.php';

// [START cloudfunctions_v1_generated_CloudFunctionsService_ListFunctions_sync]
use Google\Cloud\Functions\V1\CloudFunctionsServiceClient;

$cloudFunctionsServiceClient = new CloudFunctionsServiceClient();
try {
// Iterate over pages of elements
$pagedResponse = $cloudFunctionsServiceClient->listFunctions();
foreach ($pagedResponse->iteratePages() as $page) {
foreach ($page as $element) {
// doSomethingWith($element);
}

}

// Alternatively:
// Iterate through all elements
$pagedResponse = $cloudFunctionsServiceClient->listFunctions();
foreach ($pagedResponse->iterateAllElements() as $element) {
// doSomethingWith($element);
}

} finally {
$cloudFunctionsServiceClient->close();
}

// [END cloudfunctions_v1_generated_CloudFunctionsService_ListFunctions_sync]
Loading

0 comments on commit fd5386a

Please sign in to comment.