0.0
No commit activity in last 3 years
No release in over 3 years
Ruby wrapper for currencylayer by apilayer. This gem depends on the apilayer gem, which provides a common connection-interface to various services of apilayer.net (such as currencylayer and vatlayer). See https://currencylayer.com/ and https://apilayer.com/ for more details.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
~> 0.11
~> 12.1
~> 3.7
~> 0.14
~> 4.0
~> 3.4

Runtime

~> 2.1
 Project Readme

Ruby wrapper for currencylayer of apilayer. See currencylayer.com/ and apilayer.com for more details.

Introduction¶ ↑

This gem is extracted from the previous version of apilayer gem.

While the currency_layer gem focuses on the functionalities offered by currencylayer, it depends on the apilayer gem to configure and create connections to apilayer.net

Installation¶ ↑

Using Bundler¶ ↑

Add apilayer in your Gemfile:

gem "currency_layer"

Run the following in your console:

$ bundle install

Usage¶ ↑

Add to your application¶ ↑

require "currency_layer"

Set up currency_layer¶ ↑

Once you have signed up for currencylayer.com, you will receive an access_key. Then configure your Apilayer::Currency module like this:

Apilayer::Currency.configure do |configs|
  configs.access_key = "my_access_key_123"
  configs.https = true
end

Please note that the https configuration is optional and only available to paid-accounts. If unset, these configuration-values are just nil.

You can always review you configurations with:

Apilayer::Currency.configs

Once your configurations are set, you are ready to go

currencylayer¶ ↑

After setting the access_key for currencylayer, you can use Apilayer::Currency to call currencylayer’s API

Apilayer::Currency.list

Apilayer::Currency.live
Apilayer::Currency.live(:currencies => %w[GBP, CHF])
Apilayer::Currency.live(:source => "EUR") # source-currency is USD by default
Apilayer::Currency.live(:source => "EUR", :currencies => %w[GBP, CHF])

Apilayer::Currency.historical("2016-01-01")
Apilayer::Currency.historical("2016-01-01", :currencies => %w[GBP CHF])
Apilayer::Currency.historical(:source => "EUR") # source-currency is USD by default
Apilayer::Currency.historical("2016-01-01", :currencies => %w[GBP CHF], :source => "EUR")

Apilayer::Currency.convert("EUR", "CHF", 100) # convert 100 EUR to CHF
Apilayer::Currency.convert("EUR", "CHF", 100, "2015-06-01") # based on specific date

Apilayer::Currency.timeframe("2016-01-01", "2016-06-01")
Apilayer::Currency.timeframe("2016-01-01", "2016-06-01", :currencies => %w[GBP CHF])
Apilayer::Currency.timeframe("2016-01-01", "2016-06-01", :source => "EUR")
Apilayer::Currency.timeframe("2016-01-01", "2016-06-01", :currencies => %w[GBP CHF], :source => "EUR")

Apilayer::Currency.change
Apilayer::Currency.change("2016-01-01", "2016-03-01")
Apilayer::Currency.change("2016-01-01", "2016-03-01", :source => "EUR")
Apilayer::Currency.change("2016-01-01", "2016-03-01", :currencies => %w[GBP CHF])
Apilayer::Currency.change("2016-01-01", "2016-03-01", :source => "EUR", :currencies => %w[GBP CHF])
Apilayer::Currency.change(nil, nil, {:source => "EUR"})
Apilayer::Currency.change(nil, nil, {:currencies => %w[GBP CHF]})
Apilayer::Currency.change(nil, nil, {:source => "EUR", :currencies => %w[GBP CHF]})

Re-Configure access_key and https¶ ↑

If you happened to have forgotten to set or entered an incorrect value, you can re-configure your Apilayer module by:

# Example: reconfigure https
Apilayer::Currency.configure do |configs|
  configs.https = true
end