Class: Money::Bank::CoinMarketCap
- Inherits:
-
VariableExchange
- Object
- VariableExchange
- Money::Bank::CoinMarketCap
- Defined in:
- lib/money/bank/coin_market_cap.rb
Constant Summary collapse
- BASE_CURRENCY =
"BTC".freeze
- EXCHANGE_URL =
"http://coinmarketcap.northpole.ro/api/v5/all.json".freeze
Instance Attribute Summary collapse
-
#rates_expire_at ⇒ Object
readonly
Rates expiration time.
-
#ttl_in_seconds ⇒ Object
Seconds after which the current rates are automatically expired.
Instance Method Summary collapse
- #get_rate(iso_from, iso_to, opts = {}) ⇒ Object
-
#initialize(*args, &block) ⇒ CoinMarketCap
constructor
A new instance of CoinMarketCap.
- #original_get_rate ⇒ Object
- #update_rates ⇒ Object
Constructor Details
#initialize(*args, &block) ⇒ CoinMarketCap
Returns a new instance of CoinMarketCap.
18 19 20 21 22 |
# File 'lib/money/bank/coin_market_cap.rb', line 18 def initialize(*args, &block) super self.ttl_in_seconds = 3600 # 1 hour end |
Instance Attribute Details
#rates_expire_at ⇒ Object (readonly)
Rates expiration time
16 17 18 |
# File 'lib/money/bank/coin_market_cap.rb', line 16 def rates_expire_at @rates_expire_at end |
#ttl_in_seconds ⇒ Object
Seconds after which the current rates are automatically expired
13 14 15 |
# File 'lib/money/bank/coin_market_cap.rb', line 13 def ttl_in_seconds @ttl_in_seconds end |
Instance Method Details
#get_rate(iso_from, iso_to, opts = {}) ⇒ Object
34 35 36 37 38 |
# File 'lib/money/bank/coin_market_cap.rb', line 34 def get_rate(iso_from, iso_to, opts = {}) update_rates_if_expired super || get_indirect_rate(iso_from, iso_to, opts) end |
#original_get_rate ⇒ Object
32 |
# File 'lib/money/bank/coin_market_cap.rb', line 32 alias original_get_rate get_rate |
#update_rates ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/money/bank/coin_market_cap.rb', line 24 def update_rates store.each_rate do |iso_from, iso_to, _rate| add_rate(iso_from, iso_to, nil) end add_exchange_rates end |