Class: Pog

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/pog/templates/pog_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Pog

options expected to include client_id, client_secret, and redirect_uri



4
5
6
7
8
# File 'lib/generators/pog/templates/pog_handler.rb', line 4

def initialize(options)
  @client_id = options[:client_id]
  @client_secret = options[:client_secret]
  @redirect_uri = options[:redirect_uri]
end

Instance Method Details

#access_token_expired?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/generators/pog/templates/pog_handler.rb', line 14

def access_token_expired?
  self.access_token_expiration_time < Time.now
end

#has_permission?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/generators/pog/templates/pog_handler.rb', line 10

def has_permission?
  self.permission
end

#retrieve_auth(options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/generators/pog/templates/pog_handler.rb', line 18

def retrieve_auth(options)
  scope = create_uri_from_scopes(options)
  @client = Signet::OAuth2::Client.new(
    :authorization_uri => 'https://accounts.google.com/o/oauth2/auth',
    :token_endpoint_uri => 'https://accounts.google.com/o/oauth2/token',
    :client_id => @client_id,
    :client_secret => @client_secret,
    :scope => scope,
    :redirect_uri => @redirect_uri
  )
  @client.authorization_uri.to_s
end