Code Monkey home page Code Monkey logo

money-open-exchange-rates's Introduction

Money Open Exchange Rates

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

Installation

Add this line to your application's Gemfile:

gem 'money-open-exchange-rates'

And then execute:

bundle

Or install it yourself as:

gem install money-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

Unknown pair rates are transparently calculated: using inverse rate (if known), or using base currency rate to both currencies forming the pair.

Tests

bundle exec rake

Refs

Contributors

See GitHub.

License

The MIT License

Copyright © 2011-2016 Laurent Arnoud [email protected]


Build Version Documentation License Code Climate Inline docs

money-open-exchange-rates's People

Contributors

cover avatar dm1try avatar joshthewanderer avatar kball avatar mtcmorris avatar phallstrom avatar rsharrott avatar samlown avatar spk avatar tim3z avatar weynsee avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.