Class: Esi::OAuth
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#refresh_token ⇒ Object
readonly
Returns the value of attribute refresh_token.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(access_token:, refresh_token:, expires_at:, callback: nil) ⇒ OAuth
constructor
A new instance of OAuth.
Constructor Details
#initialize(access_token:, refresh_token:, expires_at:, callback: nil) ⇒ OAuth
Returns a new instance of OAuth.
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_token ⇒ Object (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_at ⇒ Object (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_token ⇒ Object (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 (redirect_uri:, scopes: nil) scopes ||= Esi.config.scopes client.auth_code.(scope: Array[scopes].flatten.join(' '), redirect_uri: redirect_uri) end |
.client ⇒ Object
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 |