Skip to content
A gem that calculates the exchange rate using published rates from open-exchange-rates. Compatible with the money gem.
Ruby
Latest commit 81e8458 Mar 12, 2016 @spk Update rubocop to 0.38
Failed to load latest commit information.
lib Always use raise to signal exceptions Mar 12, 2016
test Update rubocop and add frozen_string_literal Jan 16, 2016
.gitignore Refactoring to cope with Proc for cache, allowing greater flexibility Sep 15, 2012
.travis.yml Use last rubinius binary on travis Jan 17, 2016
Gemfile
History.md Bump to v0.4.1 Dec 6, 2015
LICENSE
README.md Update year Jan 16, 2016
Rakefile Remove inch from dev tools for ruby 1.9 Jan 16, 2016
money-open-exchange-rates.gemspec

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
# see https://openexchangerates.org/documentation#https
moe.secure_connection = true
# (optional)
# set historical date of the rate
# see https://openexchangerates.org/documentation#historical-data
moe.date = '2015-01-01'
# 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

bundle exec rake

Refs

Contributors

See GitHub.

License

The MIT License

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


Build Version Documentation License Code Climate Inline docs

Something went wrong with that request. Please try again.