Class: ExchangeRatesGenerator::Sources::Ecb
- Defined in:
- lib/exchange-rates-generator/sources/ecb.rb
Overview
ECB: European Central Bank home page
Class Method Summary collapse
-
.all_rates ⇒ Hash
Retrieves all the currency rates from the external source, this is a Hash of currency codes and exchange rates.
-
.base_currency ⇒ Symbol
Retrieves the currency code (as an uppercase symbol) that represents this Source’s Base currency.
-
.description ⇒ String
Retrieves a human readable description of the Source.
Methods inherited from Base
Class Method Details
.all_rates ⇒ Hash
Retrieves all the currency rates from the external source, this is a Hash of currency codes and exchange rates. The currency codes will be upcased, Symbols (e.g. :USD, :NZD). The exchange rates will be with respect to the base_currency.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/exchange-rates-generator/sources/ecb.rb', line 25 def all_rates session = Patron::Session.new session.timeout = 30000 # 10 secs session.connect_timeout = 2000 # 2 secs ExchangeRatesGenerator.logger.info "Retrieving exchange rates from #{source}..." http_response = session.get(source) if ['404', '405', '406', '410'].include?(http_response.status) # Not Found, auth failure, etc. Some form of it wasn't there. raise Errors::NotFoundError, "The exchange rate source file seems to be unavailable" elsif !['1', '2'].include?(http_response.status.to_s[0..0]) # Other non-specific failures. raise Errors::UnexpectedError, "Error while making a request to #{source}\nResponse: #{http_response.inspect}" end convert_to_exchange_rate_hash(http_response.body) end |
.base_currency ⇒ Symbol
Retrieves the currency code (as an uppercase symbol) that represents this Source’s Base currency.
9 10 11 |
# File 'lib/exchange-rates-generator/sources/ecb.rb', line 9 def base_currency :EUR end |
.description ⇒ String
Retrieves a human readable description of the Source.
16 17 18 |
# File 'lib/exchange-rates-generator/sources/ecb.rb', line 16 def description "European Central Bank currency feed" end |