Skip to content

Commit 16f7498

Browse files
authored
feat(LiveStream): add samples and tests for assets and pools (#1909)
1 parent ad2b877 commit 16f7498

File tree

8 files changed

+518
-1
lines changed

8 files changed

+518
-1
lines changed

media/livestream/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"name": "google/live-stream-sample",
33
"type": "project",
44
"require": {
5-
"google/cloud-video-live-stream": "^0.5.0"
5+
"google/cloud-video-live-stream": "^0.6.0"
66
}
77
}

media/livestream/src/create_asset.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2023 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/livestream/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\LiveStream;
26+
27+
// [START livestream_create_asset]
28+
use Google\Cloud\Video\LiveStream\V1\Asset;
29+
use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient;
30+
use Google\Cloud\Video\LiveStream\V1\CreateAssetRequest;
31+
32+
/**
33+
* Creates an asset. You can use an asset to create a slate.
34+
*
35+
* @param string $callingProjectId The project ID to run the API call under
36+
* @param string $location The location of the asset
37+
* @param string $assetId The ID of the asset to be created
38+
* @param string $assetUri The Cloud Storage URI of the asset
39+
*/
40+
function create_asset(
41+
string $callingProjectId,
42+
string $location,
43+
string $assetId,
44+
string $assetUri
45+
): void {
46+
// Instantiate a client.
47+
$livestreamClient = new LivestreamServiceClient();
48+
49+
$parent = $livestreamClient->locationName($callingProjectId, $location);
50+
$asset = (new Asset())
51+
->setVideo(
52+
(new Asset\VideoAsset())
53+
->setUri($assetUri));
54+
55+
// Run the asset creation request. The response is a long-running operation ID.
56+
$request = (new CreateAssetRequest())
57+
->setParent($parent)
58+
->setAsset($asset)
59+
->setAssetId($assetId);
60+
$operationResponse = $livestreamClient->createAsset($request);
61+
$operationResponse->pollUntilComplete();
62+
if ($operationResponse->operationSucceeded()) {
63+
$result = $operationResponse->getResult();
64+
// Print results
65+
printf('Asset: %s' . PHP_EOL, $result->getName());
66+
} else {
67+
$error = $operationResponse->getError();
68+
// handleError($error)
69+
}
70+
}
71+
// [END livestream_create_asset]
72+
73+
// The following 2 lines are only needed to run the samples
74+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
75+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

media/livestream/src/delete_asset.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2023 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/livestream/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\LiveStream;
26+
27+
// [START livestream_delete_asset]
28+
use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient;
29+
use Google\Cloud\Video\LiveStream\V1\DeleteAssetRequest;
30+
31+
/**
32+
* Deletes an asset.
33+
*
34+
* @param string $callingProjectId The project ID to run the API call under
35+
* @param string $location The location of the asset
36+
* @param string $assetId The ID of the asset to be deleted
37+
*/
38+
function delete_asset(
39+
string $callingProjectId,
40+
string $location,
41+
string $assetId
42+
): void {
43+
// Instantiate a client.
44+
$livestreamClient = new LivestreamServiceClient();
45+
$formattedName = $livestreamClient->assetName($callingProjectId, $location, $assetId);
46+
47+
// Run the asset deletion request. The response is a long-running operation ID.
48+
$request = (new DeleteAssetRequest())
49+
->setName($formattedName);
50+
$operationResponse = $livestreamClient->deleteAsset($request);
51+
$operationResponse->pollUntilComplete();
52+
if ($operationResponse->operationSucceeded()) {
53+
// Print status
54+
printf('Deleted asset %s' . PHP_EOL, $assetId);
55+
} else {
56+
$error = $operationResponse->getError();
57+
// handleError($error)
58+
}
59+
}
60+
// [END livestream_delete_asset]
61+
62+
// The following 2 lines are only needed to run the samples
63+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
64+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

media/livestream/src/get_asset.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2023 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/livestream/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\LiveStream;
26+
27+
// [START livestream_get_asset]
28+
use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient;
29+
use Google\Cloud\Video\LiveStream\V1\GetAssetRequest;
30+
31+
/**
32+
* Gets an asset.
33+
*
34+
* @param string $callingProjectId The project ID to run the API call under
35+
* @param string $location The location of the asset
36+
* @param string $assetId The ID of the asset
37+
*/
38+
function get_asset(
39+
string $callingProjectId,
40+
string $location,
41+
string $assetId
42+
): void {
43+
// Instantiate a client.
44+
$livestreamClient = new LivestreamServiceClient();
45+
$formattedName = $livestreamClient->assetName($callingProjectId, $location, $assetId);
46+
47+
// Get the asset.
48+
$request = (new GetAssetRequest())
49+
->setName($formattedName);
50+
$response = $livestreamClient->getAsset($request);
51+
// Print results
52+
printf('Asset: %s' . PHP_EOL, $response->getName());
53+
}
54+
// [END livestream_get_asset]
55+
56+
// The following 2 lines are only needed to run the samples
57+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
58+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

media/livestream/src/get_pool.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2023 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/livestream/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\LiveStream;
26+
27+
// [START livestream_get_pool]
28+
use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient;
29+
use Google\Cloud\Video\LiveStream\V1\GetPoolRequest;
30+
31+
/**
32+
* Gets a pool.
33+
*
34+
* @param string $callingProjectId The project ID to run the API call under
35+
* @param string $location The location of the pool
36+
* @param string $poolId The ID of the pool
37+
*/
38+
function get_pool(
39+
string $callingProjectId,
40+
string $location,
41+
string $poolId
42+
): void {
43+
// Instantiate a client.
44+
$livestreamClient = new LivestreamServiceClient();
45+
$formattedName = $livestreamClient->poolName($callingProjectId, $location, $poolId);
46+
47+
// Get the pool.
48+
$request = (new GetPoolRequest())
49+
->setName($formattedName);
50+
$response = $livestreamClient->getPool($request);
51+
// Print results
52+
printf('Pool: %s' . PHP_EOL, $response->getName());
53+
}
54+
// [END livestream_get_pool]
55+
56+
// The following 2 lines are only needed to run the samples
57+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
58+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

media/livestream/src/list_assets.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2023 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/livestream/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\LiveStream;
26+
27+
// [START livestream_list_assets]
28+
use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient;
29+
use Google\Cloud\Video\LiveStream\V1\ListAssetsRequest;
30+
31+
/**
32+
* Lists the assets for a given location.
33+
*
34+
* @param string $callingProjectId The project ID to run the API call under
35+
* @param string $location The location of the assets
36+
*/
37+
function list_assets(
38+
string $callingProjectId,
39+
string $location
40+
): void {
41+
// Instantiate a client.
42+
$livestreamClient = new LivestreamServiceClient();
43+
$parent = $livestreamClient->locationName($callingProjectId, $location);
44+
$request = (new ListAssetsRequest())
45+
->setParent($parent);
46+
47+
$response = $livestreamClient->listAssets($request);
48+
// Print the asset list.
49+
$assets = $response->iterateAllElements();
50+
print('Assets:' . PHP_EOL);
51+
foreach ($assets as $asset) {
52+
printf('%s' . PHP_EOL, $asset->getName());
53+
}
54+
}
55+
// [END livestream_list_assets]
56+
57+
// The following 2 lines are only needed to run the samples
58+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
59+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

0 commit comments

Comments
 (0)