Class: Exchange::ExternalAPI::OpenExchangeRates

Inherits:
Base
  • Object
show all
Defined in:
lib/exchange/external_api/open_exchange_rates.rb

Overview

The Open Exchange Rates API class, handling communication with the Open Source Currency bot API You can find further information on the Open Exchange Rates API here: openexchangerates.org

Author:

  • Beat Richartz

Since:

  • 0.1

Version:

  • 0.1

Constant Summary collapse

API_URL =

The base of the Open Exchange Rates exchange API

Since:

  • 0.1

'openexchangerates.org/api'
CURRENCIES =

The currencies the Open Exchange Rates API can convert

Since:

  • 0.1

[:xcd, :usd, :sar, :rub, :nio, :lak, :nok, :omr, :amd, :cdf, :kpw, :cny, :kes, :zwd, :khr, :pln, :mvr, :gtq, :clp, :inr, :bzd, :myr, :hkd, :sek, :cop, :dkk, :byr, :lyd, :ron, :dzd, :bif, :ars, :gip, :bob, :xof, :std, :ngn, :pgk, :aed, :mwk, :cup, :gmd, :zwl, :tzs, :cve, :btn, :xaf, :ugx, :syp, :mad, :mnt, :lsl, :top, :shp, :rsd, :htg, :mga, :mzn, :lvl, :fkp, :bwp, :hnl, :eur, :egp, :chf, :ils, :pyg, :lbp, :ang, :kzt, :wst, :gyd, :thb, :npr, :kmf, :irr, :uyu, :srd, :jpy, :brl, :szl, :mop, :bmd, :xpf, :etb, :jod, :idr, :mdl, :mro, :yer, :bam, :awg, :nzd, :pen, :vef, :try, :sll, :aoa, :tnd, :tjs, :sgd, :scr, :lkr, :mxn, :ltl, :huf, :djf, :bsd, :gnf, :isk, :vuv, :sdg, :gel, :fjd, :dop, :xdr, :mur, :php, :mmk, :krw, :lrd, :bbd, :zmk, :zar, :vnd, :uah, :tmt, :iqd, :bgn, :gbp, :kgs, :ttd, :hrk, :rwf, :clf, :bhd, :uzs, :twd, :crc, :aud, :mkd, :pkr, :afn, :nad, :bdt, :azn, :czk, :sos, :iep, :pab, :qar, :svc, :sbd, :all, :jmd, :bnd, :cad, :kwd, :ghs]

Instance Attribute Summary

Attributes inherited from Base

#base, #cache, #helper, #rates, #timestamp

Instance Method Summary collapse

Methods inherited from Base

#convert, #initialize, #rate, #test_for_rates_and_raise_if_nil, #to_hash!

Constructor Details

This class inherits a constructor from Exchange::ExternalAPI::Base

Instance Method Details

#update(opts = {}) ⇒ Object

Updates the rates by getting the information from Open Exchange Rates for today or a defined historical date The call gets cached for a maximum of 24 hours.

Examples:

Update the Open Exchange Rates API to use the file of March 2, 2010

Exchange::ExternalAPI::OpenExchangeRates.new.update(:at => Time.gm(3,2,2010))

Parameters:

  • opts (Hash) (defaults to: {})

    Options to define for the API Call

Options Hash (opts):

  • :at (Time, String)

    a historical date to get the exchange rates for

Since:

  • 0.1



27
28
29
30
31
32
33
34
35
# File 'lib/exchange/external_api/open_exchange_rates.rb', line 27

def update opts={}
  time = helper.assure_time(opts[:at])
  
  Call.new(api_url(time), :at => time, :api => self.class) do |result|
    @base                 = result['base'].downcase.to_sym
    @rates                = extract_rates(result)
    @timestamp            = result['timestamp'].to_i
  end
end