A gem that calculates the exchange rate using published rates from open-exchange-rates
require 'money/bank/open_exchange_rates_bank'
moe = Money::Bank::OpenExchangeRatesBank.new
moe.cache = 'path/to/file/cache'
moe.app_id = 'your app id from https://openexchangerates.org/#'
moe.update_rates
Money.default_bank = moe
You can also provide a Proc as a cache to provide your own caching mechanism
perhaps with Redis or just a thread safe Hash
(global). For example:
moe.cache = Proc.new do |v|
key = 'money:exchange_rates']
if v
Thread.current[key] = v
else
Thread.current[key]
end
end
As of the end of August 2012 all requests to the Open Exchange Rates API must have a valid app_id. You can place your own key on a file named TEST_APP_ID and then run:
bundle exec ruby test/open_exchange_rates_bank_test.rb
- https://github.com/currencybot/open-exchange-rates
- https://github.com/RubyMoney/money
- https://github.com/RubyMoney/eu_central_bank
- https://github.com/RubyMoney/google_currency
The MIT License
Copyright © 2012 Laurent Arnoud laurent@spkdev.net