Skip to content

Privy/fixer_currency

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code
This branch is 11 commits ahead, 6 commits behind RubyMoney:master.

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Fixer Currency

This gem extends Money::Bank::VariableExchange with Money::Bank::FixerCurrency and gives you access to the current fixer.io exchange rates.

This gem was forked from the Money::Bank::GoogleCurrency gem.

Installation

If the money gem is not already installed:

gem install money

Install the fixer_currency gem:

gem install fixer_currency

Usage

require 'money'
require 'money/bank/fixer_currency'

# (optional)
# set the seconds after than the current rates are automatically expired
# by default, they never expire
Money::Bank::FixerCurrency.ttl_in_seconds = 86400

# set default bank to instance of FixerCurrency with access key parameter
# being your access_key from fixer.io
Money.default_bank = Money::Bank::FixerCurrency.new('your_access_key')

# create a new money object, and use the standard #exchange_to method
money = Money.new(1_00, "USD") # amount is in cents
money.exchange_to(:EUR)

# or install and use the 'monetize' gem
require 'monetize'
money = 1.to_money(:USD)
money.exchange_to(:EUR)

An UnknownRate will be thrown if #exchange_to is called with a Currency that Money knows, but fixer.io does not.

An UnknownCurrency will be thrown if #exchange_to is called with a Currency that Money does not know.

A FixerCurrencyFetchError will be thrown if there is an unknown issue with parsing the response including rates from fixer.io's API.

Caveats

This gem uses fixer.io under the hood.

About

A Ruby Money::Bank interface for fixer.io exchange data

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%