Coder Social home page Coder Social logo

streetbees / currencylayer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from buru/currencylayer

0.0 4.0 1.0 451 KB

This gem extends Money::Bank::VariableExchange with Money::Bank::Currencylayer and gives you access to the current exchange rates on currencylayer.com.

License: MIT License

Ruby 100.00%
fork

currencylayer's Introduction

Currencylayer

Build Status

This gem extends Money::Bank::VariableExchange of gem money and gives you access to the current exchange rates using currencylayer.com

GitHub Pages Website

Features

  • supports 168 currencies
  • precision of rates up to 6 digits after point
  • uses fast and reliable json api
  • average response time < 20ms
  • supports caching currency rates

Installation

Add this line to your application's Gemfile:

gem 'currencylayer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install currencylayer

Usage

First, you should to register account on currencylayer.com and get your personal access_key.

require 'money'
require 'money/bank/currencylayer'

# (optional)
# set the seconds after than the current rates are automatically expired
# by default, they never expire
Money::Bank::Currencylayer.ttl_in_seconds = 7200 # 2 hours ttl

# set careful mode - each rate stores with created_at time to cache and will be flushed
# only if their time is out. If you get exception while request new rate, bank will
# return cached value if present
# by default false
Money::Bank::Currencylayer.rates_careful = true

# create new bank instance
bank = Money::Bank::Currencylayer.new

# create new bank instance with block specifying rounding of exchange result
bank = Money::Bank::Currencylayer.new {|n| n.round(4)} # round result to 4 digits after point

# specify your access_key from currencylayer.com
bank.access_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

# set default bank to instance
Money.default_bank = bank

Also you can setup Currencylayer as default_bank for money-rails gem in config/initializers/money.rb

require 'money/bank/currencylayer'
MoneyRails.configure do |config|

  bank = Money::Bank::Currencylayer.new
  bank.access_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
  config.default_bank = bank

end

An AccessError will be thrown if access_key was not specified.

An RequestError will be thrown if currencylayer.com api returns error on api request.

Refs

Created using VariableExchange implementation and using google_currency basics.

More implementations:

Contributing

  1. Fork it ( https://github.com/[my-github-username]/currencylayer/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

currencylayer's People

Contributors

coding-bunny avatar buru avatar

Watchers

James Cloos avatar Sam Lowe avatar Ricardo Marques Ramos avatar  avatar

Forkers

semmin

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.