europe 0.0.18 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +2 -6
- data/.rubocop.yml +1 -1
- data/.travis.yml +1 -0
- data/CHANGELOG.md +6 -0
- data/lib/europe/vat/rates.rb +16 -3
- data/lib/europe/vat/vat.rb +7 -7
- data/lib/europe/version.rb +1 -1
- data/test/europe/vat/rates_test.rb +3 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55a8a248cfae6ade9980da4ea2e6b47938c5aa75c8936c8f010e35a50b6f2b86
|
4
|
+
data.tar.gz: 23920666bd00770ab722cfb8d6edc5e17b416f9d6d81c8ecb1ebfc9112d65338
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd703d1d1d8e534dc8ad46bb1051aa2cfe871e807215c0a417286bac7d23814bf7aba5d0f8f4bdb49fb88f1ed49992f5b6e24a30416c0f769f06d051970b9c78
|
7
|
+
data.tar.gz: ce9d7fd212fb5905a71598ab7545eb3ad80823a095e97af46101426c214ec592e3d4eacaf429bfaa21a7f2417072a5154c2e97a2b024f642d4fe9a346322f967
|
data/.github/workflows/ruby.yml
CHANGED
@@ -20,13 +20,9 @@ jobs:
|
|
20
20
|
|
21
21
|
steps:
|
22
22
|
- uses: actions/checkout@v2
|
23
|
-
-
|
24
|
-
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
25
|
-
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
26
|
-
# uses: ruby/setup-ruby@v1
|
27
|
-
uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
|
23
|
+
- uses: ruby/setup-ruby@v1
|
28
24
|
with:
|
29
|
-
ruby-version:
|
25
|
+
ruby-version: 3.1.1
|
30
26
|
- name: Install dependencies
|
31
27
|
run: bundle install
|
32
28
|
- name: Run tests
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# Change Log
|
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
|
+
## 0.0.20
|
5
|
+
- Added fallback VAT rates in case the EU website is down or unresponsive
|
6
|
+
- [Full Changelog](https://github.com/gem-shards/europe.rb/compare/v0.0.19...v0.0.20)
|
7
|
+
## 0.0.19
|
8
|
+
- Fixed VAT validation call because XML response was updated
|
9
|
+
- [Full Changelog](https://github.com/gem-shards/europe.rb/compare/v0.0.18...v0.0.19)
|
4
10
|
## 0.0.18
|
5
11
|
- Added Estonia and Lithuania to eurozone
|
6
12
|
- [Full Changelog](https://github.com/gem-shards/europe.rb/compare/v0.0.17...v0.0.18)
|
data/lib/europe/vat/rates.rb
CHANGED
@@ -6,21 +6,33 @@ module Europe
|
|
6
6
|
module Vat
|
7
7
|
# Rates
|
8
8
|
module Rates
|
9
|
+
FALLBACK_RATES = {
|
10
|
+
AT: 20.0, BE: 21.0, BG: 20.0, CY: 19.0, CZ: 21.0, DE: 19.0, DK: 25.0, EE: 20.0,
|
11
|
+
EL: 24.0, ES: 21.0, FI: 24.0, FR: 20.0, UK: 20.0, HR: 25.0, HU: 27.0, IE: 23.0,
|
12
|
+
IT: 22.0, LT: 21.0, LU: 17.0, LV: 21.0, MT: 18.0, NL: 21.0, PL: 23.0, PT: 23.0,
|
13
|
+
RO: 19.0, SE: 25.0, SI: 22.0, SK: 20.0
|
14
|
+
}.freeze
|
9
15
|
RATES_URL = 'https://ec.europa.eu/taxation_customs/' \
|
10
16
|
'business/vat/telecommunications-broadcasting' \
|
11
17
|
'-electronic-services/vat-rates_en'
|
12
18
|
|
13
19
|
def self.retrieve
|
14
20
|
resp = fetch_rates
|
15
|
-
return
|
21
|
+
return FALLBACK_RATES if resp.nil?
|
16
22
|
|
17
23
|
extract_rates(resp)
|
18
24
|
end
|
19
25
|
|
26
|
+
# rubocop:disable Metrics/MethodLength
|
20
27
|
def self.extract_rates(resp)
|
21
28
|
rates = {}
|
22
29
|
|
23
|
-
|
30
|
+
begin
|
31
|
+
data = resp.scan(%r{\<tbody\>(.*)\<\/tbody\>}m).first.first.strip
|
32
|
+
rescue NoMethodError
|
33
|
+
return FALLBACK_RATES
|
34
|
+
end
|
35
|
+
|
24
36
|
xml = REXML::Document.new("<root>#{data}</root>")
|
25
37
|
xml.first.elements.each('tr') do |result|
|
26
38
|
next if result[3].nil?
|
@@ -29,6 +41,7 @@ module Europe
|
|
29
41
|
end
|
30
42
|
rates
|
31
43
|
end
|
44
|
+
# rubocop:enable Metrics/MethodLength
|
32
45
|
|
33
46
|
def self.filter_rate(result, rates)
|
34
47
|
country = result[0].text
|
@@ -40,7 +53,7 @@ module Europe
|
|
40
53
|
|
41
54
|
def self.fetch_rates
|
42
55
|
resp = Net::HTTP.get_response(URI.parse(RATES_URL))
|
43
|
-
resp.code.to_i == 200 ? resp.body :
|
56
|
+
resp.code.to_i == 200 ? resp.body : nil
|
44
57
|
end
|
45
58
|
end
|
46
59
|
end
|
data/lib/europe/vat/vat.rb
CHANGED
@@ -47,18 +47,18 @@ module Europe
|
|
47
47
|
def self.setup_response(response)
|
48
48
|
body = response_xml(response)
|
49
49
|
{
|
50
|
-
valid: extract_data(body,
|
51
|
-
country_code: extract_data(body,
|
52
|
-
vat_number: extract_data(body,
|
53
|
-
request_date: convert_date(extract_data(body,
|
54
|
-
name: extract_data(body,
|
55
|
-
address: extract_data(body,
|
50
|
+
valid: extract_data(body, 3) == 'true',
|
51
|
+
country_code: extract_data(body, 0),
|
52
|
+
vat_number: extract_data(body, 1),
|
53
|
+
request_date: convert_date(extract_data(body, 2)),
|
54
|
+
name: extract_data(body, 4),
|
55
|
+
address: extract_data(body, 5)
|
56
56
|
}
|
57
57
|
end
|
58
58
|
|
59
59
|
def self.response_xml(response)
|
60
60
|
xml = REXML::Document.new(response.body)
|
61
|
-
xml.
|
61
|
+
xml.elements.first.elements[2].elements[1]
|
62
62
|
end
|
63
63
|
|
64
64
|
def self.convert_date(date)
|
data/lib/europe/version.rb
CHANGED
@@ -14,11 +14,9 @@ module Europe
|
|
14
14
|
|
15
15
|
def test_retrieval_of_vat_rates
|
16
16
|
rates = Europe::Vat::Rates.retrieve
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
assert_equal rates.count, Europe::Countries::COUNTRIES.count
|
21
|
-
end
|
17
|
+
|
18
|
+
assert_equal rates.count, Europe::Countries::COUNTRIES.count
|
19
|
+
|
22
20
|
assert rates[:NL]
|
23
21
|
assert rates[:DE]
|
24
22
|
assert rates[:ES]
|
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.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gem shards
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -199,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
199
|
- !ruby/object:Gem::Version
|
200
200
|
version: '0'
|
201
201
|
requirements: []
|
202
|
-
rubygems_version: 3.
|
202
|
+
rubygems_version: 3.3.7
|
203
203
|
signing_key:
|
204
204
|
specification_version: 4
|
205
205
|
summary: Europe is a gem for retrieving and validating EU government data.
|