Class: Traxo::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/traxo/auth.rb

Constant Summary collapse

OAUTH_URL =
"https://www.traxo.com/oauth/"
TOKEN_URL =
"#{OAUTH_URL}token/"

Instance Method Summary collapse

Constructor Details

#initialize(client_id, client_secret, oauth_redirect_url) ⇒ Auth

Returns a new instance of Auth.



8
9
10
11
12
# File 'lib/traxo/auth.rb', line 8

def initialize(client_id, client_secret, oauth_redirect_url)
  @client_id = client_id
  @client_secret = client_secret
  @oauth_redirect_url = oauth_redirect_url
end

Instance Method Details

#exchange_refresh_token(token) ⇒ Object



25
26
27
28
29
# File 'lib/traxo/auth.rb', line 25

def exchange_refresh_token(token)
  data = token_refresh_data(token)
  response = Net::HTTP.post_form(token_uri, data)
  JSON.parse(response.body, symbolize_names: true)
end

#exchange_request_code(code) ⇒ Object



19
20
21
22
23
# File 'lib/traxo/auth.rb', line 19

def exchange_request_code(code)
  data = token_request_data(code, @oauth_redirect_url)
  response = Net::HTTP.post_form(token_uri, data)
  JSON.parse(response.body, symbolize_names: true)
end

#request_code_url(state) ⇒ Object



14
15
16
17
# File 'lib/traxo/auth.rb', line 14

def request_code_url(state)
  check_state_parameter(state)
  "#{OAUTH_URL}authenticate?client_id=#{@client_id}&response_type=code&redirect_uri=#{@oauth_redirect_url}&state=#{state}"
end