-
Notifications
You must be signed in to change notification settings - Fork 1k
Add real time feed api sample code #1007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,19 @@ | ||
| { | ||
| "require": { | ||
| "google/cloud-storage": "^1.9", | ||
| "google/cloud-asset": "^0.4.0", | ||
| "google/cloud-pubsub": "^1.11.1", | ||
| "google/cloud-asset": "^0.5.0", | ||
| "symfony/console": " ^3.0" | ||
| }, | ||
| "autoload": { | ||
| "files": [ | ||
| "src/export_assets.php", | ||
| "src/batch_get_assets_history.php" | ||
| "src/batch_get_assets_history.php", | ||
| "src/create_feed.php", | ||
| "src/get_feed.php", | ||
| "src/list_feeds.php", | ||
| "src/delete_feed.php", | ||
| "src/update_feed.php" | ||
| ] | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| <?php | ||
| /** | ||
| * Copyright 2020 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 | ||
| * | ||
| * 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. | ||
| */ | ||
|
|
||
| namespace Google\Cloud\Samples\Asset; | ||
|
|
||
| # [START asset_quickstart_create_feed] | ||
| use Google\Cloud\Asset\V1\AssetServiceClient; | ||
| use Google\Cloud\Asset\V1\Feed; | ||
| use Google\Cloud\Asset\V1\FeedOutputConfig; | ||
| use Google\Cloud\Asset\V1\PubsubDestination; | ||
|
|
||
| /** | ||
| * Create a real time feed. | ||
| */ | ||
| function create_feed($parent, $feedId, $topic, $assetNames) | ||
| { | ||
| $client = new AssetServiceClient(); | ||
|
|
||
| $feed = new Feed(); | ||
| $feedOutputConfig = new FeedOutputConfig(); | ||
| $pubsubDestination = new PubsubDestination(); | ||
| $pubsubDestination->setTopic($topic); | ||
| $feedOutputConfig->setPubsubDestination($pubsubDestination); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, but let's have this ordered better, like this: $pubsubDestination = (new PubsubDestination())
->setTopic($topic);
$feedOutputConfig = (new FeedOutputConfig())
->setPubsubDestination($pubsubDestination);
$feed = (new Feed())
->setAssetNames($assetNames)
->setFeedOutputConfig($feedOutputConfig); |
||
| $feed->setAssetNames($assetNames); | ||
| $feed->setFeedOutputConfig($feedOutputConfig); | ||
|
|
||
| $createdFeed = $client->CreateFeed($parent, $feedId, $feed); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. casing should be |
||
|
|
||
| echo $createdFeed->getName(); | ||
| } | ||
| # [END asset_quickstart_create_feed] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?php | ||
| /** | ||
| * Copyright 2020 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 | ||
| * | ||
| * 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. | ||
| */ | ||
|
|
||
| namespace Google\Cloud\Samples\Asset; | ||
|
|
||
| # [START asset_quickstart_delete_feed] | ||
| use Google\Cloud\Asset\V1\AssetServiceClient; | ||
|
|
||
| /** | ||
| * Get real time feed given its name. | ||
| */ | ||
| function delete_feed($feedName) | ||
| { | ||
| $client = new AssetServiceClient(); | ||
|
|
||
| $client->DeleteFeed($feedName); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. casing should be |
||
|
|
||
| echo 'Feed deleted'; | ||
| } | ||
| # [END asset_quickstart_delete_feed] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?php | ||
| /** | ||
| * Copyright 2020 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 | ||
| * | ||
| * 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. | ||
| */ | ||
|
|
||
| namespace Google\Cloud\Samples\Asset; | ||
|
|
||
| # [START asset_quickstart_create_feed] | ||
| use Google\Cloud\Asset\V1\AssetServiceClient; | ||
|
|
||
| /** | ||
| * Get real time feed given its name. | ||
| */ | ||
| function get_feed($feedName) | ||
| { | ||
| $client = new AssetServiceClient(); | ||
|
|
||
| $feed = $client->GetFeed($feedName); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. casing should be |
||
|
|
||
| echo 'Feed ' . $feed->getName() . ' got.'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not read well. Should be: printf('Got feed "%s".', $feed->getName()); |
||
| } | ||
| # [END asset_quickstart_get_feed] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?php | ||
| /** | ||
| * Copyright 2020 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 | ||
| * | ||
| * 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. | ||
| */ | ||
|
|
||
| namespace Google\Cloud\Samples\Asset; | ||
|
|
||
| # [START asset_quickstart_list_feeds] | ||
| use Google\Cloud\Asset\V1\AssetServiceClient; | ||
|
|
||
| /** | ||
| * List real time feeds sgiven their parents. | ||
| */ | ||
| function list_feeds($parent) | ||
| { | ||
| $client = new AssetServiceClient(); | ||
|
|
||
| $feed = $client->ListFeeds($parent); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. casing should be |
||
|
|
||
| echo 'Feeds listed'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No feeds were actually listed, would probably make more sense like this: $feeds = $client->listFeeds($parent);
printf('Feeds for %s:' . PHP_EOL, $parent);
foreach ($feeds as $feed) {
print($feed->getName() . PHP_EOL);
} |
||
| } | ||
| # [END asset_quickstart_list_feeds] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <?php | ||
| /** | ||
| * Copyright 2020 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 | ||
| * | ||
| * 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. | ||
| */ | ||
|
|
||
| namespace Google\Cloud\Samples\Asset; | ||
|
|
||
| # [START asset_quickstart_create_feed] | ||
| use Google\Cloud\Asset\V1\AssetServiceClient; | ||
| use Google\Cloud\Asset\V1\Feed; | ||
| use Google\Protobuf\FieldMask; | ||
|
|
||
| /** | ||
| * Create a real time feed. | ||
| */ | ||
| function update_feed($feedName, $assetNames) | ||
| { | ||
| $client = new AssetServiceClient(); | ||
|
|
||
| $new_feed = new Feed(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's be consistent with our casing and make this variable |
||
| $new_feed->setName($feedName); | ||
| $new_feed->setAssetNames($assetNames); | ||
| $updateMask = new FieldMask(); | ||
| $updateMask->setPaths(['asset_names']); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar issue here, let's format these like follows: $newFeed = (new Feed())
->setName($feedName)
->setAssetNames($assetNames);
$updateMask = (new FieldMask())
->setPaths(['asset_names']); |
||
|
|
||
| $updated_feed = $client->UpdateFeed($new_feed, $updateMask); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. casing should be |
||
|
|
||
| echo 'Feed Updated ' . $updated_feed; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make this |
||
| } | ||
| # [END asset_quickstart_create_feed] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: whitespace here