Class: Exchange::ExternalAPI::XavierMedia

Inherits:
XML
  • Object
show all
Defined in:
lib/exchange/external_api/xavier_media.rb

Overview

The XavierMedia API class, handling communication with the Xavier Media Currency API You can find further information on the Xaviermedia API here: www.xavierforum.com/viewtopic.php?f=5&t=10979&sid=671a685edbfa5dbec219fbc6793d5057

Author:

  • Beat Richartz

Since:

  • 0.1

Version:

  • 0.7

Constant Summary collapse

API_URL =

The base of the Xaviermedia API URL

Since:

  • 0.1

"api.finance.xaviermedia.com/api"
CURRENCIES =

The currencies the Xaviermedia API URL can handle

Since:

  • 0.1

[:eur, :usd, :jpy, :gbp, :cyp, :czk, :dkk, :eek, :huf, :ltl, :mtl, :pln, :sek, :sit, :skk, :chf, :isk, :nok, :bgn, :hrk, :rol, :ron, :rub, :trl, :aud, :cad, :cny, :hkd, :idr, :krw, :myr, :nzd, :php, :sgd, :thb, :zar]

Instance Attribute Summary

Attributes inherited from Base

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

Instance Method Summary collapse

Methods inherited from XML

#initialize

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::XML

Instance Method Details

#update(opts = {}) ⇒ Object

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

Examples:

Update the currency bot API to use the file of March 2, 2010

Exchange::ExternalAPI::XavierMedia.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

Version:

  • 0.7



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

def update opts={}
  time       = helper.assure_time(opts[:at], :default => :now)
  api_url    = api_url(time)
  
  Call.new(api_url, api_opts(opts.merge(:at => time, :api => self.class))) do |result|
    @base                 = extract_base_currency result
    @rates                = extract_rates result
    @timestamp            = extract_timestamp result
  end
end