Class: Glass::Subscription
- Inherits:
-
Object
- Object
- Glass::Subscription
- Defined in:
- lib/glass/subscription.rb
Constant Summary collapse
- DEFAULT_COLLECTION =
:timeline
- DEFAULT_OPERATIONS =
- ‘UPDATE’, ‘INSERT’, ‘DELETE’
%w(UPDATE INSERT DELETE)#
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#google_account ⇒ Object
Returns the value of attribute google_account.
-
#google_client ⇒ Object
Returns the value of attribute google_client.
-
#mirror_api ⇒ Object
Returns the value of attribute mirror_api.
Instance Method Summary collapse
-
#initialize(opts) ⇒ Subscription
constructor
A new instance of Subscription.
-
#insert(opts = {}) ⇒ Object
Insert a subscription optional parameters: collection can be :timeline or :locations operation is an array of operations subscribed to.
-
#user_token ⇒ Object
Token string used to identify user in the callback.
-
#verification_secret ⇒ Object
Secret string used to verify that the callback is by Google.
Constructor Details
#initialize(opts) ⇒ Subscription
Returns a new instance of Subscription.
8 9 10 11 12 13 |
# File 'lib/glass/subscription.rb', line 8 def initialize(opts) self.google_account = opts[:google_account] self.client = Glass::Client.new google_account: google_account self.google_client = client.google_client self.mirror_api = client.mirror_api end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
6 7 8 |
# File 'lib/glass/subscription.rb', line 6 def client @client end |
#google_account ⇒ Object
Returns the value of attribute google_account.
6 7 8 |
# File 'lib/glass/subscription.rb', line 6 def google_account @google_account end |
#google_client ⇒ Object
Returns the value of attribute google_client.
6 7 8 |
# File 'lib/glass/subscription.rb', line 6 def google_client @google_client end |
#mirror_api ⇒ Object
Returns the value of attribute mirror_api.
6 7 8 |
# File 'lib/glass/subscription.rb', line 6 def mirror_api @mirror_api end |
Instance Method Details
#insert(opts = {}) ⇒ Object
Insert a subscription optional parameters:
collection can be :timeline or :locations
operation is an array of operations subscribed to. Valid values are 'UPDATE', 'INSERT', 'DELETE'
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/glass/subscription.rb', line 19 def insert(opts={}) mirror_api_method = opts[:mirror_api_method] || :subscriptions subscription = mirror_api.subscriptions.insert.request_schema.new( collection: opts[:collection] || DEFAULT_COLLECTION, userToken: user_token, verifyToken: verification_secret, callbackUrl: opts[:callback_url] || client.callback_url, operation: opts[:operations] || DEFAULT_OPERATIONS) result = google_client.execute(api_method: mirror_api.send(mirror_api_method).insert, body_object: subscription) result end |
#user_token ⇒ Object
Token string used to identify user in the callback
36 37 38 |
# File 'lib/glass/subscription.rb', line 36 def user_token google_account.id.to_s end |
#verification_secret ⇒ Object
Secret string used to verify that the callback is by Google
41 42 43 |
# File 'lib/glass/subscription.rb', line 41 def verification_secret google_account.verification_secret end |