Class: DwollaV2::TokenManager

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

Instance Method Summary collapse

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_tokenObject



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