Class: Glass::Subscription
- Inherits:
-
Object
- Object
- Glass::Subscription
- Defined in:
- lib/glass/subscriptions/subscription.rb
Overview
A subscription to events on a collection.
Defined Under Namespace
Classes: Notification
Constant Summary collapse
- TIMELINE =
"timeline"- LOCATIONS =
"locations"- @@kind =
MIRROR+"#"+SUBSCRIPTION
Class Attribute Summary collapse
-
.kind ⇒ Object
The type of resource.
Instance Attribute Summary collapse
-
#callbackUrl ⇒ Object
The URL where notifications should be delivered (must start with https://).
-
#collection ⇒ Object
The collection to subscribe to.
-
#id ⇒ Object
The ID of the subscription.
-
#mirror ⇒ Object
The Mirror Api.
-
#notification ⇒ Object
Container object for notifications.
-
#operation ⇒ Object
A list of operations that should be subscribed to.
-
#updated ⇒ Object
The time at which this subscription was last modified, formatted according to RFC 3339.
-
#userToken ⇒ Object
An opaque token sent to the subscriber in notifications so that it can determine the ID of the user.
-
#verifyToken ⇒ Object
A secret token sent to the subscriber in notifications so that it can verify that the notification was generated by Google.
Class Method Summary collapse
-
.subscribe(mirror, collection, user_token, verify_token, callback_url, operation) ⇒ Object
Subscribe to notifications for the current user.
-
.unsubscribe_from_notifications(client, collection) ⇒ Object
Delete a subscription to a collection.
Class Attribute Details
.kind ⇒ Object
The type of resource. This is always mirror#subscription.
11 12 13 |
# File 'lib/glass/subscriptions/subscription.rb', line 11 def kind @kind end |
Instance Attribute Details
#callbackUrl ⇒ Object
The URL where notifications should be delivered (must start with https://).
104 105 106 |
# File 'lib/glass/subscriptions/subscription.rb', line 104 def callbackUrl @callbackUrl end |
#collection ⇒ Object
The collection to subscribe to. Allowed values are:
timeline - Changes in the timeline including insertion, deletion, and updates.
locations - Location updates.
89 90 91 |
# File 'lib/glass/subscriptions/subscription.rb', line 89 def collection @collection end |
#id ⇒ Object
The ID of the subscription.
78 79 80 |
# File 'lib/glass/subscriptions/subscription.rb', line 78 def id @id end |
#mirror ⇒ Object
The Mirror Api
73 74 75 |
# File 'lib/glass/subscriptions/subscription.rb', line 73 def mirror @mirror end |
#notification ⇒ Object
Container object for notifications. This is not populated in the Subscription resource.
121 122 123 |
# File 'lib/glass/subscriptions/subscription.rb', line 121 def notification @notification end |
#operation ⇒ Object
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.
99 100 101 |
# File 'lib/glass/subscriptions/subscription.rb', line 99 def operation @operation end |
#updated ⇒ Object
The time at which this subscription was last modified, formatted according to RFC 3339.
83 84 85 |
# File 'lib/glass/subscriptions/subscription.rb', line 83 def updated @updated end |
#userToken ⇒ Object
An opaque token sent to the subscriber in notifications so that it can determine the ID of the user.
115 116 117 |
# File 'lib/glass/subscriptions/subscription.rb', line 115 def userToken @userToken end |
#verifyToken ⇒ Object
A secret token sent to the subscriber in notifications so that it can verify that the notification was generated by Google.
110 111 112 |
# File 'lib/glass/subscriptions/subscription.rb', line 110 def verifyToken @verifyToken end |
Class Method Details
.subscribe(mirror, collection, user_token, verify_token, callback_url, operation) ⇒ Object
Subscribe to notifications for the current user.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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 |
.unsubscribe_from_notifications(client, collection) ⇒ Object
Delete a subscription to a collection.
56 57 58 59 60 61 62 63 64 |
# 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 |