Class: Schwab::AccountNumberResolver
- Inherits:
-
Object
- Object
- Schwab::AccountNumberResolver
- Defined in:
- lib/schwab/account_number_resolver.rb
Overview
Resolves plain text account numbers to their encrypted hash values required by the Schwab API for URL path parameters
Instance Method Summary collapse
-
#initialize(client) ⇒ AccountNumberResolver
constructor
Initialize a new resolver for the given client.
-
#loaded? ⇒ Boolean
Check if the account number mappings are loaded.
-
#mappings ⇒ Hash<String, String>
Get all account numbers and their hash values.
-
#refresh! ⇒ void
Refresh the account number mappings from the API.
-
#resolve(account_number) ⇒ String
Resolve an account number to its encrypted hash value.
Constructor Details
#initialize(client) ⇒ AccountNumberResolver
Initialize a new resolver for the given client
10 11 12 13 14 15 |
# File 'lib/schwab/account_number_resolver.rb', line 10 def initialize(client) @client = client @mappings = {} @loaded = false @mutex = Mutex.new end |
Instance Method Details
#loaded? ⇒ Boolean
Check if the account number mappings are loaded
66 67 68 |
# File 'lib/schwab/account_number_resolver.rb', line 66 def loaded? @loaded end |
#mappings ⇒ Hash<String, String>
Get all account numbers and their hash values
56 57 58 59 60 61 |
# File 'lib/schwab/account_number_resolver.rb', line 56 def mappings @mutex.synchronize do load_mappings unless @loaded @mappings.dup end end |
#refresh! ⇒ void
This method returns an undefined value.
Refresh the account number mappings from the API
45 46 47 48 49 |
# File 'lib/schwab/account_number_resolver.rb', line 45 def refresh! @mutex.synchronize do refresh_mappings end end |
#resolve(account_number) ⇒ String
Resolve an account number to its encrypted hash value
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/schwab/account_number_resolver.rb', line 25 def resolve(account_number) return account_number if looks_like_hash?(account_number) @mutex.synchronize do load_mappings unless @loaded hash_value = @mappings[account_number.to_s] return hash_value if hash_value # Try refreshing mappings in case this is a new account refresh_mappings @mappings[account_number.to_s] || raise_account_not_found(account_number) end end |