class ECBExchangeRatesApi::Client
Client
. Provides ways for different configurations.
Attributes
options[R]
Public Class Methods
new() { |self| ... }
click to toggle source
# File lib/ecb_exchange_rates_api/client.rb, line 21 def initialize @options = ECBExchangeRatesApi::Options.new yield self if block_given? end
Public Instance Methods
at(date)
click to toggle source
# File lib/ecb_exchange_rates_api/client.rb, line 41 def at(date) @options.specific_date = date self end
convert(amount, base_code = nil, codes = nil, date = nil)
click to toggle source
# File lib/ecb_exchange_rates_api/client.rb, line 61 def convert(amount, base_code = nil, codes = nil, date = nil) response = self.class.new do |client| client.with_base presented_base(base_code) client.for_rates presented_symbols(codes) client.at presented_date(date) end.fetch response.rates.transform_values! { |v| v * amount } response end
currency_is_supported?(code)
click to toggle source
# File lib/ecb_exchange_rates_api/client.rb, line 72 def currency_is_supported?(code) supported_currency?(validated_currency_code(code)) end
fetch()
click to toggle source
# File lib/ecb_exchange_rates_api/client.rb, line 26 def fetch response = self.class.get(path, query: options.to_params) create_result(response.parsed_response, response.code) end
for_rate(code)
click to toggle source
# File lib/ecb_exchange_rates_api/client.rb, line 56 def for_rate(code) @options.append_symbol(code) self end
for_rates(codes)
click to toggle source
# File lib/ecb_exchange_rates_api/client.rb, line 51 def for_rates(codes) codes.each(&method(:for_rate)) self end
from(date)
click to toggle source
# File lib/ecb_exchange_rates_api/client.rb, line 31 def from(date) @options.start_at = date self end
supported_currencies()
click to toggle source
# File lib/ecb_exchange_rates_api/client.rb, line 76 def supported_currencies CURRENCIES end
to(date)
click to toggle source
# File lib/ecb_exchange_rates_api/client.rb, line 36 def to(date) @options.end_at = date self end
with_base(code)
click to toggle source
# File lib/ecb_exchange_rates_api/client.rb, line 46 def with_base(code) @options.base = code self end
Private Instance Methods
create_result(response, status)
click to toggle source
# File lib/ecb_exchange_rates_api/client.rb, line 92 def create_result(response, status) ECBExchangeRatesApi::Result.new(response, status: status) end
path()
click to toggle source
# File lib/ecb_exchange_rates_api/client.rb, line 84 def path return "/#{specific_date}" if specific_date return "/history" if start_at && end_at "/latest" end
presented_base(base_from_params)
click to toggle source
# File lib/ecb_exchange_rates_api/client.rb, line 96 def presented_base(base_from_params) base_from_params || base || default_base end
presented_date(date)
click to toggle source
# File lib/ecb_exchange_rates_api/client.rb, line 104 def presented_date(date) date || specific_date || current_date end
presented_symbols(codes)
click to toggle source
# File lib/ecb_exchange_rates_api/client.rb, line 100 def presented_symbols(codes) (codes && Array.wrap(codes)) || symbols || [] end