Class: Esi::OAuth

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/esi/o_auth.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token:, refresh_token:, expires_at:, callback: nil) ⇒ OAuth

Returns a new instance of OAuth.



28
29
30
31
32
33
34
35
36
37
# File 'lib/esi/o_auth.rb', line 28

def initialize(access_token:, refresh_token:, expires_at:, callback: nil)
  if callback && !callback.respond_to?(:call)
    raise Esi::Error.new("Callback should be a callable Proc")
  end

  @access_token = access_token
  @refresh_token = refresh_token
  @expires_at = expires_at
  @callback = callback if callback
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



5
6
7
# File 'lib/esi/o_auth.rb', line 5

def access_token
  @access_token
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



5
6
7
# File 'lib/esi/o_auth.rb', line 5

def expires_at
  @expires_at
end

#refresh_tokenObject (readonly)

Returns the value of attribute refresh_token.



5
6
7
# File 'lib/esi/o_auth.rb', line 5

def refresh_token
  @refresh_token
end

Class Method Details

.authorize_url(redirect_uri:, scopes: nil) ⇒ Object



9
10
11
12
# File 'lib/esi/o_auth.rb', line 9

def authorize_url(redirect_uri:, scopes: nil)
  scopes ||= Esi.config.scopes
  client.auth_code.authorize_url(scope: scopes.join(' '), redirect_uri: redirect_uri)
end

.clientObject



20
21
22
23
24
25
# File 'lib/esi/o_auth.rb', line 20

def client
  @client ||= OAuth2::Client.new(
    Esi.config.client_id, Esi.config.client_secret,
    { site: Esi.config.oauth_host }
  )
end

.obtain_token(code) ⇒ Object



14
15
16
17
18
# File 'lib/esi/o_auth.rb', line 14

def obtain_token(code)
  ActiveSupport::Notifications.instrument('esi.oauth.obtain_token') do
    Esi::AccessToken.new(client.auth_code.get_token(code))
  end
end