Class: GustoApi::Oauth

Inherits:
Object
  • Object
show all
Defined in:
lib/gusto_api/oauth.rb

Class Method Summary collapse

Class Method Details

.auth_urlObject



3
4
5
6
7
8
9
10
11
# File 'lib/gusto_api/oauth.rb', line 3

def self.auth_url
  URI(GustoApi.configuration.base_uri + "oauth/authorize").tap do |uri|
    uri.query = URI.encode_www_form(
      client_id: GustoApi.configuration.client_id,
      redirect_uri: GustoApi.configuration.redirect_url,
      response_type: 'code'
    )
  end.to_s
end

.get_token(code) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gusto_api/oauth.rb', line 13

def self.get_token(code)
  OauthRequest.new(
    method: :post,
    params: {
      client_id: GustoApi.configuration.client_id,
      client_secret: GustoApi.configuration.client_secret,
      redirect_uri: GustoApi.configuration.redirect_url,
      code: code,
      grant_type: 'authorization_code'
    }
  ).submit
end

.refresh_token(refresh_token) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gusto_api/oauth.rb', line 26

def self.refresh_token(refresh_token)
  OauthRequest.new(
    method: :post,
    params: {
      client_id: GustoApi.configuration.client_id,
      client_secret: GustoApi.configuration.client_secret,
      redirect_uri: GustoApi.configuration.redirect_url,
      refresh_token: refresh_token,
      grant_type: 'refresh_token'
    }
  ).submit
end