Class: Multicard::TokenManager

Inherits:
Object
  • Object
show all
Defined in:
lib/multicard/token_manager.rb

Constant Summary collapse

TOKEN_TTL =

Refresh 1 hour before 24h expiry

23 * 3600

Instance Method Summary collapse

Constructor Details

#initialize(http_client, config) ⇒ TokenManager

Returns a new instance of TokenManager.



7
8
9
10
11
12
13
# File 'lib/multicard/token_manager.rb', line 7

def initialize(http_client, config)
  @http_client = http_client
  @config = config
  @token = nil
  @expires_at = nil
  @mutex = Mutex.new
end

Instance Method Details

#reset!Object



22
23
24
25
26
27
# File 'lib/multicard/token_manager.rb', line 22

def reset!
  @mutex.synchronize do
    @token = nil
    @expires_at = nil
  end
end

#tokenObject



15
16
17
18
19
20
# File 'lib/multicard/token_manager.rb', line 15

def token
  @mutex.synchronize do
    refresh! if expired?
    @token
  end
end