Methods

delete

delete(options, callback) returns Promise containing DeleteNotificationResponse

Permanently deletes a notification subscription.

Parameter

options

Optional

object

Configuration options.

callback

Optional

DeleteNotificationCallback

Callback function.

See also

Notifications: delete API Documentation

Returns

Promise containing DeleteNotificationResponse 

Example

var storage = require('@google-cloud/storage')();
var myBucket = storage.bucket('my-bucket');
var notification = myBucket.notification('1');

notification.delete(function(err, apiResponse) {});

//-
// If the callback is omitted, we'll return a Promise.
//-
notification.delete().then(function(data) {
  var apiResponse = data[0];
});

Another example:

// Imports the Google Cloud client library
const Storage = require('@google-cloud/storage');

// Creates a client
const storage = new Storage();

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// const bucketName = 'Name of a bucket, e.g. my-bucket';
// const notificationId = 'ID of notification to delete, e.g. 1';

// Deletes the notification from the bucket
storage
  .bucket(bucketName)
  .notification(notificationId)
  .delete()
  .then(() => {
    console.log(`Notification ${notificationId} deleted.`);
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

get

get(options, callback) returns Promise containing GetNotificationCallback

Get a notification and its metadata if it exists.

Parameter

options

Optional

object

Configuration options. See Bucket#createNotification for create options.

callback

Optional

GetNotificationCallback

Callback function.

See also

Notifications: get API Documentation

Returns

Promise containing GetNotificationCallback 

Example

var storage = require('@google-cloud/storage')();
var myBucket = storage.bucket('my-bucket');
var 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) {
  var notification = data[0];
  var apiResponse = data[1];
});

getMetadata

getMetadata(options, callback) returns Promise containing GetNotificationMetadataResponse

Get the notification's metadata.

Parameter

options

Optional

object

Configuration options.

callback

Optional

GetNotificationMetadataCallback

Callback function.

See also

Notifications: get API Documentation

Returns

Promise containing GetNotificationMetadataResponse 

Example

var storage = require('@google-cloud/storage')();
var myBucket = storage.bucket('my-bucket');
var 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) {
  var metadata = data[0];
  var apiResponse = data[1];
});

Another example:

// Imports the Google Cloud client library
const Storage = require('@google-cloud/storage');

// Creates a client
const storage = new Storage();

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// const bucketName = 'Name of a bucket, e.g. my-bucket';
// const notificationId = 'ID of notification to get, e.g. 1';

// Get the notification metadata
storage
  .bucket(bucketName)
  .notification(notificationId)
  .getMetadata()
  .then(results => {
    const metadata = results[0];

    console.log(`ID: ${metadata.id}`);
    console.log(`Topic: ${metadata.topic}`);
    console.log(`Event Types: ${metadata.event_types}`);
    console.log(`Custom Attributes: ${metadata.custom_attributes}`);
    console.log(`Payload Format: ${metadata.payload_format}`);
    console.log(`Object Name Prefix: ${metadata.object_name_prefix}`);
    console.log(`Etag: ${metadata.etag}`);
    console.log(`Self Link: ${metadata.selfLink}`);
    console.log(`Kind: ${metadata.kind}`);
  })
  .catch(err => {
    console.error('ERROR:', err);
  });