Skip to content

Instantly share code, notes, and snippets.

@sharshenov
Created August 28, 2016 07:36
Show Gist options
  • Save sharshenov/c09ed8955692ca98d371eeb42a1b6d45 to your computer and use it in GitHub Desktop.
Save sharshenov/c09ed8955692ca98d371eeb42a1b6d45 to your computer and use it in GitHub Desktop.
exchange gem NBKR external API
module Exchange
module ExternalAPI
class Nbkr < XML
API_URL = "http://nbkr.kg/XML/daily.xml"
CURRENCIES = %W(kgs usd eur kzt rub).map(&:to_sym)
def update opts={}
time = helper.assure_time(opts[:at], default: :now)
Call.new(api_url(time), 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
private
def api_url(time)
API_URL
end
end
end
end
Exchange.configuration = Exchange::Configuration.new do |c|
c.api.subclass = :nbkr
end
@adis-io
Copy link

adis-io commented Aug 28, 2016

вместо
%W(kgs usd eur kzt rub).map(&:to_sym)
можно
%I(kgs usd eur kzt rub)
ps. after ruby 2.0

@sharshenov
Copy link
Author

Поэтому так и написал, чтобы в 1.9.3 заработало :)

@adis-io
Copy link

adis-io commented Aug 29, 2016

1.9.3 кетсин

@sharshenov
Copy link
Author

Обернуто в гем https://github.com/sharshenov/exchange-nbkr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment