Class: Gahh::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/gahh/handler.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Handler

Returns a new instance of Handler.



7
8
9
10
11
# File 'lib/gahh/handler.rb', line 7

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

Class Method Details

.testing_def(param) ⇒ Object



3
4
5
# File 'lib/gahh/handler.rb', line 3

def self.testing_def(param)
  puts "testing with parameter #{param}"
end

Instance Method Details

#request_access_token(auth_code) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/gahh/handler.rb', line 30

def request_access_token(auth_code)
  http = Net::HTTP.new('accounts.google.com', 443)
  path = '/o/oauth2/token'
  http.use_ssl = true
  data = "code=#{auth_code}&client_id=#{@client_id}&client_secret=#{@client_secret}&redirect_uri=#{@redirect_uri}&grant_type=authorization_code"
  response = http.post(path, data)
  values = JSON.parse(response.body)
  binding.pry
end

#retrieve_auth(scopes) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gahh/handler.rb', line 13

def retrieve_auth(scopes)
  # options expecting scopes organized in hash with api and expectation
  # ie {"analytics" => "read"}

  scope = Gahh::ApiScopeParser::convert_api_scope_to_uri(scopes)

  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
  )
  return client.authorization_uri.to_s
end