Sha256: 8f2ce5a44feea740921a6578a7971b570046ff62178248fe787df5dd6504ae78

Contents?: true

Size: 1.03 KB

Versions: 5

Compression:

Stored size: 1.03 KB

Contents

# -*- encoding : utf-8 -*-
module Exchange
  module ExternalAPI
    
    # The Random API class, which is only intended for use in development mode. Returns random exchange rates.
    # @author Beat Richartz
    # @version 1.0
    # @since 1.0
    #
    class Random < Base
      
      CURRENCIES           = Exchange::ISO.currencies
      RANDOM_RATES         = lambda { Hash[*CURRENCIES.map{|c| [c, rand] }.flatten] }
      
      # Updates the rates with new random ones
      # The call gets cached for a maximum of 24 hours.
      # @version 0.7
      # @param [Hash] opts Options to define for the API Call
      # @option opts [Time, String] :at a historical date to get the exchange rates for
      # @example Update the currency bot API to use the file of March 2, 2010
      #   Exchange::ExternalAPI::XavierMedia.new.update(:at => Time.gm(3,2,2010))
      #
      def update opts={}
        @base                 = :usd
        @rates                = RANDOM_RATES.call
        @timestamp            =  Time.now.to_i
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
exchange-1.2.2 lib/exchange/external_api/random.rb
exchange-1.2.1 lib/exchange/external_api/random.rb
exchange-1.2.0 lib/exchange/external_api/random.rb
exchange-1.1.1 lib/exchange/external_api/random.rb
exchange-1.1.0 lib/exchange/external_api/random.rb