Class: IesAuth::TokenManager

Inherits:
Object
  • Object
show all
Includes:
RequestDefaults
Defined in:
lib/ies_auth/token_manager.rb

Overview

TLD

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RequestDefaults

#delete, #get, #ies_api_url, #post, #put

Constructor Details

#initialize(token = nil) ⇒ TokenManager

Returns a new instance of TokenManager.



10
11
12
13
14
# File 'lib/ies_auth/token_manager.rb', line 10

def initialize(token = nil)
  @token = token || create_token
  raise InvalidTokenStructureError unless token_duck?(@token)
  raise ExpiredTokenError if expired?
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



8
9
10
# File 'lib/ies_auth/token_manager.rb', line 8

def token
  @token
end

Instance Method Details

#dataObject



16
17
18
# File 'lib/ies_auth/token_manager.rb', line 16

def data
  token.data
end

#expirationObject



20
21
22
# File 'lib/ies_auth/token_manager.rb', line 20

def expiration
  token.expiration
end

#expired?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ies_auth/token_manager.rb', line 24

def expired?
  (Time.now <=> expiration).positive?
end

#user_idObject



28
29
30
# File 'lib/ies_auth/token_manager.rb', line 28

def user_id
  token.user_id
end