Class: DwollaV2::TokenManager
- Inherits:
-
Object
- Object
- DwollaV2::TokenManager
- Defined in:
- lib/dwolla_v2/token_manager.rb
Instance Method Summary collapse
- #get_token ⇒ Object
-
#initialize(client) ⇒ TokenManager
constructor
A new instance of TokenManager.
Constructor Details
#initialize(client) ⇒ TokenManager
Returns a new instance of TokenManager.
3 4 5 6 7 |
# File 'lib/dwolla_v2/token_manager.rb', line 3 def initialize(client) @client = client @wrapped_token = nil @mutex = Mutex.new end |
Instance Method Details
#get_token ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/dwolla_v2/token_manager.rb', line 9 def get_token @mutex.synchronize do current_token = @wrapped_token || fetch_new_token() fresh_token = current_token.is_expired? ? fetch_new_token() : current_token @wrapped_token = fresh_token unless @wrapped_token == fresh_token fresh_token.token end end |