europe.rb

:eu: Europe is a ruby library for retrieving EU data such as VAT rates, VAT validation, currency exchange rates and country information.

4
0
Ruby

Europe gem logo

Europe 🇪🇺

This gem provides EU governmental data, extracted from various EU / EC websites. With this gem you can validate VAT numbers, retrieve VAT tax rates and currency exchange rates matched to the Euro. How to use this gem is pretty straightforward and written below.

Table of Contents

Installation

Add this line to your application’s Gemfile:

gem 'europe'

And then execute:

$ bundle

Or install it yourself as:

$ gem install europe

Usage

There are several calls you can make with this gem. Below are a few examples
where this gem can be used for.

Validating VAT numbers

** Updated: Parameter now consists of one value.**
Call to validate VAT number (always starts with country code as specified in VIES)

Europe::Vat.validate('NL009291477B01')

Response

{ :country_code => "NL",
  :vat_number => "009291477B01",
  :request_date => #<Date: 2015-12-15 ((2457372j,0s,0n),+0s,2299161j)>,
  :valid => true,
  :name => "KONINKLIJKE POSTNL B.V.",
  :address => nil }

Validate VAT number format

Call

Europe::Vat::Format.validate('NL123456789B01')

Response

=> true

Validate Postal Code format

Call

Europe::Postal.validate('NL', '1000 AP')

Response

=> true

Retrieving VAT rates for each EC/EU member

Call

Europe::Vat::Rates.retrieve

Response

{  :AT=>20.0,
   :BE=>21.0,
   :BG=>20.0,
   :CY=>19.0,
   :CZ=>21.0,
   :DE=>19.0,
   :DK=>25.0,
   # etc...

Retrieving currency exchange rates

Call

Europe::Currency::ExchangeRates.retrieve

Response

{  :date=>#<Date: 2015-12-15 ((2457372j,0s,0n),+0s,2299161j)>,
   :rates=>
   { :USD=>1.099,
     :JPY=>132.97,
     :BGN=>1.9558,
     :CZK=>27.022,
     :DKK=>7.4614,
     :GBP=>0.7252,
     # etc...

Retrieving currency information

Call

Europe::Currency::CURRENCIES

Response

CURRENCIES = {
  EUR: { name: 'Euro', symbol: '€', html: '&euro;' },
  BGN: { name: 'Lev', symbol: 'лв', html: '&#1083;&#1074;' },
  # etc...

Retrieving country information

Call

Europe::Countries::COUNTRIES

Response

{
 :BE=>
  {:name=>"Belgium",
   :source_name=>"Belgique/België",
   :official_name=>"Kingdom of Belgium",
   :tld=>".be",
   :currency=>:EUR,
   :capital=>"Brussels"},
 :BG=>
  {:name=>"Bulgaria",
   :source_name=>"България",
   :official_name=>"Republic of Bulgaria",
   :tld=>".bg",
   :currency=>:BGN,
   :capital=>"Sofia"},
 # etc...

Retrieving country information reversed

Call with optional parameters (name, currency, source_name, official_name, tld, currency and capital)

Europe::Countries::Reversed.generate('name')

Response

{  "Belgium" => :BE,
   "Bulgaria" => :BG,
   "Czech Republic" => :CZ,
   "Denmark" => :DK,
   "Germany" => :DE,
   "Estonia" => :EE,
   # etc...

Compatibility

This gem is tested with the following Ruby versions on Linux and Mac OS X:

  • Ruby > 2.2.2

Todo

Contributing

  1. Fork it ( https://github.com/gem-shards/europe.rb/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