Class: ApontadorOauth2::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/apontador_oauth2/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
# File 'lib/apontador_oauth2/client.rb', line 9

def initialize(options)
  @options = {
    :grant_type      => "client_credentials",
    :username        => "",
    :password        => "",
  }.merge!(options)
  request
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/apontador_oauth2/client.rb', line 8

def options
  @options
end

#tokenObject

Returns the value of attribute token.



8
9
10
# File 'lib/apontador_oauth2/client.rb', line 8

def token
  @token
end

Instance Method Details

#requestObject



18
19
20
21
22
23
# File 'lib/apontador_oauth2/client.rb', line 18

def request
  url = URI.parse(@options[:url])
  connection  = Faraday.new(:url => url)
  response = connection.post 'oauth/token', @options
  @token = JSON.parse(response.body)['access_token']
end