Module: Nbrb::Api::Currencies

Included in:
Nbrb::Api
Defined in:
lib/nbrb-api/currencies.rb

Instance Method Summary collapse

Instance Method Details

#cleanup_rate_row(row) ⇒ Object



19
20
21
22
23
24
# File 'lib/nbrb-api/currencies.rb', line 19

def cleanup_rate_row(row)
  row.each do |key, value|
    row.delete(key) if key.to_s[0] == '@'
  end
  row
end

#daily_rates(date = Date.today) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/nbrb-api/currencies.rb', line 4

def daily_rates(date = Date.today)
  response = call(:ex_rates_daily, message: {on_date: date.to_date})
  rates = response.find(*%w{Body ExRatesDailyResponse ExRatesDailyResult diffgram new_data_set daily_ex_rates_on_date})

  if rates.nil?
    raise Nbrb::Api::GeneralError, "No exchange rates found for operation #{:ex_rates_daily}"
  end

  result = {}
  [rates].flatten.each do |rate|
    result[rate[:cur_abbreviation]] = cleanup_rate_row(rate)
  end
  result
end