Class: Exchange::ExternalAPI::Nbkr

Inherits:
XML
  • Object
show all
Defined in:
lib/exchange/external_api/nbkr.rb

Constant Summary collapse

API_URL =
"http://nbkr.kg/XML/daily.xml"
CURRENCIES =
I(kgs usd eur kzt rub)

Instance Method Summary collapse

Instance Method Details

#update(opts = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/exchange/external_api/nbkr.rb', line 10

def update opts={}
  time = helper.assure_time(opts[:at], default: :now)

  Call.new(API_URL, at: time, format: :xml) do |result|
    @base = :kgs

    @rates = result.search('Currency').map do |c|
      [
        c.attr("ISOCode").downcase.to_sym,
        (1 / BigDecimal.new(c.at('Value').text.sub(',', '.')))
      ]
    end.to_h.merge({ kgs: 1 })

    @timestamp = Date.today.to_time.to_i
  end
end