class DailyExchangeRatesBank::ExchangeRatesApiClient

Access api.frankfurter.app to fetch historic exchange rates

Public Instance Methods

exchange_rates(from: 'EUR', to: %w[USD GBP CHF], date: Date.today) click to toggle source
# File lib/daily_exchange_rates_bank/exchange_rates_api_client.rb, line 8
def exchange_rates(from: 'EUR', to: %w[USD GBP CHF], date: Date.today)
  api_url = ENV.fetch('RATES_API_URL', 'https://api.frankfurter.app/')
  uri = URI.parse(api_url)
  uri.path = "/#{date}"
  uri.query = "base=#{from}&symbols=#{to.join(',')}"
  json_response = uri.read
  JSON.parse(json_response)['rates']
end