europe 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/europe/currency/exchange_rates.rb +7 -8
- data/lib/europe/postal/postal.rb +2 -1
- data/lib/europe/tasks/eurostat.rake +4 -1
- data/lib/europe/vat/format.rb +2 -1
- data/lib/europe/vat/rates.rb +2 -0
- data/lib/europe/vat/vat.rb +13 -4
- data/lib/europe/version.rb +1 -1
- data/test/europe/currency/exchange_rates_test.rb +1 -1
- data/test/test_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 485843e469d396d96b1f4691904ed6d2e21139a31eea5840e6369dd10f2cfaec
|
4
|
+
data.tar.gz: 596c49fcafcb9d05964c697f500e475adb2cf510baad1dd0f65df5e7fb1790bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 239e7f92f39acc3f49f345a49eb1e3140866b0eab2f471d4619010e4c09adefe05fe62267a20ac4a993d91f4054b46fc6f131a60949846bdadf56151b4a520fc
|
7
|
+
data.tar.gz: 717c7a926fd9302c277d2d5d675eccc04b468bef6a12dd01148dab1270c491dd6091dd4ac1e746c4c09ae430a823ad3c6a828176f79e4d358d3e9783fbb245df
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
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.13
|
6
|
+
- Fixed rubocop syntax issues
|
7
|
+
- Changed ExchangeRate source from XML to JSON
|
8
|
+
- Fixed date parsing and soap:fault handling in VAT validation
|
9
|
+
- [Full Changelog](https://github.com/VvanGemert/europe/compare/v0.0.12...v0.0.13)
|
10
|
+
|
5
11
|
## 0.0.12
|
6
12
|
- Fixed extracting vat validation data when it didn't exists
|
7
13
|
- [Full Changelog](https://github.com/VvanGemert/europe/compare/v0.0.11...v0.0.12)
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'rexml/document'
|
2
1
|
require 'net/http'
|
3
2
|
require 'date'
|
4
3
|
|
@@ -8,7 +7,7 @@ module Europe
|
|
8
7
|
module Currency
|
9
8
|
# exchange rates
|
10
9
|
module ExchangeRates
|
11
|
-
EXCHANGE_URL = 'https://www.floatrates.com/daily/eur.
|
10
|
+
EXCHANGE_URL = 'https://www.floatrates.com/daily/eur.json'.freeze
|
12
11
|
|
13
12
|
def self.retrieve
|
14
13
|
resp = Net::HTTP.get_response(URI.parse(EXCHANGE_URL))
|
@@ -16,17 +15,17 @@ module Europe
|
|
16
15
|
end
|
17
16
|
|
18
17
|
def self.extract_rates(doc)
|
19
|
-
|
18
|
+
data = JSON.parse(doc)
|
20
19
|
|
21
|
-
rates = { date: Date.parse(
|
20
|
+
rates = { date: Date.parse(data['usd']['date']),
|
22
21
|
rates: {} }
|
23
22
|
|
24
|
-
filter_rates(
|
23
|
+
filter_rates(data, rates)
|
25
24
|
end
|
26
25
|
|
27
|
-
def self.filter_rates(
|
28
|
-
|
29
|
-
rates[:rates][
|
26
|
+
def self.filter_rates(data, rates)
|
27
|
+
data.each do |currency, object|
|
28
|
+
rates[:rates][currency.upcase.to_sym] = object['rate'].to_f
|
30
29
|
end
|
31
30
|
rates
|
32
31
|
end
|
data/lib/europe/postal/postal.rb
CHANGED
@@ -36,7 +36,8 @@ module Europe
|
|
36
36
|
# rubocop:enable LineLength
|
37
37
|
|
38
38
|
def self.validate(country_code, postal_code)
|
39
|
-
return false unless POSTAL_REGEX.
|
39
|
+
return false unless POSTAL_REGEX.key?(country_code.to_sym)
|
40
|
+
|
40
41
|
match_postal_code(postal_code, country_code)
|
41
42
|
end
|
42
43
|
|
@@ -7,8 +7,11 @@ namespace :eurostat do
|
|
7
7
|
|
8
8
|
desc 'Download categories from Eurostat Bulk Facility'
|
9
9
|
task :download_categories do
|
10
|
+
data = Net::HTTP.get_response(
|
11
|
+
URI.parse(EUROSTAT_BULK_URL + 'table_of_contents_en.txt')
|
12
|
+
).body
|
10
13
|
File.open('cat.txt', 'w') do |f|
|
11
|
-
IO.copy_stream(
|
14
|
+
IO.copy_stream(data, f)
|
12
15
|
end
|
13
16
|
end
|
14
17
|
end
|
data/lib/europe/vat/format.rb
CHANGED
@@ -38,7 +38,8 @@ module Europe
|
|
38
38
|
def self.validate(number)
|
39
39
|
country_code = number[0..1].to_sym
|
40
40
|
number = sanitize_number(number, country_code)
|
41
|
-
return false unless VAT_REGEX.
|
41
|
+
return false unless VAT_REGEX.key?(country_code)
|
42
|
+
|
42
43
|
match_vat_number(number, country_code)
|
43
44
|
end
|
44
45
|
|
data/lib/europe/vat/rates.rb
CHANGED
@@ -9,6 +9,7 @@ module Europe
|
|
9
9
|
def self.retrieve
|
10
10
|
resp = fetch_rates
|
11
11
|
return resp if resp == :failed
|
12
|
+
|
12
13
|
extract_rates(resp)
|
13
14
|
end
|
14
15
|
|
@@ -19,6 +20,7 @@ module Europe
|
|
19
20
|
xml = REXML::Document.new("<root>#{data}</root>")
|
20
21
|
xml.first.elements.each('tr') do |result|
|
21
22
|
next if result[3].nil?
|
23
|
+
|
22
24
|
rates = filter_rate(result, rates)
|
23
25
|
end
|
24
26
|
rates
|
data/lib/europe/vat/vat.rb
CHANGED
@@ -33,11 +33,13 @@ module Europe
|
|
33
33
|
def self.validate(number)
|
34
34
|
response = send_request(number[0..1], number[2..-1])
|
35
35
|
return :failed unless response.is_a? Net::HTTPSuccess
|
36
|
+
return :failed if response.body.include?('soap:Fault')
|
37
|
+
|
36
38
|
setup_response(response)
|
37
39
|
rescue Net::OpenTimeout
|
38
|
-
|
40
|
+
:timeout
|
39
41
|
rescue Net::HTTPServerError
|
40
|
-
|
42
|
+
:server_error
|
41
43
|
end
|
42
44
|
|
43
45
|
def self.setup_response(response)
|
@@ -46,7 +48,7 @@ module Europe
|
|
46
48
|
valid: extract_data(body, 4) == 'true',
|
47
49
|
country_code: extract_data(body, 1),
|
48
50
|
vat_number: extract_data(body, 2),
|
49
|
-
request_date:
|
51
|
+
request_date: convert_date(extract_data(body, 3)),
|
50
52
|
name: extract_data(body, 5),
|
51
53
|
address: extract_data(body, 6)
|
52
54
|
}
|
@@ -57,17 +59,24 @@ module Europe
|
|
57
59
|
xml.first.elements.first.elements.first.elements
|
58
60
|
end
|
59
61
|
|
62
|
+
def self.convert_date(date)
|
63
|
+
return unless date
|
64
|
+
|
65
|
+
Date.parse(date)
|
66
|
+
end
|
67
|
+
|
60
68
|
def self.extract_data(body, position)
|
61
69
|
body[position].text if body[position]
|
62
70
|
end
|
63
71
|
|
64
72
|
def self.charge_vat?(origin_country, number)
|
65
73
|
return false if number.nil? || number.empty?
|
74
|
+
|
66
75
|
if origin_country.to_sym == number[0..1].to_sym
|
67
76
|
true
|
68
77
|
else
|
69
78
|
Europe::Countries::COUNTRIES
|
70
|
-
.
|
79
|
+
.key?(number[0..1].to_sym)
|
71
80
|
end
|
72
81
|
end
|
73
82
|
|
data/lib/europe/version.rb
CHANGED
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.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- VvanGemert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|