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.

Raises:



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

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

  @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.



7
8
9
# File 'lib/esi/o_auth.rb', line 7

def access_token
  @access_token
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



7
8
9
# File 'lib/esi/o_auth.rb', line 7

def expires_at
  @expires_at
end

#refresh_tokenObject (readonly)

Returns the value of attribute refresh_token.



7
8
9
# File 'lib/esi/o_auth.rb', line 7

def refresh_token
  @refresh_token
end

Class Method Details

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



11
12
13
14
# File 'lib/esi/o_auth.rb', line 11

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

.clientObject



22
23
24
25
26
27
# File 'lib/esi/o_auth.rb', line 22

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

.obtain_token(code) ⇒ Object



16
17
18
19
20
# File 'lib/esi/o_auth.rb', line 16

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