Class: Money::Bank::BlockchainInfoExchangeRates
- Inherits:
-
VariableExchange
- Object
- VariableExchange
- Money::Bank::BlockchainInfoExchangeRates
- Defined in:
- lib/money/bank/blockchain_info_exchange_rates.rb
Constant Summary collapse
- TICKER_URL =
'https://blockchain.info/ticker'
Instance Attribute Summary collapse
-
#bi_rates ⇒ Object
readonly
Returns the value of attribute bi_rates.
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#rates_expiration ⇒ Object
readonly
Returns the value of attribute rates_expiration.
-
#ttl_in_seconds ⇒ Object
Returns the value of attribute ttl_in_seconds.
Instance Method Summary collapse
- #expire_rates ⇒ Object
- #get_rate(from_currency, to_currency, opts = {}) ⇒ Object
- #save_rates ⇒ Object
- #update_rates ⇒ Object
Instance Attribute Details
#bi_rates ⇒ Object (readonly)
Returns the value of attribute bi_rates.
14 15 16 |
# File 'lib/money/bank/blockchain_info_exchange_rates.rb', line 14 def bi_rates @bi_rates end |
#cache ⇒ Object
Returns the value of attribute cache.
12 13 14 |
# File 'lib/money/bank/blockchain_info_exchange_rates.rb', line 12 def cache @cache end |
#rates_expiration ⇒ Object (readonly)
Returns the value of attribute rates_expiration.
14 15 16 |
# File 'lib/money/bank/blockchain_info_exchange_rates.rb', line 14 def rates_expiration @rates_expiration end |
#ttl_in_seconds ⇒ Object
Returns the value of attribute ttl_in_seconds.
14 15 16 |
# File 'lib/money/bank/blockchain_info_exchange_rates.rb', line 14 def ttl_in_seconds @ttl_in_seconds end |
Instance Method Details
#expire_rates ⇒ Object
44 45 46 47 48 49 |
# File 'lib/money/bank/blockchain_info_exchange_rates.rb', line 44 def expire_rates if ttl_in_seconds && rates_expiration <= Time.now update_rates refresh_rates_expiration end end |
#get_rate(from_currency, to_currency, opts = {}) ⇒ Object
39 40 41 42 |
# File 'lib/money/bank/blockchain_info_exchange_rates.rb', line 39 def get_rate(from_currency, to_currency, opts = {}) expire_rates super end |
#save_rates ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/money/bank/blockchain_info_exchange_rates.rb', line 29 def save_rates raise InvalidCache unless cache text = read_from_url if has_valid_rates?(text) store_in_cache(text) end rescue Errno::ENOENT raise InvalidCache end |
#update_rates ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/money/bank/blockchain_info_exchange_rates.rb', line 21 def update_rates exchange_rates.each do |currency, rate| next unless Money::Currency.find(currency) set_rate('BTC', currency, rate) set_rate(currency, 'BTC', 1.0/rate) end end |