Project

vatlayer

0.0
No commit activity in last 3 years
No release in over 3 years
A Ruby wrapper around vatlayer.com API.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.1
~> 3.0
~> 0.54
>= 12.3.3

Runtime

~> 4.2
 Project Readme

Vatlayer

Build Status codecov.io

The Ruby gem for accessing the Vatlayer API painlessly, easily and awesomely! Be sure to check the branch for the version you're using.

Important and helpful links:

Installation

Add this line to your application's Gemfile:

gem 'vatlayer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install vatlayer

Usage

require 'vatlayer'
vatlayer = Vatlayer.new('Your API access key')

You can find your API key in your Vatlayer account, by reference. API access is available for every Vatlayer account.

Configuration

API keys must be configured in the gem setup. You can do this anywhere in your application before you make API calls using the gem. You can find your API key in your Vatlayer account, by reference. API access is available for every Vatlayer account.

Vatlayer.configure do |config|
  config.access_key = 'a1sad2f4g2srf'
  config.https = true
end
  • config.access_key - your Vatlayer access key
  • config.https - you can use https mode, default false

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

Available methods

Creating an instance of the Vatlayer client:

vatlayer = Vatlayer.new('Your API access key')

If you've configured the gem with a default access_key, then you can just instantiate the class.

vatlayer = Vatlayer.new

Validate

vatlayer.validate(vat_number: 'LU26375245')

# <Vatlayer::Response::Data:0x0000555fd334ba10
#            @valid=true,
#            @database="ok",
#            @format_valid=true,
#            @query="LU26375245",
#            @country_code="LU",
#            @vat_number="26375245",
#            @company_name="AMAZON EUROPE CORE S.A R.L.",
#            @company_address="5, RUE PLAETIS L-2338  LUXEMBOURG">

Rate

vatlayer.rate(country_code: 'gb')

# <Vatlayer::Response::Data:0x000055c949f35210
#            @success=true,
#            @country_code="GB",
#            @country_name="United Kingdom",
#            @standard_rate=20,
#            @reduced_rates=#<Vatlayer::Response::Data:0x000055c949f344f0
#                            @property_renovations=5,
#                            @foodstuffs=0,
#                            @books=0,
#                            @pharmaceuticals=0,
#                            @medical=0,
#                            @passenger_transport=0,
#                            @newspapers=0,
#                            @childrens_clothing=0>>

Also rate method takes parameters like ip_address, use_client_ip.

Rate list

vatlayer.rate_list

# <Vatlayer::Response::Data:0x0000564e0063b308
#   @rates=#<Vatlayer::Response::Data:0x0000564e00639d78
#   @at=#<Vatlayer::Response::Data:0x0000564e00638b30
#     @country_name="Austria",
#     @reduced_rates=#<Vatlayer::Response::Data:0x0000564e0062e270
#                     @admission_to_cultural_events=10,
#                     @admission_to_entertainment_events=10,
#                     @books=10,
#                     @foodstuffs=10,
#                     @hotels=10,
#                     @newspapers=10,
#                     @passenger_transport=10,
#                     @pharmaceuticals=10>,
#     @standard_rate=20>

Price

vatlayer.price(amount: 100, country_code: 'GB', options: { type: 'medical' })

# <Vatlayer::Response::Data:0x00005564aa23e880
#            @success=true,
#            @country_code="GB",
#            @country_name="United Kingdom",
#            @price_excl_vat=100,
#            @price_incl_vat=100,
#            @type="medical",
#            @vat_rate=0>

Also price method takes parameters like ip_address, use_client_ip and optional parameters type, incl.

Fetch errors

vatlayer = Vatlayer.new('invalid_access_key')
vatlayer.validate('LU26375245')

# <Vatlayer::Response::Data:0x0000555fd3379c80
#            @success=false,
#            @error=#<Vatlayer::Response::Error:0x0000555fd33797d0
#                               @code=101,
#                               @type="invalid_access_key",
#                               @info="You have not supplied a valid API Access Key. [Technical Support: support@apilayer.com]">

License

The Vatlayer GEM is released under the MIT License.

Contributing

  1. Fork it
  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