Class: Multicard::TokenManager
- Inherits:
-
Object
- Object
- Multicard::TokenManager
- Defined in:
- lib/multicard/token_manager.rb
Constant Summary collapse
- TOKEN_TTL =
Refresh 1 hour before 24h expiry
23 * 3600
Instance Method Summary collapse
-
#initialize(http_client, config) ⇒ TokenManager
constructor
A new instance of TokenManager.
- #reset! ⇒ Object
- #token ⇒ Object
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 |
#token ⇒ Object
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 |