Class: Danconia::Exchanges::CurrencyLayer

Inherits:
Exchange
  • Object
show all
Defined in:
lib/danconia/exchanges/currency_layer.rb

Instance Attribute Summary

Attributes inherited from Exchange

#store

Instance Method Summary collapse

Methods inherited from Exchange

#rate, #rates, #update_rates!

Constructor Details

#initialize(access_key:, **args) ⇒ CurrencyLayer

Returns a new instance of CurrencyLayer.



8
9
10
11
# File 'lib/danconia/exchanges/currency_layer.rb', line 8

def initialize access_key:, **args
  super args
  @access_key = access_key
end

Instance Method Details

#fetch_ratesObject



13
14
15
16
17
18
19
20
# File 'lib/danconia/exchanges/currency_layer.rb', line 13

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