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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0a55ae95d39dcab68a14a4de1d298819078e8298e9c9af5c39959c9a7b23ac0
4
- data.tar.gz: 6f94ef270dba36c732cb01f3c59585207c7a1af85e2fd36943bdb8ae539a9a5d
3
+ metadata.gz: b8dfe84a1c050d715865f2f5878458f4f9708437770e629ee64564d59ff622d4
4
+ data.tar.gz: d59e3b667b741269bfb5db4dafeb6cc531a052fd79ccfcbe354e941c5976cb13
5
5
  SHA512:
6
- metadata.gz: f9f0684d1dad36ef0dc571eb57e16fd5ca1906f6590a5e41b86524f6ed6b028dd2c7164225b667562e95415d1a400b0ab9a8ffbed3f914e40602d8f7181df055
7
- data.tar.gz: 3360fac7092630a575698bde54dee4378de5d954a6fff06e2bd2d8111e22e5a66bf8d67baac1a498ecb0e4f52ee8b5b48b47bb960f38e994c637e0f0a7296d89
6
+ metadata.gz: 5da3ca3fc8579d8b55043b6f9af8da9ac1f69aa46ec9e4c9858a2318cae1222724679553ec45f61308928f65595bbd71682279aa219e46e698811eb3a27217a2
7
+ data.tar.gz: 3c5f1f99dab00df6e1e66acf202c4a12cf339fb0207566b5ef613d93c8ac262e61b243a05045e30c82dbc3b36667f89bc99345bb4b42456420951a5d7b889420
data/.pryrc CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # .pryrc
2
4
  require 'europe'
3
5
 
@@ -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
@@ -6,3 +6,6 @@ rvm:
6
6
  - 2.4.0
7
7
  - 2.5.0
8
8
  - 2.5.1
9
+ - 2.6.0
10
+ - 2.6.2
11
+ - 2.6.3
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in europe.gemspec
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/VvanGemert/europe/fork )
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rake/testtask'
3
5
  require 'europe/rake_task'
@@ -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 = ['VvanGemert']
10
- spec.email = ['vincent@floorplanner.com']
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/VvanGemert/europe'
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")
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'europe/version'
2
4
  require 'europe/countries/countries'
3
5
  require 'europe/currency/currency'
@@ -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: 'Slovak Republic', source_name: 'Slovensko',
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Europe
2
4
  # Countries
3
5
  module Countries
@@ -1,4 +1,6 @@
1
1
  #!/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  # Source: Wikipedia
3
5
  require 'europe/currency/exchange_rates'
4
6
 
@@ -1,4 +1,5 @@
1
- require 'rexml/document'
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.xml'.freeze
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
- xml = REXML::Document.new(doc)
20
+ data = JSON.parse(doc)
20
21
 
21
- rates = { date: Date.parse(xml.elements.first.elements[7].text),
22
+ rates = { date: Date.parse(data['usd']['date']),
22
23
  rates: {} }
23
24
 
24
- filter_rates(xml, rates)
25
+ filter_rates(data, rates)
26
+ rescue JSON::ParserError
27
+ :failed
25
28
  end
26
29
 
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
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/'.freeze
13
+ '/rest/data/v2.1/json/en/'
12
14
 
13
15
  def self.retrieve(dataset, filters)
14
16
  fetch_stats(dataset, filters)
@@ -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.keys.include?(country_code.to_sym)
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
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Europe
2
4
  # RakeTask
3
5
  module RakeTask
@@ -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(open(EUROSTAT_BULK_URL + 'table_of_contents_en.txt'), f)
16
+ IO.copy_stream(data, f)
12
17
  end
13
18
  end
14
19
  end
@@ -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.keys.include?(country_code)
43
+ return false unless VAT_REGEX.key?(country_code)
44
+
42
45
  match_vat_number(number, country_code)
43
46
  end
44
47
 
@@ -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/youreurope/business/taxation/' \
8
- 'vat/vat-rules-rates/index_en.htm'.freeze
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[3].text
29
- rate = result[5].text
30
- rates[country.to_sym] = rate.to_f if country
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
 
@@ -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'.freeze
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.freeze
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
- return :timeout
42
+ :timeout
39
43
  rescue Net::HTTPServerError
40
- return :server_error
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: Date.parse(extract_data(body, 3)),
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].text
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
- .keys.include?(number[0..1].to_sym)
81
+ .key?(number[0..1].to_sym)
71
82
  end
72
83
  end
73
84
 
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Europe version
2
4
  module Europe
3
- VERSION = '0.0.11'.freeze
5
+ VERSION = '0.0.16'
4
6
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  module Europe
@@ -1,4 +1,6 @@
1
1
  #!/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'test_helper'
3
5
 
4
6
  module Europe
@@ -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].keys.include?(:GBP)
17
+ assert rates[:rates].key?(:GBP)
16
18
  end
17
19
  end
18
20
  end
@@ -1,4 +1,6 @@
1
1
  #!/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'test_helper'
3
5
 
4
6
  module Europe
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  module Europe
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  module Europe
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  module Europe
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  module Europe
@@ -1,4 +1,6 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
2
4
  require 'europe'
3
5
  require 'minitest/autorun'
4
6
  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.11
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
- - VvanGemert
8
- autorequire:
7
+ - Gem shards
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-18 00:00:00.000000000 Z
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@floorplanner.com
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/VvanGemert/europe
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
- rubyforge_project:
200
- rubygems_version: 2.7.6
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: