Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A gem that calculates the exchange rate using published rates from open-exchange-rates. Compatible with the money gem.
Ruby

README.md

Money Open Exchange Rates

A gem that calculates the exchange rate using published rates from open-exchange-rates

Usage

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/signup'
moe.update_rates

# (optional)
# set the seconds after than the current rates are automatically expired
# by default, they never expire, in this example 1 day.
moe.ttl_in_seconds = 86400
# (optional)
# use https to fetch rates from Open Exchange Rates
# disabled by default to support free-tier users
moe.secure_connection = true
# Store in cache
moe.save_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

Tests

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 or environment variable named TEST_APP_ID and then run:

bundle exec rake

Refs

Contributors

See GitHub.

License

The MIT License

Copyright © 2011-2015 Laurent Arnoud laurent@spkdev.net


Gem Version Build Status Code Climate Inline docs License

Something went wrong with that request. Please try again.