europe 0.0.11 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.pryrc +2 -0
- data/.rubocop.yml +15 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile +2 -0
- data/README.md +2 -2
- data/Rakefile +2 -0
- data/europe.gemspec +3 -3
- data/lib/europe.rb +2 -0
- data/lib/europe/countries/countries.rb +3 -1
- data/lib/europe/countries/reversed.rb +2 -0
- data/lib/europe/currency/currency.rb +2 -0
- data/lib/europe/currency/exchange_rates.rb +11 -8
- data/lib/europe/eurostat/eurostat.rb +3 -1
- data/lib/europe/postal/postal.rb +6 -3
- data/lib/europe/rake_task.rb +2 -0
- data/lib/europe/tasks/eurostat.rake +10 -5
- data/lib/europe/vat/format.rb +4 -1
- data/lib/europe/vat/rates.rb +12 -5
- data/lib/europe/vat/vat.rb +18 -7
- data/lib/europe/version.rb +3 -1
- data/test/europe/countries/country_test.rb +2 -0
- data/test/europe/currency/currency_test.rb +2 -0
- data/test/europe/currency/exchange_rates_test.rb +3 -1
- data/test/europe/eurostat/eurostat_test.rb +2 -0
- data/test/europe/postal/format_test.rb +2 -0
- data/test/europe/vat/format_test.rb +2 -0
- data/test/europe/vat/rates_test.rb +2 -0
- data/test/europe/vat/validation_test.rb +2 -0
- data/test/test_helper.rb +3 -1
- metadata +9 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8dfe84a1c050d715865f2f5878458f4f9708437770e629ee64564d59ff622d4
|
4
|
+
data.tar.gz: d59e3b667b741269bfb5db4dafeb6cc531a052fd79ccfcbe354e941c5976cb13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5da3ca3fc8579d8b55043b6f9af8da9ac1f69aa46ec9e4c9858a2318cae1222724679553ec45f61308928f65595bbd71682279aa219e46e698811eb3a27217a2
|
7
|
+
data.tar.gz: 3c5f1f99dab00df6e1e66acf202c4a12cf339fb0207566b5ef613d93c8ac262e61b243a05045e30c82dbc3b36667f89bc99345bb4b42456420951a5d7b889420
|
data/.pryrc
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,3 +1,18 @@
|
|
1
1
|
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
TargetRubyVersion: 2.7
|
4
|
+
SuggestExtensions: false
|
2
5
|
Exclude:
|
3
6
|
- 'europe.gemspec'
|
7
|
+
|
8
|
+
Style/SlicingWithRange:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Style/RedundantRegexpEscape:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Style/RedundantRegexpCharacterClass:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Style/CaseLikeIf:
|
18
|
+
Enabled: false
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,21 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
+
## 0.0.14
|
6
|
+
- Fixed rubocop syntax issues
|
7
|
+
- Fixed issue with retrieving exchange rates when no valid JSON is returned
|
8
|
+
- [Full Changelog](https://github.com/VvanGemert/europe/compare/v0.0.13...v0.0.14)
|
9
|
+
|
10
|
+
## 0.0.13
|
11
|
+
- Fixed rubocop syntax issues
|
12
|
+
- Changed ExchangeRate source from XML to JSON
|
13
|
+
- Fixed date parsing and soap:fault handling in VAT validation
|
14
|
+
- [Full Changelog](https://github.com/VvanGemert/europe/compare/v0.0.12...v0.0.13)
|
15
|
+
|
16
|
+
## 0.0.12
|
17
|
+
- Fixed extracting vat validation data when it didn't exists
|
18
|
+
- [Full Changelog](https://github.com/VvanGemert/europe/compare/v0.0.11...v0.0.12)
|
19
|
+
|
5
20
|
## 0.0.11
|
6
21
|
- Removed print outout when fetching VAT rates
|
7
22
|
- [Full Changelog](https://github.com/VvanGemert/europe/compare/v0.0.10...v0.0.11)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
![Europe gem logo](https://s3-eu-west-1.amazonaws.com/valorsis.s3-website-eu-west-1.amazonaws.com/static/logo256.png)
|
2
|
-
# Europe
|
2
|
+
# Europe :eu:
|
3
3
|
|
4
4
|
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.
|
5
5
|
|
@@ -179,7 +179,7 @@ This gem is tested with the following Ruby versions on Linux and Mac OS X:
|
|
179
179
|
|
180
180
|
## Contributing
|
181
181
|
|
182
|
-
1. Fork it ( https://github.com/
|
182
|
+
1. Fork it ( https://github.com/gem-shards/europe.rb/fork )
|
183
183
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
184
184
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
185
185
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
data/europe.gemspec
CHANGED
@@ -6,15 +6,15 @@ require 'europe/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'europe'
|
8
8
|
spec.version = Europe::VERSION
|
9
|
-
spec.authors = ['
|
10
|
-
spec.email = ['vincent@
|
9
|
+
spec.authors = ['Gem shards']
|
10
|
+
spec.email = ['vincent@gemshards.com']
|
11
11
|
spec.summary = 'Europe is a gem for retrieving and validating ' \
|
12
12
|
'EU government data.'
|
13
13
|
spec.description = 'Europe is a simple library for retrieving ' \
|
14
14
|
'EU government data such as VAT information, ' \
|
15
15
|
'VAT validation, currency exchange rates and ' \
|
16
16
|
'country information.'
|
17
|
-
spec.homepage = 'https://github.com/
|
17
|
+
spec.homepage = 'https://github.com/gem-shards/europe.rb'
|
18
18
|
spec.license = 'MIT'
|
19
19
|
|
20
20
|
spec.files = `git ls-files -z`.split("\x0")
|
data/lib/europe.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Source: http://publications.europa.eu/code/pdf/370000en.htm
|
2
4
|
|
3
5
|
require 'europe/countries/reversed'
|
@@ -79,7 +81,7 @@ module Europe
|
|
79
81
|
SI: { name: 'Slovenia', source_name: 'Slovenija',
|
80
82
|
official_name: 'Republic of Slovenia',
|
81
83
|
tld: '.si', currency: :EUR, capital: 'Ljubljana' },
|
82
|
-
SK: { name: '
|
84
|
+
SK: { name: 'Slovakia', source_name: 'Slovensko',
|
83
85
|
official_name: 'Slovak Republic',
|
84
86
|
tld: '.sk', currency: :EUR, capital: 'Bratislava' },
|
85
87
|
FI: { name: 'Finland', source_name: 'Suomi',
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'net/http'
|
3
4
|
require 'date'
|
4
5
|
|
@@ -8,7 +9,7 @@ module Europe
|
|
8
9
|
module Currency
|
9
10
|
# exchange rates
|
10
11
|
module ExchangeRates
|
11
|
-
EXCHANGE_URL = 'https://www.floatrates.com/daily/eur.
|
12
|
+
EXCHANGE_URL = 'https://www.floatrates.com/daily/eur.json'
|
12
13
|
|
13
14
|
def self.retrieve
|
14
15
|
resp = Net::HTTP.get_response(URI.parse(EXCHANGE_URL))
|
@@ -16,17 +17,19 @@ module Europe
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def self.extract_rates(doc)
|
19
|
-
|
20
|
+
data = JSON.parse(doc)
|
20
21
|
|
21
|
-
rates = { date: Date.parse(
|
22
|
+
rates = { date: Date.parse(data['usd']['date']),
|
22
23
|
rates: {} }
|
23
24
|
|
24
|
-
filter_rates(
|
25
|
+
filter_rates(data, rates)
|
26
|
+
rescue JSON::ParserError
|
27
|
+
:failed
|
25
28
|
end
|
26
29
|
|
27
|
-
def self.filter_rates(
|
28
|
-
|
29
|
-
rates[:rates][
|
30
|
+
def self.filter_rates(data, rates)
|
31
|
+
data.each do |currency, object|
|
32
|
+
rates[:rates][currency.upcase.to_sym] = object['rate'].to_f
|
30
33
|
end
|
31
34
|
rates
|
32
35
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'net/http'
|
2
4
|
require 'uri'
|
3
5
|
require 'json'
|
@@ -8,7 +10,7 @@ module Europe
|
|
8
10
|
module Eurostat
|
9
11
|
# http://ec.europa.eu/eurostat/data/database
|
10
12
|
STAT_URL = 'http://ec.europa.eu/eurostat/wdds' \
|
11
|
-
'/rest/data/v2.1/json/en/'
|
13
|
+
'/rest/data/v2.1/json/en/'
|
12
14
|
|
13
15
|
def self.retrieve(dataset, filters)
|
14
16
|
fetch_stats(dataset, filters)
|
data/lib/europe/postal/postal.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Europe Gem
|
2
4
|
module Europe
|
3
5
|
# VAT
|
4
6
|
module Postal
|
5
|
-
# rubocop:disable LineLength
|
7
|
+
# rubocop:disable Layout/LineLength
|
6
8
|
POSTAL_REGEX = {
|
7
9
|
AT: /^\d{4}$/,
|
8
10
|
BE: /^\d{4}$/,
|
@@ -33,10 +35,11 @@ module Europe
|
|
33
35
|
SI: /^\d{4}$/,
|
34
36
|
SK: /^\d{3}[ ]?\d{2}$/
|
35
37
|
}.freeze
|
36
|
-
# rubocop:enable LineLength
|
38
|
+
# rubocop:enable Layout/LineLength
|
37
39
|
|
38
40
|
def self.validate(country_code, postal_code)
|
39
|
-
return false unless POSTAL_REGEX.
|
41
|
+
return false unless POSTAL_REGEX.key?(country_code.to_sym)
|
42
|
+
|
40
43
|
match_postal_code(postal_code, country_code)
|
41
44
|
end
|
42
45
|
|
data/lib/europe/rake_task.rb
CHANGED
@@ -1,14 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'open-uri'
|
2
4
|
|
3
5
|
namespace :eurostat do
|
4
|
-
EUROSTAT_BULK_URL = 'http://ec.europa.eu/eurostat/' \
|
5
|
-
'estat-navtree-portlet-prod/BulkDownloadListing' \
|
6
|
-
'?sort=1&file='.freeze
|
7
|
-
|
8
6
|
desc 'Download categories from Eurostat Bulk Facility'
|
9
7
|
task :download_categories do
|
8
|
+
eurostat_bulk_url = 'http://ec.europa.eu/eurostat/' \
|
9
|
+
'estat-navtree-portlet-prod/BulkDownloadListing' \
|
10
|
+
'?sort=1&file='
|
11
|
+
|
12
|
+
data = Net::HTTP.get_response(
|
13
|
+
URI.parse("#{eurostat_bulk_url}table_of_contents_en.txt")
|
14
|
+
).body
|
10
15
|
File.open('cat.txt', 'w') do |f|
|
11
|
-
IO.copy_stream(
|
16
|
+
IO.copy_stream(data, f)
|
12
17
|
end
|
13
18
|
end
|
14
19
|
end
|
data/lib/europe/vat/format.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Europe Gem
|
2
4
|
module Europe
|
3
5
|
# VAT
|
@@ -38,7 +40,8 @@ module Europe
|
|
38
40
|
def self.validate(number)
|
39
41
|
country_code = number[0..1].to_sym
|
40
42
|
number = sanitize_number(number, country_code)
|
41
|
-
return false unless VAT_REGEX.
|
43
|
+
return false unless VAT_REGEX.key?(country_code)
|
44
|
+
|
42
45
|
match_vat_number(number, country_code)
|
43
46
|
end
|
44
47
|
|
data/lib/europe/vat/rates.rb
CHANGED
@@ -1,14 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rexml/document'
|
2
4
|
|
3
5
|
module Europe
|
4
6
|
module Vat
|
5
7
|
# Rates
|
6
8
|
module Rates
|
7
|
-
RATES_URL = 'https://europa.eu/
|
8
|
-
'vat/
|
9
|
+
RATES_URL = 'https://ec.europa.eu/taxation_customs/' \
|
10
|
+
'business/vat/telecommunications-broadcasting' \
|
11
|
+
'-electronic-services/vat-rates_en'
|
12
|
+
|
9
13
|
def self.retrieve
|
10
14
|
resp = fetch_rates
|
11
15
|
return resp if resp == :failed
|
16
|
+
|
12
17
|
extract_rates(resp)
|
13
18
|
end
|
14
19
|
|
@@ -19,15 +24,17 @@ module Europe
|
|
19
24
|
xml = REXML::Document.new("<root>#{data}</root>")
|
20
25
|
xml.first.elements.each('tr') do |result|
|
21
26
|
next if result[3].nil?
|
27
|
+
|
22
28
|
rates = filter_rate(result, rates)
|
23
29
|
end
|
24
30
|
rates
|
25
31
|
end
|
26
32
|
|
27
33
|
def self.filter_rate(result, rates)
|
28
|
-
country = result[
|
29
|
-
rate = result[
|
30
|
-
|
34
|
+
country = result[0].text
|
35
|
+
rate = result[3].text
|
36
|
+
country_code = Europe::Countries::Reversed.generate(:name)[country]
|
37
|
+
rates[country_code] = rate.to_f if country_code
|
31
38
|
rates
|
32
39
|
end
|
33
40
|
|
data/lib/europe/vat/vat.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'europe/vat/rates'
|
2
4
|
require 'europe/vat/format'
|
3
5
|
require 'uri'
|
@@ -10,13 +12,13 @@ module Europe
|
|
10
12
|
# VAT
|
11
13
|
module Vat
|
12
14
|
WSDL = 'http://ec.europa.eu/taxation_customs/vies/' \
|
13
|
-
'services/checkVatService'
|
15
|
+
'services/checkVatService'
|
14
16
|
HEADERS = {
|
15
17
|
'Content-Type' => 'text/xml;charset=UTF-8',
|
16
18
|
'SOAPAction' => ''
|
17
19
|
}.freeze
|
18
20
|
|
19
|
-
BODY = <<-XML
|
21
|
+
BODY = <<-XML
|
20
22
|
<soapenv:Envelope
|
21
23
|
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
|
22
24
|
xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
|
@@ -33,11 +35,13 @@ module Europe
|
|
33
35
|
def self.validate(number)
|
34
36
|
response = send_request(number[0..1], number[2..-1])
|
35
37
|
return :failed unless response.is_a? Net::HTTPSuccess
|
38
|
+
return :failed if response.body.include?('soap:Fault')
|
39
|
+
|
36
40
|
setup_response(response)
|
37
41
|
rescue Net::OpenTimeout
|
38
|
-
|
42
|
+
:timeout
|
39
43
|
rescue Net::HTTPServerError
|
40
|
-
|
44
|
+
:server_error
|
41
45
|
end
|
42
46
|
|
43
47
|
def self.setup_response(response)
|
@@ -46,7 +50,7 @@ module Europe
|
|
46
50
|
valid: extract_data(body, 4) == 'true',
|
47
51
|
country_code: extract_data(body, 1),
|
48
52
|
vat_number: extract_data(body, 2),
|
49
|
-
request_date:
|
53
|
+
request_date: convert_date(extract_data(body, 3)),
|
50
54
|
name: extract_data(body, 5),
|
51
55
|
address: extract_data(body, 6)
|
52
56
|
}
|
@@ -57,17 +61,24 @@ module Europe
|
|
57
61
|
xml.first.elements.first.elements.first.elements
|
58
62
|
end
|
59
63
|
|
64
|
+
def self.convert_date(date)
|
65
|
+
return unless date
|
66
|
+
|
67
|
+
Date.parse(date)
|
68
|
+
end
|
69
|
+
|
60
70
|
def self.extract_data(body, position)
|
61
|
-
body[position]
|
71
|
+
body[position]&.text
|
62
72
|
end
|
63
73
|
|
64
74
|
def self.charge_vat?(origin_country, number)
|
65
75
|
return false if number.nil? || number.empty?
|
76
|
+
|
66
77
|
if origin_country.to_sym == number[0..1].to_sym
|
67
78
|
true
|
68
79
|
else
|
69
80
|
Europe::Countries::COUNTRIES
|
70
|
-
.
|
81
|
+
.key?(number[0..1].to_sym)
|
71
82
|
end
|
72
83
|
end
|
73
84
|
|
data/lib/europe/version.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
module Europe
|
@@ -12,7 +14,7 @@ module Europe
|
|
12
14
|
|
13
15
|
def test_retrieval_exchange_rates
|
14
16
|
rates = Europe::Currency::ExchangeRates.retrieve
|
15
|
-
assert rates[:rates].
|
17
|
+
assert rates[:rates].key?(:GBP)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: europe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- Gem shards
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -139,7 +139,7 @@ dependencies:
|
|
139
139
|
description: Europe is a simple library for retrieving EU government data such as
|
140
140
|
VAT information, VAT validation, currency exchange rates and country information.
|
141
141
|
email:
|
142
|
-
- vincent@
|
142
|
+
- vincent@gemshards.com
|
143
143
|
executables: []
|
144
144
|
extensions: []
|
145
145
|
extra_rdoc_files: []
|
@@ -177,11 +177,11 @@ files:
|
|
177
177
|
- test/europe/vat/rates_test.rb
|
178
178
|
- test/europe/vat/validation_test.rb
|
179
179
|
- test/test_helper.rb
|
180
|
-
homepage: https://github.com/
|
180
|
+
homepage: https://github.com/gem-shards/europe.rb
|
181
181
|
licenses:
|
182
182
|
- MIT
|
183
183
|
metadata: {}
|
184
|
-
post_install_message:
|
184
|
+
post_install_message:
|
185
185
|
rdoc_options: []
|
186
186
|
require_paths:
|
187
187
|
- lib
|
@@ -196,9 +196,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
196
|
- !ruby/object:Gem::Version
|
197
197
|
version: '0'
|
198
198
|
requirements: []
|
199
|
-
|
200
|
-
|
201
|
-
signing_key:
|
199
|
+
rubygems_version: 3.1.4
|
200
|
+
signing_key:
|
202
201
|
specification_version: 4
|
203
202
|
summary: Europe is a gem for retrieving and validating EU government data.
|
204
203
|
test_files:
|