openexchangerates/example.rb

15 lines
491 B
Ruby
Raw Permalink Normal View History

2013-12-06 06:22:46 +04:00
require 'json'
require 'time'
require 'openexchangerates'
currency = OpenExchange.new('586ee899f7eb4f79861589a1f00a8630')
cur = JSON.parse(currency.get_latest)
2013-12-06 06:47:08 +04:00
cur_old = JSON.parse(currency.get_old('2010-12-31'))
2013-12-06 06:22:46 +04:00
cur_show = 'RUB'
2013-12-06 06:47:08 +04:00
puts "#{Time.at(cur_old['timestamp'])} \n\t1 USD = #{cur['rates'][cur_show]} \
#{JSON.parse(currency.get_currencies)[cur_show]}"
puts "#{Time.at(cur['timestamp'])} \n\t1 USD = #{cur_old['rates'][cur_show]} \
#{JSON.parse(currency.get_currencies)[cur_show]}"