Notification
Source: notification.
A Notification object is created from your Bucket object using Bucket#notification. Use it to interact with Cloud Pub/Sub notifications.
Methods
delete([options][, callback]) → Promise containing DeleteNotificationResponse
Permanently deletes a notification subscription.
Examples
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const myBucket = storage.bucket('my-bucket');
const notification = myBucket.notification('1');
notification.delete(function(err, apiResponse) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
notification.delete().then(function(data) {
const apiResponse = data[0];
});
include:samples/notifications.js
region_tag:storage_delete_notification
Another example:
Parameters
Name | Type | Optional | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Yes |
Configuration options. Values in
|
||||||||
callback |
DeleteNotificationCallback |
Yes |
Callback function. |
- See also
- Returns
-
Promise containing DeleteNotificationResponse
exists(topic[, options][, callback]) → Promise containing CreateNotificationResponse
Creates a notification subscription for the bucket.
Example
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const myBucket = storage.bucket('my-bucket');
const notification = myBucket.notification('1');
notification.create(function(err, notification, apiResponse) {
if (!err) {
// The notification was created successfully.
}
});
//-
// If the callback is omitted, we'll return a Promise.
//-
notification.create().then(function(data) {
const notification = data[0];
const apiResponse = data[1];
});
Parameters
Name | Type | Optional | Description |
---|---|---|---|
topic |
(Topic or string) |
|
The Cloud PubSub topic to which this subscription publishes. If the project ID is omitted, the current project ID will be used.
|
options |
CreateNotificationRequest |
Yes |
Metadata to set for the notification. |
callback |
Yes |
Callback function. |
- See also
- Throws
-
Error
If a valid topic is not provided.
- Returns
-
Promise containing CreateNotificationResponse
exists([callback]) → Promise containing NotificationExistsResponse
Check if the notification exists.
Example
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const myBucket = storage.bucket('my-bucket');
const notification = myBucket.notification('1');
notification.exists(function(err, exists) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
notification.exists().then(function(data) {
const exists = data[0];
});
Parameter
Name | Type | Optional | Description |
---|---|---|---|
callback |
Yes |
Callback function. |
- Returns
-
Promise containing NotificationExistsResponse
get([options][, callback]) → Promise containing GetNotificationCallback
Get a notification and its metadata if it exists.
Example
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const myBucket = storage.bucket('my-bucket');
const notification = myBucket.notification('1');
notification.get(function(err, notification, apiResponse) {
// `notification.metadata` has been populated.
});
//-
// If the callback is omitted, we'll return a Promise.
//-
notification.get().then(function(data) {
const notification = data[0];
const apiResponse = data[1];
});
Parameters
Name | Type | Optional | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Yes |
Configuration options. See Bucket#createNotification for create options. Values in
|
||||||||||||
callback |
GetNotificationCallback |
Yes |
Callback function. |
- See also
- Returns
-
Promise containing GetNotificationCallback
getMetadata([options][, callback]) → Promise containing GetNotificationMetadataResponse
Get the notification's metadata.
Examples
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const myBucket = storage.bucket('my-bucket');
const notification = myBucket.notification('1');
notification.getMetadata(function(err, metadata, apiResponse) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
notification.getMetadata().then(function(data) {
const metadata = data[0];
const apiResponse = data[1];
});
include:samples/notifications.js
region_tag:storage_notifications_get_metadata
Another example:
Parameters
Name | Type | Optional | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Yes |
Configuration options. Values in
|
||||||||
callback |
GetNotificationMetadataCallback |
Yes |
Callback function. |
- See also
- Returns
-
Promise containing GetNotificationMetadataResponse