class Glass::Subscription
A subscription to events on a collection.
Constants
- LOCATIONS
- TIMELINE
Attributes
The type of resource. This is always mirror#subscription.
The URL where notifications should be delivered (must start with https://).
The collection to subscribe to. Allowed values are:
timeline - Changes in the timeline including insertion, deletion, and updates. locations - Location updates.
The ID of the subscription.
The Mirror
Api
Container object for notifications. This is not populated in the Subscription
resource.
A list of operations that should be subscribed to. An empty list indicates that all operations on the collection should be subscribed to. Allowed values are:
UPDATE - The item has been updated. INSERT - A new item has been inserted. DELETE - The item has been deleted.
The time at which this subscription was last modified, formatted according to RFC 3339.
An opaque token sent to the subscriber in notifications so that it can determine the ID of the user.
A secret token sent to the subscriber in notifications so that it can verify that the notification was generated by Google.
Public Class Methods
Subscribe to notifications for the current user.
@param [Google::APIClient] client
Authorized client instance.
@param [String] collection
Collection to subscribe to (supported values are "timeline" and "locations").
@param [String] user_token
Opaque token used by the Glassware to identify the user the notification pings are sent for (recommended).
@param [String] verify_token
Opaque token used by the Glassware to verify that the notification pings are sent by the API (optional).
@param [String] callback_url
URL receiving notification pings (must be HTTPS).
@param [Array] operation
List of operations to subscribe to. Valid values are "UPDATE", "INSERT" and "DELETE" or nil to subscribe to all.
@return nil
# File lib/glass/subscriptions/subscription.rb, line 32 def subscribe(mirror, collection, user_token, verify_token, callback_url, operation) subscription = mirror.subscriptions.insert.request_schema.new({ 'collection' => collection, 'userToken' => user_token, 'verifyToken' => verify_token, 'callbackUrl' => callback_url, 'operation' => operation}) result = client.execute( :api_method => mirror.subscriptions.insert, :body_object => subscription) if result.error? puts "An error occurred: #{result.data['error']['message']}" end end
Delete a subscription to a collection.
@param [Google::APIClient] client
Authorized client instance.
@param [String] collection
Collection to unsubscribe from (supported values are "timeline" and "locations").
@return nil
# File lib/glass/subscriptions/subscription.rb, line 56 def unsubscribe_from_notifications(client, collection) mirror = client.discovered_api('mirror', 'v1') result = client.execute( :api_method => mirror.subscriptions.delete, :parameters => { 'id' => collection }) if result.error? puts "An error occurred: #{result.data['error']['message']}" end end