Class: Exchange::ExternalAPI::Random

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

Overview

The Random API class, which is only intended for use in development mode. Returns random exchange rates.

Author:

  • Beat Richartz

Since:

  • 1.0

Version:

  • 1.0

Constant Summary collapse

CURRENCIES =

Since:

  • 1.0

Exchange::ISO.currencies
RANDOM_RATES =

Since:

  • 1.0

lambda { Hash[*CURRENCIES.map{|c| [c, rand] }.flatten] }

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 with new random ones 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:

  • 1.0

Version:

  • 0.7


23
24
25
26
27
# File 'lib/exchange/external_api/random.rb', line 23

def update opts={}
  @base                 = :usd
  @rates                = RANDOM_RATES.call
  @timestamp            =  Time.now.to_i
end