europe 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +15 -0
- data/.pryrc +14 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +22 -0
- data/README.md +126 -0
- data/Rakefile +10 -0
- data/europe.gemspec +30 -0
- data/lib/europe.rb +8 -0
- data/lib/europe/countries/countries.rb +103 -0
- data/lib/europe/currency/currency.rb +23 -0
- data/lib/europe/currency/exchange_rates.rb +29 -0
- data/lib/europe/vat/rates.rb +58 -0
- data/lib/europe/vat/vat.rb +32 -0
- data/lib/europe/version.rb +4 -0
- data/test/europe/countries/country_test.rb +16 -0
- data/test/europe/currency/currency_test.rb +18 -0
- data/test/europe/currency/exchange_rates_test.rb +17 -0
- data/test/europe/vat/rates_test.rb +19 -0
- data/test/europe/vat/validation_test.rb +29 -0
- data/test/test_helper.rb +5 -0
- metadata +171 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: de67a9a0a75909308ceba08e914998b551daa158
|
4
|
+
data.tar.gz: 2f1ff149e70373a95aafb104e29b5353639aaeab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cff8f406e3666c2d54a76670c6ebcad127b5a92db31b888d678983e90893fa20f7cf75d532a5d2702e0d79bf2d13f45932b0264a2514c981528da570bb549091
|
7
|
+
data.tar.gz: 103b78ce13b51964788c26c6234a7d5bdfafc87d50781859e045de7485018d852725c93dea4f13795d7903eb31c631ccf78ac9c34f00c1b8a522b4388d7f747c
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.pryrc
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# .pryrc
|
2
|
+
require 'europe'
|
3
|
+
|
4
|
+
Pry.config.commands.import(Pry::CommandSet.new do
|
5
|
+
|
6
|
+
command "reload!", "Reload Pry" do
|
7
|
+
target.eval <<-EVAL
|
8
|
+
at_exit { puts "Reloading pry..."; exec "pry" }
|
9
|
+
exit
|
10
|
+
EVAL
|
11
|
+
end
|
12
|
+
|
13
|
+
alias_command "r", "reload!"
|
14
|
+
end)
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Vincent
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 VvanGemert
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
# Europe
|
2
|
+
|
3
|
+
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.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'europe'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install europe
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
There are several calls you can make with this gem. Below are a few examples
|
24
|
+
where this gem can be used for.
|
25
|
+
|
26
|
+
### Validating VAT numbers
|
27
|
+
Call
|
28
|
+
```ruby
|
29
|
+
Europe::Vat.validate('GB', '440627467')
|
30
|
+
```
|
31
|
+
Response
|
32
|
+
```ruby
|
33
|
+
{ :country_code=>"GB",
|
34
|
+
:vat_number=>"440627467",
|
35
|
+
:request_date=>#<Date: 2015-12-15 ((2457372j,0s,0n),+0s,2299161j)>,
|
36
|
+
:valid=>true,
|
37
|
+
:name=>"SKY PLC",
|
38
|
+
:address=>"6 CENTAURS BUSINESS PARK\nGRANT WAY\nISLEWORTH\nMIDDLESEX\n\nTW7 5QD" }
|
39
|
+
```
|
40
|
+
|
41
|
+
### Retrieving VAT rates for each EC/EU member
|
42
|
+
Call
|
43
|
+
```ruby
|
44
|
+
Europe::Vat::Rates.retrieve
|
45
|
+
```
|
46
|
+
Response
|
47
|
+
```ruby
|
48
|
+
{ :AT=>20.0,
|
49
|
+
:BE=>21.0,
|
50
|
+
:BG=>20.0,
|
51
|
+
:CY=>19.0,
|
52
|
+
:CZ=>21.0,
|
53
|
+
:DE=>19.0,
|
54
|
+
:DK=>25.0,
|
55
|
+
# etc...
|
56
|
+
```
|
57
|
+
|
58
|
+
### Retrieving currency exchange rates
|
59
|
+
Call
|
60
|
+
```ruby
|
61
|
+
Europe::Currency::ExchangeRates.retrieve
|
62
|
+
```
|
63
|
+
Response
|
64
|
+
```ruby
|
65
|
+
{ :date=>#<Date: 2015-12-15 ((2457372j,0s,0n),+0s,2299161j)>,
|
66
|
+
:rates=>
|
67
|
+
{ :USD=>1.099,
|
68
|
+
:JPY=>132.97,
|
69
|
+
:BGN=>1.9558,
|
70
|
+
:CZK=>27.022,
|
71
|
+
:DKK=>7.4614,
|
72
|
+
:GBP=>0.7252,
|
73
|
+
# etc...
|
74
|
+
```
|
75
|
+
|
76
|
+
### Retrieving currency information
|
77
|
+
Call
|
78
|
+
```ruby
|
79
|
+
Europe::Currency::CURRENCIES
|
80
|
+
```
|
81
|
+
Response
|
82
|
+
```ruby
|
83
|
+
CURRENCIES = {
|
84
|
+
EUR: { name: 'Euro', symbol: '€', html: '€' },
|
85
|
+
BGN: { name: 'Lev', symbol: 'лв', html: 'лв' },
|
86
|
+
```
|
87
|
+
|
88
|
+
## Retrieving country information
|
89
|
+
Call
|
90
|
+
```ruby
|
91
|
+
Europe::Countries::COUNTRIES
|
92
|
+
```
|
93
|
+
Response
|
94
|
+
```ruby
|
95
|
+
{ :BE=>{
|
96
|
+
:name=>"Belgium",
|
97
|
+
:source_name=>"Belgique/België",
|
98
|
+
:official_name=>"Kingdom of Belgium" },
|
99
|
+
:BG=>{
|
100
|
+
:name=>"Bulgaria",
|
101
|
+
:source_name=>"България",
|
102
|
+
:official_name=>"Republic of Bulgaria" },
|
103
|
+
```
|
104
|
+
|
105
|
+
## Retrieving country information reversed
|
106
|
+
Call
|
107
|
+
```ruby
|
108
|
+
Europe::Countries.name_to_code
|
109
|
+
```
|
110
|
+
Response
|
111
|
+
```ruby
|
112
|
+
{ "Belgium" => :BE,
|
113
|
+
"Bulgaria" => :BG,
|
114
|
+
"Czech Republic" => :CZ,
|
115
|
+
"Denmark" => :DK,
|
116
|
+
"Germany" => :DE,
|
117
|
+
"Estonia" => :EE,
|
118
|
+
```
|
119
|
+
|
120
|
+
## Contributing
|
121
|
+
|
122
|
+
1. Fork it ( https://github.com/VvanGemert/europe/fork )
|
123
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
124
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
125
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
126
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/europe.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'europe/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'europe'
|
8
|
+
spec.version = Europe::VERSION
|
9
|
+
spec.authors = ['VvanGemert']
|
10
|
+
spec.email = ['vincent@floorplanner.com']
|
11
|
+
spec.summary = 'Europe is a helper gem for retrieving \
|
12
|
+
EU government data'
|
13
|
+
spec.description = 'This gem retrieves data from EU government websites'
|
14
|
+
spec.homepage = ''
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'nokogiri', '~> 1.6'
|
23
|
+
spec.add_dependency 'savon', '~> 2.10.0'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'minitest'
|
28
|
+
spec.add_development_dependency 'awesome_print'
|
29
|
+
spec.add_development_dependency 'pry'
|
30
|
+
end
|
data/lib/europe.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
# Source: http://publications.europa.eu/code/pdf/370000en.htm
|
5
|
+
|
6
|
+
# Europe Gem
|
7
|
+
module Europe
|
8
|
+
# Countries
|
9
|
+
module Countries
|
10
|
+
COUNTRIES = {
|
11
|
+
BE: { name: 'Belgium',
|
12
|
+
source_name: 'Belgique/België',
|
13
|
+
official_name: 'Kingdom of Belgium' },
|
14
|
+
BG: { name: 'Bulgaria',
|
15
|
+
source_name: 'България',
|
16
|
+
official_name: 'Republic of Bulgaria' },
|
17
|
+
CZ: { name: 'Czech Republic',
|
18
|
+
source_name: 'Česká republika',
|
19
|
+
official_name: 'Czech Republic' },
|
20
|
+
DK: { name: 'Denmark',
|
21
|
+
source_name: 'Danmark',
|
22
|
+
official_name: 'Kingdom of Denmark' },
|
23
|
+
DE: { name: 'Germany',
|
24
|
+
source_name: 'Deutschland',
|
25
|
+
official_name: 'Federal Republic of Germany' },
|
26
|
+
EE: { name: 'Estonia',
|
27
|
+
source_name: 'Eesti',
|
28
|
+
official_name: 'Republic of Estonia' },
|
29
|
+
IE: { name: 'Ireland',
|
30
|
+
source_name: 'Éire',
|
31
|
+
official_name: 'Ireland' },
|
32
|
+
EL: { name: 'Greece',
|
33
|
+
source_name: 'Ελλάδα',
|
34
|
+
official_name: 'Hellenic Republic' },
|
35
|
+
ES: { name: 'Spain',
|
36
|
+
source_name: 'España',
|
37
|
+
official_name: 'Kingdom of Spain' },
|
38
|
+
FR: { name: 'France',
|
39
|
+
source_name: 'France',
|
40
|
+
official_name: 'French Republic' },
|
41
|
+
HR: { name: 'Croatia',
|
42
|
+
source_name: 'Hrvatska',
|
43
|
+
official_name: 'Republic of Croatia' },
|
44
|
+
IT: { name: 'Italy',
|
45
|
+
source_name: 'Italia',
|
46
|
+
official_name: 'Italian Republic' },
|
47
|
+
CY: { name: 'Cyprus',
|
48
|
+
source_name: 'Κύπρος',
|
49
|
+
official_name: 'Republic of Cyprus' },
|
50
|
+
LV: { name: 'Latvia',
|
51
|
+
source_name: 'Latvija',
|
52
|
+
official_name: 'Republic of Latvia' },
|
53
|
+
LT: { name: 'Lithuania',
|
54
|
+
source_name: 'Lietuva',
|
55
|
+
official_name: 'Republic of Lithuania' },
|
56
|
+
LU: { name: 'Luxembourg',
|
57
|
+
source_name: 'Luxembourg',
|
58
|
+
official_name: 'Grand Duchy of Luxembourg' },
|
59
|
+
HU: { name: 'Hungary',
|
60
|
+
source_name: 'Magyarország',
|
61
|
+
official_name: 'Hungary' },
|
62
|
+
MT: { name: 'Malta',
|
63
|
+
source_name: 'Malta',
|
64
|
+
official_name: 'Republic of Malta' },
|
65
|
+
NL: { name: 'Netherlands',
|
66
|
+
source_name: 'Nederland',
|
67
|
+
official_name: 'Kingdom of the Netherlands' },
|
68
|
+
AT: { name: 'Austria',
|
69
|
+
source_name: 'Österreich',
|
70
|
+
official_name: 'Republic of Austria' },
|
71
|
+
PL: { name: 'Poland',
|
72
|
+
source_name: 'Polska',
|
73
|
+
official_name: 'Republic of Poland' },
|
74
|
+
PT: { name: 'Portugal',
|
75
|
+
source_name: 'Portugal',
|
76
|
+
official_name: 'Portuguese Republic' },
|
77
|
+
RO: { name: 'Romania',
|
78
|
+
source_name: 'România',
|
79
|
+
official_name: 'Romania' },
|
80
|
+
SI: { name: 'Slovenia',
|
81
|
+
source_name: 'Slovenija',
|
82
|
+
official_name: 'Republic of Slovenia' },
|
83
|
+
SK: { name: 'Slovak Republic',
|
84
|
+
source_name: 'Slovensko',
|
85
|
+
official_name: 'Slovak Republic' },
|
86
|
+
FI: { name: 'Finland',
|
87
|
+
source_name: 'Suomi',
|
88
|
+
official_name: 'Republic of Finland' },
|
89
|
+
SE: { name: 'Sweden',
|
90
|
+
source_name: 'Sverige',
|
91
|
+
official_name: 'Kingdom of Sweden' },
|
92
|
+
UK: { name: 'United Kingdom',
|
93
|
+
source_name: 'United Kingdom',
|
94
|
+
official_name: 'United Kingdom of Great ' \
|
95
|
+
'Britain and Northern Ireland' } }
|
96
|
+
|
97
|
+
def self.name_to_code
|
98
|
+
@name_to_code ||= COUNTRIES.each_with_object({}) do |(key, value), out|
|
99
|
+
out[value[:name]] = key
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
# Source: Wikipedia
|
5
|
+
require 'europe/currency/exchange_rates'
|
6
|
+
|
7
|
+
# Europe Gem
|
8
|
+
module Europe
|
9
|
+
# currency
|
10
|
+
module Currency
|
11
|
+
CURRENCIES = {
|
12
|
+
EUR: { name: 'Euro', symbol: '€', html: '€' },
|
13
|
+
BGN: { name: 'Lev', symbol: 'лв', html: 'лв' },
|
14
|
+
CZK: { name: 'Koruna', symbol: 'Kč', html: 'Kč' },
|
15
|
+
DKK: { name: 'Krone', symbol: 'kr.', html: 'kr' },
|
16
|
+
GBP: { name: 'Pound', symbol: '£', html: '£' },
|
17
|
+
HRK: { name: 'Kuna', symbol: 'kn.', html: 'kn' },
|
18
|
+
HUF: { name: 'Forint', symbol: 'Ft', html: 'Ft' },
|
19
|
+
PLN: { name: 'Zloty', symbol: 'zł', html: 'zł' },
|
20
|
+
RON: { name: 'Leu', symbol: 'lei', html: 'lei' },
|
21
|
+
SEK: { name: 'Krona', symbol: 'kr', html: 'kr' } }
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
# Europe Gem
|
5
|
+
module Europe
|
6
|
+
# currency
|
7
|
+
module Currency
|
8
|
+
# exchange rates
|
9
|
+
module ExchangeRates
|
10
|
+
EXCHANGE_URL = 'http://www.ecb.europa.eu/stats/' \
|
11
|
+
'eurofxref/eurofxref-daily.xml'
|
12
|
+
def self.retrieve
|
13
|
+
extract_rates(Nokogiri::XML(open(EXCHANGE_URL)))
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def self.extract_rates(doc)
|
19
|
+
rates = { date: Date.parse(doc.css('Cube Cube').first['time']),
|
20
|
+
rates: {} }
|
21
|
+
doc.css('Cube Cube Cube').each do |rate|
|
22
|
+
rates[:rates][rate.xpath('@currency').text.to_sym] =
|
23
|
+
rate.xpath('@rate').text.to_f
|
24
|
+
end
|
25
|
+
rates
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
module Europe
|
6
|
+
module Vat
|
7
|
+
# Rates
|
8
|
+
module Rates
|
9
|
+
RATES_URL = 'http://ec.europa.eu/taxation_customs/tic/' \
|
10
|
+
'public/vatRates/vatratesSearch.html'
|
11
|
+
def self.retrieve
|
12
|
+
resp = fetch_rates
|
13
|
+
return resp if resp == :failed
|
14
|
+
extract_rates(resp)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def self.extract_country_code(data)
|
20
|
+
Europe::Countries.name_to_code[data.css('td').first.text.strip!]
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.extract_rate_number(data)
|
24
|
+
data.css('td')[1].css('div span').text.tr('%', '').to_f
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.extract_rates(resp)
|
28
|
+
rates = {}
|
29
|
+
doc = Nokogiri::XML(resp)
|
30
|
+
doc.css('#national tbody tr')[0..-2].each do |data|
|
31
|
+
key = extract_country_code(data)
|
32
|
+
rates[key] = extract_rate_number(data)
|
33
|
+
end
|
34
|
+
rates
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.generate_url
|
38
|
+
uri = URI.parse(RATES_URL)
|
39
|
+
params = 'listOfTypes=Standard&dateFilter=' +
|
40
|
+
Time.new.strftime('%d/%m/%Y')
|
41
|
+
[*1..Europe::Countries::COUNTRIES.count].each do |index|
|
42
|
+
params += '&listOfMsa=' + (index).to_s
|
43
|
+
end
|
44
|
+
[uri, params]
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.fetch_rates
|
48
|
+
uri, params = generate_url
|
49
|
+
req = Net::HTTP::Post.new(uri.path)
|
50
|
+
req.body = params
|
51
|
+
resp = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
52
|
+
http.request(req)
|
53
|
+
end
|
54
|
+
resp.code.to_i == 200 ? resp.body : :failed
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'europe/vat/rates'
|
2
|
+
require 'savon'
|
3
|
+
|
4
|
+
# Europe Gem
|
5
|
+
module Europe
|
6
|
+
# VAT
|
7
|
+
module Vat
|
8
|
+
WSDL = 'http://ec.europa.eu/taxation_customs/' \
|
9
|
+
'vies/checkVatService.wsdl'
|
10
|
+
NS = 'urn:ec.europa.eu:taxud:vies:services:checkVat:types'
|
11
|
+
def self.validate(country_code, number)
|
12
|
+
response = send_request(country_code, number)
|
13
|
+
return :failed unless response.success?
|
14
|
+
response.body[:check_vat_response].tap { |x| x.delete(:@xmlns) }
|
15
|
+
rescue Savon::SOAPFault => fault
|
16
|
+
return :timeout \
|
17
|
+
if fault.to_hash[:fault][:faultstring] == 'SERVER_BUSY'
|
18
|
+
:fault
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def self.send_request(country_code, number)
|
24
|
+
client = Savon.client(wsdl: WSDL, namespace: NS,
|
25
|
+
open_timeout: 10, read_timeout: 10)
|
26
|
+
|
27
|
+
client.call(:check_vat,
|
28
|
+
message: { countryCode: country_code,
|
29
|
+
vatNumber: number.delete(' ') })
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Europe
|
4
|
+
module Countries
|
5
|
+
# CurrencyTest
|
6
|
+
class CountryTest < Minitest::Test
|
7
|
+
include Benchmark
|
8
|
+
|
9
|
+
def test_country_by_name
|
10
|
+
reversed_hash = Europe::Countries.name_to_code
|
11
|
+
assert_equal reversed_hash['Netherlands'], :NL
|
12
|
+
assert_equal reversed_hash['Ireland'], :IE
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
module Europe
|
6
|
+
module Currency
|
7
|
+
# CurrencyTest
|
8
|
+
class CurrencyTest < Minitest::Test
|
9
|
+
include Benchmark
|
10
|
+
|
11
|
+
def test_currency_retrieval
|
12
|
+
assert_equal Europe::Currency::CURRENCIES[:EUR][:name], 'Euro'
|
13
|
+
assert_equal Europe::Currency::CURRENCIES[:GBP][:symbol], '£'
|
14
|
+
assert_equal Europe::Currency::CURRENCIES[:SEK][:html], 'kr'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Europe
|
4
|
+
module Currency
|
5
|
+
# CurrencyTest
|
6
|
+
class ExchangeRatesTest < Minitest::Test
|
7
|
+
include Benchmark
|
8
|
+
|
9
|
+
def test_retrieval_exchange_rates
|
10
|
+
rates = Europe::Currency::ExchangeRates.retrieve
|
11
|
+
assert_equal rates[:date].to_s,
|
12
|
+
DateTime.now.strftime('%Y-%m-%d')
|
13
|
+
assert rates[:rates].keys.include?(:GBP)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Europe
|
4
|
+
module Vat
|
5
|
+
# CurrencyTest
|
6
|
+
class RatesTest < Minitest::Test
|
7
|
+
include Benchmark
|
8
|
+
|
9
|
+
def test_retrieval_of_vat_rates
|
10
|
+
rates = Europe::Vat::Rates.retrieve
|
11
|
+
assert_equal rates.count, Europe::Countries::COUNTRIES.count
|
12
|
+
assert rates[:NL]
|
13
|
+
assert rates[:DE]
|
14
|
+
assert rates[:ES]
|
15
|
+
assert_nil rates[:GG]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Europe
|
4
|
+
module Vat
|
5
|
+
# CurrencyTest
|
6
|
+
class ValidationTest < Minitest::Test
|
7
|
+
include Benchmark
|
8
|
+
|
9
|
+
def test_validation_of_false_vat_number
|
10
|
+
validate_false_vat = Europe::Vat.validate('NL', '123456789B01')
|
11
|
+
assert_equal false, validate_false_vat[:valid]
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_validation_of_correct_vat_number
|
15
|
+
# PostNL
|
16
|
+
validate_correct_vat = Europe::Vat.validate('NL', '009291477B01')
|
17
|
+
assert validate_correct_vat[:valid]
|
18
|
+
|
19
|
+
# Sky
|
20
|
+
validate_correct_vat = Europe::Vat.validate('GB', '440627467')
|
21
|
+
assert validate_correct_vat[:valid]
|
22
|
+
|
23
|
+
# Volkswagen
|
24
|
+
validate_correct_vat = Europe::Vat.validate('DE', '115235681')
|
25
|
+
assert validate_correct_vat[:valid]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: europe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- VvanGemert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: savon
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.10.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.10.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: awesome_print
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: This gem retrieves data from EU government websites
|
112
|
+
email:
|
113
|
+
- vincent@floorplanner.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".coveralls.yml"
|
119
|
+
- ".gitignore"
|
120
|
+
- ".pryrc"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- europe.gemspec
|
128
|
+
- lib/europe.rb
|
129
|
+
- lib/europe/countries/countries.rb
|
130
|
+
- lib/europe/currency/currency.rb
|
131
|
+
- lib/europe/currency/exchange_rates.rb
|
132
|
+
- lib/europe/vat/rates.rb
|
133
|
+
- lib/europe/vat/vat.rb
|
134
|
+
- lib/europe/version.rb
|
135
|
+
- test/europe/countries/country_test.rb
|
136
|
+
- test/europe/currency/currency_test.rb
|
137
|
+
- test/europe/currency/exchange_rates_test.rb
|
138
|
+
- test/europe/vat/rates_test.rb
|
139
|
+
- test/europe/vat/validation_test.rb
|
140
|
+
- test/test_helper.rb
|
141
|
+
homepage: ''
|
142
|
+
licenses:
|
143
|
+
- MIT
|
144
|
+
metadata: {}
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
requirements: []
|
160
|
+
rubyforge_project:
|
161
|
+
rubygems_version: 2.4.8
|
162
|
+
signing_key:
|
163
|
+
specification_version: 4
|
164
|
+
summary: Europe is a helper gem for retrieving \ EU government data
|
165
|
+
test_files:
|
166
|
+
- test/europe/countries/country_test.rb
|
167
|
+
- test/europe/currency/currency_test.rb
|
168
|
+
- test/europe/currency/exchange_rates_test.rb
|
169
|
+
- test/europe/vat/rates_test.rb
|
170
|
+
- test/europe/vat/validation_test.rb
|
171
|
+
- test/test_helper.rb
|