Class: OpenExchange
- Inherits:
-
Object
- Object
- OpenExchange
- Defined in:
- lib/openexchangerates.rb
Constant Summary collapse
- @@url =
'http://openexchangerates.org/api/'
Instance Method Summary collapse
- #get_currencies ⇒ Object
- #get_latest ⇒ Object
-
#get_old(date) ⇒ Object
YYYY-MM-DD.
-
#initialize(api_key) ⇒ OpenExchange
constructor
A new instance of OpenExchange.
- #set_userAgent(user_agent) ⇒ Object
Constructor Details
#initialize(api_key) ⇒ OpenExchange
Returns a new instance of OpenExchange.
6 7 8 9 |
# File 'lib/openexchangerates.rb', line 6 def initialize(api_key) @api_key = api_key @user_agent = "Ruby/#{RUBY_VERSION}" end |
Instance Method Details
#get_currencies ⇒ Object
27 28 29 30 31 |
# File 'lib/openexchangerates.rb', line 27 def get_currencies() json = URI.open("#{@@url}currencies.json?app_id=#{@api_key}", 'User-Agent' => @user_agent).read return json end |
#get_latest ⇒ Object
15 16 17 18 19 |
# File 'lib/openexchangerates.rb', line 15 def get_latest() json = URI.open("#{@@url}latest.json?app_id=#{@api_key}", 'User-Agent' => @user_agent).read return json end |
#get_old(date) ⇒ Object
YYYY-MM-DD
21 22 23 24 25 |
# File 'lib/openexchangerates.rb', line 21 def get_old(date) # YYYY-MM-DD json = URI.open("#{@@url}historical/#{date}.json?app_id=#{@api_key}", 'User-Agent' => @user_agent).read return json end |
#set_userAgent(user_agent) ⇒ Object
11 12 13 |
# File 'lib/openexchangerates.rb', line 11 def set_userAgent(user_agent) @user_agent = user_agent end |