class Danconia::Exchanges::CurrencyLayer
Fetches the rates from currencylayer.com/. The `access_key` must be provided. See `examples/currency_layer.rb` for a complete usage example.
Attributes
store[R]
Public Class Methods
new(access_key:, store: Stores::InMemory.new)
click to toggle source
# File lib/danconia/exchanges/currency_layer.rb, line 12 def initialize access_key:, store: Stores::InMemory.new @access_key = access_key @store = store end
Public Instance Methods
fetch_rates()
click to toggle source
# File lib/danconia/exchanges/currency_layer.rb, line 17 def fetch_rates response = JSON.parse Net::HTTP.get URI "http://www.apilayer.net/api/live?access_key=#{@access_key}" if response['success'] response['quotes'] else raise Errors::APIError, response end end
rates(**_opts)
click to toggle source
# File lib/danconia/exchanges/currency_layer.rb, line 30 def rates **_opts array_of_rates_to_hash @store.rates end
update_rates!()
click to toggle source
# File lib/danconia/exchanges/currency_layer.rb, line 26 def update_rates! @store.save_rates fetch_rates.map { |pair, rate| {pair: pair, rate: rate} } end