-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(samples): add Video Stitcher slate and CDN key code samples and …
…tests (#6) Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [X] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/nodejs-video-stitcher/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [X] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes b:202972969
- Loading branch information
Showing
12 changed files
with
788 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* Copyright 2022, Google, Inc. | ||
* 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
function main( | ||
projectId, | ||
location, | ||
cdnKeyId, | ||
hostname, | ||
gCdnKeyname, | ||
gCdnPrivateKey, | ||
akamaiTokenKey = '' | ||
) { | ||
// [START video_stitcher_create_cdn_key] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// projectId = 'my-project-id'; | ||
// location = 'us-central1'; | ||
// cdnKeyId = 'my-cdn-key'; | ||
// hostname = 'cdn.example.com'; | ||
// gCdnKeyname = 'gcdn-key'; | ||
// gCdnPrivateKey = 'VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLg=='; | ||
// akamaiTokenKey = 'VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLg=='; | ||
|
||
// Imports the Video Stitcher library | ||
const {VideoStitcherServiceClient} = | ||
require('@google-cloud/video-stitcher').v1; | ||
// Instantiates a client | ||
const stitcherClient = new VideoStitcherServiceClient(); | ||
|
||
async function createCdnKey() { | ||
// Construct request | ||
const request = { | ||
parent: stitcherClient.locationPath(projectId, location), | ||
cdnKey: { | ||
hostname: hostname, | ||
}, | ||
cdnKeyId: cdnKeyId, | ||
}; | ||
|
||
if (akamaiTokenKey !== '') { | ||
request.cdnKey.akamaiCdnKey = { | ||
tokenKey: akamaiTokenKey, | ||
}; | ||
} else { | ||
request.cdnKey.googleCdnKey = { | ||
keyName: gCdnKeyname, | ||
privateKey: gCdnPrivateKey, | ||
}; | ||
} | ||
|
||
const [cdnKey] = await stitcherClient.createCdnKey(request); | ||
console.log(`CDN key: ${cdnKey.name}`); | ||
} | ||
|
||
createCdnKey(); | ||
// [END video_stitcher_create_cdn_key] | ||
} | ||
|
||
// node createCdnKey.js <projectId> <location> <cdnKeyId> <hostname> <gCdnKeyname> <gCdnPrivateKey> <akamaiTokenKey> | ||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Copyright 2022, Google, Inc. | ||
* 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
function main(projectId, location, slateId, slateUri) { | ||
// [START video_stitcher_create_slate] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// projectId = 'my-project-id'; | ||
// location = 'us-central1'; | ||
// slateId = 'my-slate'; | ||
// slateUri = 'https://my-slate-uri/test.mp4'; | ||
|
||
// Imports the Video Stitcher library | ||
const {VideoStitcherServiceClient} = | ||
require('@google-cloud/video-stitcher').v1; | ||
// Instantiates a client | ||
const stitcherClient = new VideoStitcherServiceClient(); | ||
|
||
async function createSlate() { | ||
// Construct request | ||
const request = { | ||
parent: stitcherClient.locationPath(projectId, location), | ||
slate: { | ||
uri: slateUri, | ||
}, | ||
slateId: slateId, | ||
}; | ||
const [slate] = await stitcherClient.createSlate(request); | ||
console.log(`Slate: ${slate.name}`); | ||
} | ||
|
||
createSlate(); | ||
// [END video_stitcher_create_slate] | ||
} | ||
|
||
// node createSlate.js <projectId> <location> <slateId> <slateUri> | ||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright 2022, Google, Inc. | ||
* 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
function main(projectId, location, cdnKeyId) { | ||
// [START video_stitcher_delete_cdn_key] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// projectId = 'my-project-id'; | ||
// location = 'us-central1'; | ||
// cdnKeyId = 'my-cdn-key'; | ||
|
||
// Imports the Video Stitcher library | ||
const {VideoStitcherServiceClient} = | ||
require('@google-cloud/video-stitcher').v1; | ||
// Instantiates a client | ||
const stitcherClient = new VideoStitcherServiceClient(); | ||
|
||
async function deleteCdnKey() { | ||
// Construct request | ||
const request = { | ||
name: stitcherClient.cdnKeyPath(projectId, location, cdnKeyId), | ||
}; | ||
await stitcherClient.deleteCdnKey(request); | ||
console.log('Deleted CDN key'); | ||
} | ||
|
||
deleteCdnKey(); | ||
// [END video_stitcher_delete_cdn_key] | ||
} | ||
|
||
// node deleteCdnKey.js <projectId> <location> <cdnKeyId> | ||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright 2022, Google, Inc. | ||
* 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
function main(projectId, location, slateId) { | ||
// [START video_stitcher_delete_slate] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// projectId = 'my-project-id'; | ||
// location = 'us-central1'; | ||
// slateId = 'my-slate'; | ||
|
||
// Imports the Video Stitcher library | ||
const {VideoStitcherServiceClient} = | ||
require('@google-cloud/video-stitcher').v1; | ||
// Instantiates a client | ||
const stitcherClient = new VideoStitcherServiceClient(); | ||
|
||
async function deleteSlate() { | ||
// Construct request | ||
const request = { | ||
name: stitcherClient.slatePath(projectId, location, slateId), | ||
}; | ||
await stitcherClient.deleteSlate(request); | ||
console.log('Deleted slate'); | ||
} | ||
|
||
deleteSlate(); | ||
// [END video_stitcher_delete_slate] | ||
} | ||
|
||
// node deleteSlate.js <projectId> <location> <slateId> | ||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright 2022, Google, Inc. | ||
* 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
function main(projectId, location, cdnKeyId) { | ||
// [START video_stitcher_get_cdn_key] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// projectId = 'my-project-id'; | ||
// location = 'us-central1'; | ||
// cdnKeyId = 'my-cdn-key'; | ||
|
||
// Imports the Video Stitcher library | ||
const {VideoStitcherServiceClient} = | ||
require('@google-cloud/video-stitcher').v1; | ||
// Instantiates a client | ||
const stitcherClient = new VideoStitcherServiceClient(); | ||
|
||
async function getCdnKey() { | ||
// Construct request | ||
const request = { | ||
name: stitcherClient.cdnKeyPath(projectId, location, cdnKeyId), | ||
}; | ||
const [cdnKey] = await stitcherClient.getCdnKey(request); | ||
console.log(`CDN key: ${cdnKey.name}`); | ||
} | ||
|
||
getCdnKey(); | ||
// [END video_stitcher_get_cdn_key] | ||
} | ||
|
||
// node getCdnKey.js <projectId> <location> <cdnKeyId> | ||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright 2022, Google, Inc. | ||
* 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
function main(projectId, location, slateId) { | ||
// [START video_stitcher_get_slate] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// projectId = 'my-project-id'; | ||
// location = 'us-central1'; | ||
// slateId = 'my-slate'; | ||
|
||
// Imports the Video Stitcher library | ||
const {VideoStitcherServiceClient} = | ||
require('@google-cloud/video-stitcher').v1; | ||
// Instantiates a client | ||
const stitcherClient = new VideoStitcherServiceClient(); | ||
|
||
async function getSlate() { | ||
// Construct request | ||
const request = { | ||
name: stitcherClient.slatePath(projectId, location, slateId), | ||
}; | ||
const [slate] = await stitcherClient.getSlate(request); | ||
console.log(`Slate: ${slate.name}`); | ||
} | ||
|
||
getSlate(); | ||
// [END video_stitcher_get_slate] | ||
} | ||
|
||
// node getSlate.js <projectId> <location> <slateId> | ||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright 2022, Google, Inc. | ||
* 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
function main(projectId, location) { | ||
// [START video_stitcher_list_cdn_keys] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// projectId = 'my-project-id'; | ||
// location = 'us-central1'; | ||
|
||
// Imports the Video Stitcher library | ||
const {VideoStitcherServiceClient} = | ||
require('@google-cloud/video-stitcher').v1; | ||
// Instantiates a client | ||
const stitcherClient = new VideoStitcherServiceClient(); | ||
|
||
async function listCdnKeys() { | ||
const iterable = await stitcherClient.listCdnKeysAsync({ | ||
parent: stitcherClient.locationPath(projectId, location), | ||
}); | ||
console.info('CDN keys:'); | ||
for await (const response of iterable) { | ||
console.log(response.name); | ||
} | ||
} | ||
|
||
listCdnKeys(); | ||
// [END video_stitcher_list_cdn_keys] | ||
} | ||
|
||
// node listCdnKeys.js <projectId> <location> | ||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
Oops, something went wrong.