-
Notifications
You must be signed in to change notification settings - Fork 598
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add real time feed api sample code (#184)
- Loading branch information
1 parent
e4033ce
commit d02f8ab
Showing
5 changed files
with
260 additions
and
0 deletions.
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,60 @@ | ||
/** | ||
* Copyright 2019, 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'; | ||
|
||
// sample-metadata: | ||
// title: Create Feed | ||
// description: Create Feed. | ||
// usage: node createFeed <FEED_ID> "//storage.googleapis.com/<BUCKET_NAME>", projects/<PROJECT_ID>/topics/<TOPIC_ID> | ||
|
||
async function main(feedId, assetNames, topicName) { | ||
// [START asset_quickstart_create_feed] | ||
const util = require('util'); | ||
const {AssetServiceClient} = require('@google-cloud/asset/src/v1p2beta1'); | ||
|
||
const client = new AssetServiceClient(); | ||
|
||
async function createFeed() { | ||
const projectId = await client.getProjectId(); | ||
// TODO(developer): Choose asset names, such as //storage.googleapis.com/[YOUR_BUCKET_NAME]. | ||
// const assetNames = ['ASSET_NAME1', 'ASSET_NAME2', ...]; | ||
|
||
const request = { | ||
parent: `projects/${projectId}`, | ||
feedId: feedId, | ||
feed: { | ||
assetNames: assetNames.split(','), | ||
feedOutputConfig: { | ||
pubsubDestination: { | ||
topic: topicName, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
// Handle the operation using the promise pattern. | ||
const result = await client.createFeed(request); | ||
// Do things with with the response. | ||
console.log(util.inspect(result, {depth: null})); | ||
// [END asset_quickstart_create_feed] | ||
} | ||
createFeed(); | ||
} | ||
|
||
main(...process.argv.slice(2)).catch(err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); |
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,47 @@ | ||
/** | ||
* Copyright 2019, 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'; | ||
|
||
// sample-metadata: | ||
// title: Delete Feed | ||
// description: Delete Feed. | ||
// usage: node deleteFeed "project/<PROJECT_NUMBER>/feeds/<FEED_ID>" | ||
|
||
async function main(feedName) { | ||
// [START asset_quickstart_delete_feed] | ||
const util = require('util'); | ||
const {AssetServiceClient} = require('@google-cloud/asset/src/v1p2beta1'); | ||
|
||
const client = new AssetServiceClient(); | ||
|
||
async function deleteFeed() { | ||
const request = { | ||
name: feedName, | ||
}; | ||
|
||
// Handle the operation using the promise pattern. | ||
const result = await client.deleteFeed(request); | ||
// Do things with with the response. | ||
console.log(util.inspect(result, {depth: null})); | ||
// [END asset_quickstart_delete_feed] | ||
} | ||
deleteFeed(); | ||
} | ||
|
||
main(...process.argv.slice(2)).catch(err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); |
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,47 @@ | ||
/** | ||
* Copyright 2019, 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'; | ||
|
||
// sample-metadata: | ||
// title: Get Feed | ||
// description: Get Feed. | ||
// usage: node getFeed "project/<PROJECT_NUMBER>/feeds/<FEED_ID>" | ||
|
||
async function main(feedName) { | ||
// [START asset_quickstart_get_feed] | ||
const util = require('util'); | ||
const {AssetServiceClient} = require('@google-cloud/asset/src/v1p2beta1'); | ||
|
||
const client = new AssetServiceClient(); | ||
|
||
async function getFeed() { | ||
const request = { | ||
name: feedName, | ||
}; | ||
|
||
// Handle the operation using the promise pattern. | ||
const result = await client.getFeed(request); | ||
// Do things with with the response. | ||
console.log(util.inspect(result, {depth: null})); | ||
// [END asset_quickstart_get_feed] | ||
} | ||
getFeed(); | ||
} | ||
|
||
main(...process.argv.slice(2)).catch(err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); |
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,49 @@ | ||
/** | ||
* Copyright 2019, 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'; | ||
|
||
// sample-metadata: | ||
// title: List Feeds | ||
// description: List Feeds. | ||
// usage: node listFeeds | ||
|
||
async function main() { | ||
// [START asset_quickstart_list_feeds] | ||
const util = require('util'); | ||
const {AssetServiceClient} = require('@google-cloud/asset/src/v1p2beta1'); | ||
|
||
const client = new AssetServiceClient(); | ||
|
||
async function listFeeds() { | ||
const projectId = await client.getProjectId(); | ||
|
||
const request = { | ||
parent: `projects/${projectId}`, | ||
}; | ||
|
||
// Handle the operation using the promise pattern. | ||
const result = await client.listFeeds(request); | ||
// Do things with with the response. | ||
console.log(util.inspect(result, {depth: null})); | ||
// [END asset_quickstart_list_feeds] | ||
} | ||
listFeeds(); | ||
} | ||
|
||
main(...process.argv.slice(2)).catch(err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); |
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,57 @@ | ||
/** | ||
* Copyright 2019, 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'; | ||
|
||
// sample-metadata: | ||
// title: Update Feed | ||
// description: Update Feed. | ||
// usage: node updateFeed "project/<PROJECT_NUMBER>/feeds/<FEED_ID>" projects/<PROJECT_ID>/topics/<TOPIC_ID> | ||
|
||
async function main(feedName, topicName) { | ||
// [START asset_quickstart_update_feed] | ||
const util = require('util'); | ||
const {AssetServiceClient} = require('@google-cloud/asset/src/v1p2beta1'); | ||
|
||
const client = new AssetServiceClient(); | ||
|
||
async function updateFeed() { | ||
const request = { | ||
feed: { | ||
name: feedName, | ||
feedOutputConfig: { | ||
pubsubDestination: { | ||
topic: topicName, | ||
}, | ||
}, | ||
}, | ||
updateMask: { | ||
paths: ['feed_output_config.pubsub_destination.topic'], | ||
}, | ||
}; | ||
|
||
// Handle the operation using the promise pattern. | ||
const result = await client.updateFeed(request); | ||
// Do things with with the response. | ||
console.log(util.inspect(result, {depth: null})); | ||
// [END asset_quickstart_update_feed] | ||
} | ||
updateFeed(); | ||
} | ||
|
||
main(...process.argv.slice(2)).catch(err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); |