apilayer Gem Version

Ruby wrapper for various services of apilayer. See apilayer.com for more details.

Version 1.4

Added .change and .list to Apilayer::Currency

Version 1.3

Added .timeframe to Apilayer::Currency

Version 1.2

Added .convert to Apilayer::Currency

Version 1.1

  • Major change to how .live and .historical in Apilayer::Currency are invoked.

  • Added :source option to Apilayer::Currency.live and Apilayer::Currency.historical methods. This option is only available to paid users of currencylayer.

Installation

Using Bundler

Add apilayer in your Gemfile:

gem "apilayer"

Run the following in your console:

$ bundle install

Usage

Set up Apilayer

Once you sign up for a service of apilayer, you will receive an access_key. Please pay attention that different services of apilayer (such as vatlayer and currencylayer) have different access keys.

Then you can use your access_key(s) to configure your Apilayer module like this:

Apilayer.configure do |configs|
  configs.vat_key = "my_vatlayer_access_key_123"
  configs.currency_key = "my_currencylayer_access_key_123"
end

Please note that you don't need to assign keys for both services. You only need to assign the key for the service you have signed up for.

Once that is done, 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]})

vatlayer

After setting the access_key for vatlayer, you can use Apilayer::Vat to call vatlayer's API

Apilayer::Vat.validate("LU26375245")
Apilayer::Vat.rate(:country_code, "NL")
Apilayer::Vat.rate(:ip_address, "176.249.153.36")
Apilayer::Vat.rate_list
Apilayer::Vat.price(100, :country, "NL")
Apilayer::Vat.price(100, :ip_address, "176.249.153.36")

Re-Configure Apilayer's access_keys

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

# Example: reconfigure access_key for vatlayer
Apilayer::Vatlayer.reset_connection
Apilayer.configure do |configs|
  configs.vat_key = "my_valid_key_123"
end