europe 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa46dc40ecd90942490472823d2557a6cffaed5467a8147a589323a3cfe81bc4
4
- data.tar.gz: 150097042834342df620e01663afad133e10ee7263a6740356ec108a7ff10e9e
3
+ metadata.gz: 485843e469d396d96b1f4691904ed6d2e21139a31eea5840e6369dd10f2cfaec
4
+ data.tar.gz: 596c49fcafcb9d05964c697f500e475adb2cf510baad1dd0f65df5e7fb1790bf
5
5
  SHA512:
6
- metadata.gz: cf1c063eaa959b37e9202a0b962335c4479eab908210e4d5562c0ea7b667be366a20018f0334128a55ed51f2f31e9f6c3f13e108a62155d5d9f9ed3195d62d0a
7
- data.tar.gz: 8fd71a389816b6a02178419b975e00a9017e6c713be070ad365fe067e269dfcb18c4c2e881903b2b0111f2f0f89f3a6a57485d8ce3ed2a71321dfc25d75df69b
6
+ metadata.gz: 239e7f92f39acc3f49f345a49eb1e3140866b0eab2f471d4619010e4c09adefe05fe62267a20ac4a993d91f4054b46fc6f131a60949846bdadf56151b4a520fc
7
+ data.tar.gz: 717c7a926fd9302c277d2d5d675eccc04b468bef6a12dd01148dab1270c491dd6091dd4ac1e746c4c09ae430a823ad3c6a828176f79e4d358d3e9783fbb245df
@@ -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.xml'.freeze
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
- xml = REXML::Document.new(doc)
18
+ data = JSON.parse(doc)
20
19
 
21
- rates = { date: Date.parse(xml.elements.first.elements[7].text),
20
+ rates = { date: Date.parse(data['usd']['date']),
22
21
  rates: {} }
23
22
 
24
- filter_rates(xml, rates)
23
+ filter_rates(data, rates)
25
24
  end
26
25
 
27
- def self.filter_rates(xml, rates)
28
- xml.elements.each('channel/item') do |item|
29
- rates[:rates][item[13].text.to_sym] = item[17].text.delete(',').to_f
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
@@ -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.keys.include?(country_code.to_sym)
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(open(EUROSTAT_BULK_URL + 'table_of_contents_en.txt'), f)
14
+ IO.copy_stream(data, f)
12
15
  end
13
16
  end
14
17
  end
@@ -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.keys.include?(country_code)
41
+ return false unless VAT_REGEX.key?(country_code)
42
+
42
43
  match_vat_number(number, country_code)
43
44
  end
44
45
 
@@ -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
@@ -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
- return :timeout
40
+ :timeout
39
41
  rescue Net::HTTPServerError
40
- return :server_error
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: Date.parse(extract_data(body, 3)),
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
- .keys.include?(number[0..1].to_sym)
79
+ .key?(number[0..1].to_sym)
71
80
  end
72
81
  end
73
82
 
@@ -1,4 +1,4 @@
1
1
  # Europe version
2
2
  module Europe
3
- VERSION = '0.0.12'.freeze
3
+ VERSION = '0.0.13'.freeze
4
4
  end
@@ -12,7 +12,7 @@ module Europe
12
12
 
13
13
  def test_retrieval_exchange_rates
14
14
  rates = Europe::Currency::ExchangeRates.retrieve
15
- assert rates[:rates].keys.include?(:GBP)
15
+ assert rates[:rates].key?(:GBP)
16
16
  end
17
17
  end
18
18
  end
@@ -1,4 +1,4 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
2
2
  require 'europe'
3
3
  require 'minitest/autorun'
4
4
  require 'webmock/minitest'
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.12
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-14 00:00:00.000000000 Z
11
+ date: 2018-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug