Class: TwitchOAuth2::Tokens
- Inherits:
-
Object
- Object
- TwitchOAuth2::Tokens
- Defined in:
- lib/twitch_oauth2/tokens.rb
Overview
Class for tokens and their refreshing, using provided client
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
‘refresh_token` for `on_update`, but it can be better to make getter with logic like for `access_token`, but there can be troubles: * right now `refresh_token` is kind of constant, but it can have TTL in the future; * right now there is no `refresh_token` for `:application` tokens, but it can appears in the future.
-
#refresh_token ⇒ Object
readonly
‘refresh_token` for `on_update`, but it can be better to make getter with logic like for `access_token`, but there can be troubles: * right now `refresh_token` is kind of constant, but it can have TTL in the future; * right now there is no `refresh_token` for `:application` tokens, but it can appears in the future.
-
#token_type ⇒ Object
readonly
‘refresh_token` for `on_update`, but it can be better to make getter with logic like for `access_token`, but there can be troubles: * right now `refresh_token` is kind of constant, but it can have TTL in the future; * right now there is no `refresh_token` for `:application` tokens, but it can appears in the future.
Instance Method Summary collapse
- #access_token ⇒ Object
- #authorize_link ⇒ Object
- #code=(value) ⇒ Object
-
#initialize(client:, access_token: nil, refresh_token: nil, token_type: :application, scopes: nil, on_update: nil) ⇒ Tokens
constructor
I don’t know how to make it shorter rubocop:disable Metrics/ParameterLists.
- #valid? ⇒ Boolean
Constructor Details
#initialize(client:, access_token: nil, refresh_token: nil, token_type: :application, scopes: nil, on_update: nil) ⇒ Tokens
I don’t know how to make it shorter rubocop:disable Metrics/ParameterLists
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/twitch_oauth2/tokens.rb', line 17 def initialize( client:, access_token: nil, refresh_token: nil, token_type: :application, scopes: nil, on_update: nil ) # rubocop:enable Metrics/ParameterLists @client = client.is_a?(Hash) ? Client.new(**client) : client @access_token = access_token @refresh_token = refresh_token @token_type = token_type @scopes = scopes @on_update = on_update @expires_at = nil end |
Instance Attribute Details
#client ⇒ Object (readonly)
‘refresh_token` for `on_update`, but it can be better to make getter with logic like for `access_token`, but there can be troubles:
-
right now ‘refresh_token` is kind of constant, but it can have TTL in the future;
-
right now there is no ‘refresh_token` for `:application` tokens, but it can appears in the future.
13 14 15 |
# File 'lib/twitch_oauth2/tokens.rb', line 13 def client @client end |
#refresh_token ⇒ Object (readonly)
‘refresh_token` for `on_update`, but it can be better to make getter with logic like for `access_token`, but there can be troubles:
-
right now ‘refresh_token` is kind of constant, but it can have TTL in the future;
-
right now there is no ‘refresh_token` for `:application` tokens, but it can appears in the future.
13 14 15 |
# File 'lib/twitch_oauth2/tokens.rb', line 13 def refresh_token @refresh_token end |
#token_type ⇒ Object (readonly)
‘refresh_token` for `on_update`, but it can be better to make getter with logic like for `access_token`, but there can be troubles:
-
right now ‘refresh_token` is kind of constant, but it can have TTL in the future;
-
right now there is no ‘refresh_token` for `:application` tokens, but it can appears in the future.
13 14 15 |
# File 'lib/twitch_oauth2/tokens.rb', line 13 def token_type @token_type end |
Instance Method Details
#access_token ⇒ Object
48 49 50 51 52 |
# File 'lib/twitch_oauth2/tokens.rb', line 48 def access_token raise AuthorizeError, if !valid? && @token_type == :user @access_token end |
#authorize_link ⇒ Object
44 45 46 |
# File 'lib/twitch_oauth2/tokens.rb', line 44 def @client.(scopes: @scopes) end |
#code=(value) ⇒ Object
54 55 56 |
# File 'lib/twitch_oauth2/tokens.rb', line 54 def code=(value) assign_tokens @client.token(token_type: @token_type, code: value) end |
#valid? ⇒ Boolean
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/twitch_oauth2/tokens.rb', line 32 def valid? if @access_token validate_access_token if @expires_at.nil? || Time.now >= @expires_at else return false if @token_type == :user request_new_tokens end true end |