Class: Exchange::ExternalAPI::Ecb
- Defined in:
- lib/exchange/external_api/ecb.rb
Overview
The ECB class, handling communication with the European Central Bank XML File API You can find further information on the European Central Bank XML API API here: www.ecb.int/stats/exchange/eurofxref/html/index.en.html
Constant Summary collapse
- API_URL =
The base of the ECB API URL
"www.ecb.europa.eu/stats/eurofxref"
- CURRENCIES =
The currencies the ECB API URL can handle
[:eur, :usd, :jpy, :bgn, :czk, :dkk, :gbp, :huf, :ltl, :lvl, :pln, :ron, :sek, :chf, :nok, :hrk, :rub, :try, :aud, :brl, :cad, :cny, :hkd, :idr, :ils, :inr, :krw, :mxn, :myr, :nzd, :php, :sgd, :thb, :zar]
Instance Attribute Summary collapse
-
#callresult ⇒ Object
The result of the api call to the Central bank.
Attributes inherited from Base
#base, #cache, #helper, #rates, #timestamp
Instance Method Summary collapse
-
#update(opts = {}) ⇒ Object
Updates the rates by getting the information from ECB API for today or a defined historical date The call gets cached for a maximum of 24 hours.
Methods inherited from XML
Methods inherited from Base
#convert, #initialize, #rate, #test_for_rates_and_raise_if_nil, #to_hash!
Constructor Details
This class inherits a constructor from Exchange::ExternalAPI::XML
Instance Attribute Details
#callresult ⇒ Object
The result of the api call to the Central bank
22 23 24 |
# File 'lib/exchange/external_api/ecb.rb', line 22 def callresult @callresult end |
Instance Method Details
#update(opts = {}) ⇒ Object
Updates the rates by getting the information from ECB API for today or a defined historical date The call gets cached for a maximum of 24 hours. Getting history from ECB is a bit special, since they do not seem to have any smaller portion history than an epic 4MB XML history file and a 90 day recent history file. We get each of that once and cache it in smaller portions.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/exchange/external_api/ecb.rb', line 35 def update opts={} time = helper.assure_time(opts[:at], :default => :now) times = map_retry_times time Call.new(api_url(time), call_opts(time)) do |result| t = time # Weekends do not have rates present # t = times.shift while (r = find_rate!(result, t)).empty? && !times.empty? @base = :eur # We just have to assume, since it's the ECB @rates = extract_rates(r.children) @timestamp = time.to_i end end |