Created
August 28, 2016 07:36
-
-
Save sharshenov/c09ed8955692ca98d371eeb42a1b6d45 to your computer and use it in GitHub Desktop.
exchange gem NBKR external API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
вместо
%W(kgs usd eur kzt rub).map(&:to_sym)
можно
%I(kgs usd eur kzt rub)
ps. after ruby 2.0
Поэтому так и написал, чтобы в 1.9.3 заработало :)
1.9.3
кетсин
Обернуто в гем https://github.com/sharshenov/exchange-nbkr
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bundle
100.in(:kgs).to(:usd).to_f.round(2)