first version
This commit is contained in:
parent
31c9a230df
commit
8e92e48e59
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.gem
|
12
example.rb
Normal file
12
example.rb
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
require 'json'
|
||||||
|
require 'time'
|
||||||
|
require 'openexchangerates'
|
||||||
|
|
||||||
|
currency = OpenExchange.new('586ee899f7eb4f79861589a1f00a8630')
|
||||||
|
cur = JSON.parse(currency.get_latest)
|
||||||
|
|
||||||
|
cur_show = 'RUB'
|
||||||
|
|
||||||
|
puts "Latest update: #{Time.at(cur['timestamp'])}"
|
||||||
|
puts "1 USD = #{cur['rates'][cur_show]} \
|
||||||
|
(#{JSON.parse(currency.get_currencies)[cur_show]})"
|
31
lib/openexchangerates.rb
Normal file
31
lib/openexchangerates.rb
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
require 'open-uri'
|
||||||
|
|
||||||
|
class OpenExchange
|
||||||
|
@@url = 'http://openexchangerates.org/api/'
|
||||||
|
|
||||||
|
def initialize(api_key)
|
||||||
|
@api_key = api_key
|
||||||
|
@user_agent = "Ruby/#{RUBY_VERSION}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_userAgent(user_agent)
|
||||||
|
@user_agent = user_agent
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_latest()
|
||||||
|
json = open("#{@@url}latest.json?app_id=#{@api_key}",
|
||||||
|
'User-Agent' => @user_agent).read
|
||||||
|
return json
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_old(date) # YYYY-MM-DD
|
||||||
|
json = open("#{@@url}historical/#{date}.json?app_id=#{@api_key}",
|
||||||
|
'User-Agent' => @user_agent).read
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_currencies()
|
||||||
|
json = open("#{@@url}currencies.json?app_id=#{@api_key}",
|
||||||
|
'User-Agent' => @user_agent).read
|
||||||
|
return json
|
||||||
|
end
|
||||||
|
end
|
14
openexchangerates.gemspec
Normal file
14
openexchangerates.gemspec
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
Gem::Specification.new do |s|
|
||||||
|
s.name = 'openexchangerates'
|
||||||
|
s.version = '0.0.1'
|
||||||
|
s.date = '2012-12-06'
|
||||||
|
s.summary = 'Implementation API openexchangerates.org on Ruby'
|
||||||
|
s.description = 'Implementation API openexchangerates.org on Ruby'
|
||||||
|
s.authors = ['Alexander Popov']
|
||||||
|
s.email = ['iiiypuk@iiiypuk.me']
|
||||||
|
s.homepage = 'https://github.com/IIIypuk/openexchangerates'
|
||||||
|
s.license = 'MIT'
|
||||||
|
|
||||||
|
s.files = `git ls-files`.split("\n")
|
||||||
|
s.require_paths = ["lib"]
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user