Class: Glass::Subscription

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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. = opts[:google_account]
  self.client = Glass::Client.new google_account: 
  self.google_client = client.google_client
  self.mirror_api = client.mirror_api
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



6
7
8
# File 'lib/glass/subscription.rb', line 6

def client
  @client
end

#google_accountObject

Returns the value of attribute google_account.



6
7
8
# File 'lib/glass/subscription.rb', line 6

def 
  @google_account
end

#google_clientObject

Returns the value of attribute google_client.



6
7
8
# File 'lib/glass/subscription.rb', line 6

def google_client
  @google_client
end

#mirror_apiObject

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_tokenObject

Token string used to identify user in the callback



36
37
38
# File 'lib/glass/subscription.rb', line 36

def user_token
  .id.to_s
end

#verification_secretObject

Secret string used to verify that the callback is by Google



41
42
43
# File 'lib/glass/subscription.rb', line 41

def verification_secret
  .verification_secret
end