valvat 0.9.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.github/workflows/ruby.yml +35 -0
  5. data/.gitignore +3 -1
  6. data/.rubocop.yml +15 -0
  7. data/CHANGES.md +30 -1
  8. data/Gemfile +4 -3
  9. data/Guardfile +6 -4
  10. data/README.md +99 -47
  11. data/Rakefile +3 -1
  12. data/certs/yolk.pem +21 -21
  13. data/gemfiles/activemodel-5 +4 -5
  14. data/gemfiles/activemodel-6 +7 -0
  15. data/gemfiles/standalone +3 -5
  16. data/lib/active_model/validations/valvat_validator.rb +70 -22
  17. data/lib/valvat.rb +7 -3
  18. data/lib/valvat/checksum.rb +14 -13
  19. data/lib/valvat/checksum/at.rb +3 -1
  20. data/lib/valvat/checksum/be.rb +3 -1
  21. data/lib/valvat/checksum/bg.rb +17 -17
  22. data/lib/valvat/checksum/cy.rb +2 -0
  23. data/lib/valvat/checksum/de.rb +5 -3
  24. data/lib/valvat/checksum/dk.rb +3 -1
  25. data/lib/valvat/checksum/ee.rb +2 -0
  26. data/lib/valvat/checksum/es.rb +14 -16
  27. data/lib/valvat/checksum/fi.rb +3 -1
  28. data/lib/valvat/checksum/fr.rb +4 -2
  29. data/lib/valvat/checksum/gb.rb +53 -21
  30. data/lib/valvat/checksum/gr.rb +4 -2
  31. data/lib/valvat/checksum/hr.rb +2 -0
  32. data/lib/valvat/checksum/hu.rb +2 -0
  33. data/lib/valvat/checksum/ie.rb +5 -6
  34. data/lib/valvat/checksum/it.rb +6 -4
  35. data/lib/valvat/checksum/lt.rb +2 -0
  36. data/lib/valvat/checksum/lu.rb +3 -1
  37. data/lib/valvat/checksum/mt.rb +2 -0
  38. data/lib/valvat/checksum/nl.rb +5 -3
  39. data/lib/valvat/checksum/pl.rb +3 -1
  40. data/lib/valvat/checksum/pt.rb +3 -1
  41. data/lib/valvat/checksum/ro.rb +2 -0
  42. data/lib/valvat/checksum/se.rb +5 -3
  43. data/lib/valvat/checksum/si.rb +4 -2
  44. data/lib/valvat/error.rb +31 -0
  45. data/lib/valvat/local.rb +8 -5
  46. data/lib/valvat/locales/de.yml +2 -1
  47. data/lib/valvat/locales/en.yml +2 -1
  48. data/lib/valvat/locales/es.yml +1 -0
  49. data/lib/valvat/locales/fr.yml +1 -0
  50. data/lib/valvat/locales/hu.yml +1 -0
  51. data/lib/valvat/locales/nl.yml +1 -0
  52. data/lib/valvat/locales/pl.yml +1 -0
  53. data/lib/valvat/locales/pt.yml +28 -28
  54. data/lib/valvat/lookup.rb +14 -45
  55. data/lib/valvat/lookup/fault.rb +31 -0
  56. data/lib/valvat/lookup/request.rb +37 -11
  57. data/lib/valvat/lookup/response.rb +37 -0
  58. data/lib/valvat/syntax.rb +31 -30
  59. data/lib/valvat/utils.rb +20 -9
  60. data/lib/valvat/version.rb +3 -1
  61. data/spec/active_model/validations/valvat_validator_spec.rb +132 -100
  62. data/spec/spec_helper.rb +8 -8
  63. data/spec/valvat/checksum/at_spec.rb +8 -6
  64. data/spec/valvat/checksum/be_spec.rb +8 -6
  65. data/spec/valvat/checksum/bg_spec.rb +9 -6
  66. data/spec/valvat/checksum/cy_spec.rb +5 -3
  67. data/spec/valvat/checksum/de_spec.rb +8 -6
  68. data/spec/valvat/checksum/dk_spec.rb +8 -6
  69. data/spec/valvat/checksum/ee_spec.rb +5 -3
  70. data/spec/valvat/checksum/es_spec.rb +9 -6
  71. data/spec/valvat/checksum/fi_spec.rb +8 -6
  72. data/spec/valvat/checksum/fr_spec.rb +8 -6
  73. data/spec/valvat/checksum/gb_spec.rb +9 -5
  74. data/spec/valvat/checksum/gr_spec.rb +8 -6
  75. data/spec/valvat/checksum/hr_spec.rb +5 -3
  76. data/spec/valvat/checksum/hu_spec.rb +5 -3
  77. data/spec/valvat/checksum/ie_spec.rb +13 -5
  78. data/spec/valvat/checksum/it_spec.rb +12 -10
  79. data/spec/valvat/checksum/lt_spec.rb +5 -3
  80. data/spec/valvat/checksum/lu_spec.rb +8 -6
  81. data/spec/valvat/checksum/mt_spec.rb +5 -3
  82. data/spec/valvat/checksum/nl_spec.rb +9 -7
  83. data/spec/valvat/checksum/pl_spec.rb +10 -8
  84. data/spec/valvat/checksum/pt_spec.rb +12 -13
  85. data/spec/valvat/checksum/ro_spec.rb +5 -3
  86. data/spec/valvat/checksum/se_spec.rb +10 -8
  87. data/spec/valvat/checksum/si_spec.rb +12 -10
  88. data/spec/valvat/checksum_spec.rb +12 -10
  89. data/spec/valvat/lookup/fault_spec.rb +34 -0
  90. data/spec/valvat/lookup/request_spec.rb +19 -0
  91. data/spec/valvat/lookup/response_spec.rb +29 -0
  92. data/spec/valvat/lookup_spec.rb +202 -84
  93. data/spec/valvat/syntax_spec.rb +59 -280
  94. data/spec/valvat/utils_spec.rb +76 -43
  95. data/spec/valvat_spec.rb +140 -152
  96. data/valvat.gemspec +18 -17
  97. metadata +61 -41
  98. metadata.gz.sig +3 -3
  99. data/.travis.yml +0 -33
  100. data/gemfiles/activemodel-3-2 +0 -8
  101. data/gemfiles/activemodel-4 +0 -8
  102. data/gemfiles/before-ruby21/activemodel-3-2 +0 -9
  103. data/gemfiles/before-ruby21/activemodel-4 +0 -9
  104. data/gemfiles/before-ruby21/standalone +0 -8
  105. data/lib/valvat/lookup/request_with_id.rb +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d200983c316dadd7d6fa2382bf7e76c3153cfe81a8b27ea820b4dd388f2868be
4
- data.tar.gz: 27271cbfc2172fd9a335fe574d49a521bd7a0955710e1eace8493b74076ce157
3
+ metadata.gz: ddc578b98f0c869566769b5588b5768bbdcc5ba4901ab97227c7908502a7b5c9
4
+ data.tar.gz: f7bfc69d3cd2983bb3d306d0932ef6d436890850bc67f6c63e639d2c666dc1ac
5
5
  SHA512:
6
- metadata.gz: 997033c89f5641814cc856ac06a9029e937af9147b7450cf4b1ea2866090da46329310d6c72e7f14a94f0a7d5cdf2ebeedd3914bde0e6b1b66eeaa8b57422eea
7
- data.tar.gz: fd50ce45794e3985ad2534be289f1e620e790ad75dfc27b91a5e5ac6022268ad0b50206bd951f5a6b9c8dbb1e407d2b5467e68ad4ee90380d78bf47d836c1a09
6
+ metadata.gz: 910d4c387c6e82adeee3146b54e928b253fcd4aae6873ae438a575612b72a136459d50411c565ba47683b1b8f325f90771774add2b7110b1c4a6c4e880ba0999
7
+ data.tar.gz: a93a4d12a53fe3601525a153c6f2ae042259371f1775c05fb27ada151e91f3ff0325f794332797eb31ff502606dd31edee502d910866e8c76feeb6613cb3b95e
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -0,0 +1,35 @@
1
+ name: Specs
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ paths-ignore:
7
+ - 'README.md'
8
+ - 'CHANGES.md'
9
+ pull_request:
10
+ branches: [ master ]
11
+
12
+ jobs:
13
+ test:
14
+ if: "!contains(github.event.head_commit.message, '[skip ci]')"
15
+ runs-on: ubuntu-latest
16
+ env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
17
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}
18
+ strategy:
19
+ matrix:
20
+ ruby-version: ['2.5', '2.6', '2.7', '3.0', 'jruby-head']
21
+ gemfile: [ 'standalone', 'activemodel-5', 'activemodel-6' ]
22
+ exclude:
23
+ - ruby-version: '3.0'
24
+ gemfile: 'activemodel-5'
25
+
26
+ steps:
27
+ - uses: actions/checkout@v2
28
+ - name: Set up Ruby
29
+ uses: ruby/setup-ruby@v1
30
+ with:
31
+ ruby-version: ${{ matrix.ruby-version }}
32
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
33
+ - name: Run specs
34
+ run: |
35
+ bundle exec rspec
data/.gitignore CHANGED
@@ -2,6 +2,8 @@ pkg/*
2
2
  *.gem
3
3
  .bundle
4
4
  Gemfile.lock
5
+ gemfiles/*.lock
5
6
  tmp
6
7
  .rbenv-*
7
- .ruby-version
8
+ .ruby-version
9
+ .ruby-gemset
data/.rubocop.yml ADDED
@@ -0,0 +1,15 @@
1
+ require: rubocop-rspec
2
+ AllCops:
3
+ NewCops: enable
4
+ TargetRubyVersion: 2.5
5
+
6
+ Metrics/BlockLength:
7
+ Exclude:
8
+ - valvat.gemspec
9
+ - spec/**/*_spec.rb
10
+
11
+ Style/Documentation:
12
+ Enabled: false
13
+
14
+ RSpec/MultipleExpectations:
15
+ Enabled: false
data/CHANGES.md CHANGED
@@ -1,7 +1,36 @@
1
1
 
2
2
  ### dev
3
3
 
4
- [full changelog](http://github.com/yolk/valvat/compare/v0.9.1...master)
4
+ [full changelog](http://github.com/yolk/valvat/compare/v1.1.0...master)
5
+
6
+ ### 1.1.0 / 2021-01-15
7
+
8
+ [full changelog](http://github.com/yolk/valvat/compare/v1.0.1...v1.1.0)
9
+
10
+ * Added support for Northern Ireland XI prefixed VAT numbers (by [Avatar Ignacy Kasperowicz](https://github.com/kspe))
11
+ * ActiveModel: Return specific error message if VIES is down and fail_if_down is set to true (by [Arkadiy Zabazhanov](https://github.com/pyromaniac))
12
+ * Removed support for EOL rubies (all before 2.5) and ActiveModel before 5.0
13
+
14
+ ### 1.0.1 / 2020-12-06
15
+
16
+ [full changelog](http://github.com/yolk/valvat/compare/v1.0.0...v1.0.1)
17
+
18
+ * Added missing spaces to malformatted portuegese locale file
19
+ * Removed GB from EU_COUNTRIES / EU_MEMBER_STATES but kept support
20
+ * Fixed typo in error message: UNK(N)OWN (by [Igor Gonchar](https://github.com/gigorok))
21
+
22
+ ### 1.0.0 / 2020-11-06
23
+
24
+ [full changelog](http://github.com/yolk/valvat/compare/v0.9.1...v1.0.0)
25
+
26
+ * Refactored lookup to use specific rescue for savons soapfaults
27
+ * Raises vies specific error classes to help debugging temporary and permanent VIES errors
28
+ * Lookup#validate supports :savon option to allow altering the behaviour of the used savon client
29
+ * ActiveModel validator now supports all lookup options.
30
+ * Use https instead of http for accessing vies (by [Crazy Chris](https://github.com/lubekpl))
31
+ * Lookup#validate supports :raise_error option to return nil instead of raising (known) error when connecting to the VIES web service.
32
+ * [BUGFIX] Checksum: Prevent error on some invalid IE vat numbers
33
+ * EN: Capitalized VAT in error messages (and specs) (by [Vitalii Kashoid](https://github.com/Kashoid23))
5
34
 
6
35
  ### 0.9.1 / 2020-03-19
7
36
 
data/Gemfile CHANGED
@@ -1,7 +1,8 @@
1
- source 'http://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in valvat.gemspec
4
6
  gemspec
5
7
 
6
- gem 'rake'
7
- gem 'guard-rspec', '~>4.0'
8
+ gem 'guard-rspec', '~>4.0'
data/Guardfile CHANGED
@@ -1,5 +1,7 @@
1
- guard :rspec, cmd: "bundle exec rspec --color" do
2
- watch(/^spec\/(.*)_spec.rb/)
3
- watch(/^lib\/(.*)\.rb/) { |m| "spec/#{m[1]}_spec.rb" }
4
- watch(/^spec\/spec_helper.rb/) { "spec" }
1
+ # frozen_string_literal: true
2
+
3
+ guard :rspec, cmd: 'bundle exec rspec --color' do
4
+ watch(%r{^spec/(.*)_spec.rb})
5
+ watch(%r{^lib/(.*)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
6
+ watch(%r{^spec/spec_helper.rb}) { 'spec' }
5
7
  end
data/README.md CHANGED
@@ -1,10 +1,16 @@
1
1
  valvat
2
2
  ===========
3
3
 
4
- [![Gem Version](https://badge.fury.io/rb/valvat.svg)](http://badge.fury.io/rb/valvat) [![Build Status](https://travis-ci.org/yolk/valvat.svg)](https://travis-ci.org/yolk/valvat) [![Code Climate](https://codeclimate.com/github/yolk/valvat.svg)](https://codeclimate.com/github/yolk/valvat)
4
+ [![rubygems](https://badgen.net/rubygems/v/valvat)](https://rubygems.org/gems/valvat) [![Specs](https://github.com/yolk/valvat/workflows/Specs/badge.svg)](https://github.com/yolk/valvat/actions?query=workflow%3ASpecs)
5
5
 
6
6
  Validates european vat numbers. Standalone or as a ActiveModel validator.
7
7
 
8
+ ## A note on Brexit
9
+
10
+ Valvat supports validating VAT-IDs from the UK by syntax & checksum for now. Validation against the VIES web service will probably stop working (and return `false`) in 2021.
11
+
12
+ Northern Ireland received its own VAT number prefix - XI which is supported by VIES web service so any XI-prefixed VAT numbers should be validated as any EU VAT number.
13
+
8
14
  ## Features
9
15
 
10
16
  * Simple syntax verification
@@ -14,7 +20,7 @@ Validates european vat numbers. Standalone or as a ActiveModel validator.
14
20
  * I18n locales for language specific error messages in English, German, French, Spanish, Italian, Portuguese, Polish, Swedish, Dutch, Danish, Czech, Slovakian, Hungarian, Bulgarian, Romanian, Latvian, Catalan, Norwegian, and Finnish.
15
21
  * *Experimental* checksum verification
16
22
 
17
- valvat is tested and works with ruby MRI 1.9.3/2.0/2.1/2.2/2.3/2.4/2.5/2.6, jruby (in 1.9 mode) and ActiveModel 3/4/5
23
+ valvat is tested and works with ruby MRI 2.5/2.6/2.7/3.0, jruby-head and ActiveModel 5/6. If you need support for ruby down to 1.9.3 and ActiveModel 3 and 4 use [v1.0.1](https://github.com/yolk/valvat/tree/v1.0.1).
18
24
 
19
25
  ## Installation
20
26
 
@@ -22,9 +28,9 @@ Add it to your Gemfile:
22
28
 
23
29
  gem 'valvat'
24
30
 
25
- To use less memory (~3.5 mb vs. ~0.5 mb) and load only the local verification functionality – and not the remote lookup with VIES – add it like this instead:
31
+ To use less memory (~0.5 mb vs. ~3.5 mb) and load only the local verification functionality – and not the remote lookup with VIES – add it like this instead:
26
32
 
27
- gem 'valvat', :require => 'valvat/local'
33
+ gem 'valvat', require: 'valvat/local'
28
34
 
29
35
  In any case run:
30
36
 
@@ -34,72 +40,114 @@ Or install it yourself as:
34
40
 
35
41
  $ gem install valvat
36
42
 
37
- ## Basic Usage
43
+ ## Validate the syntax of a VAT number
38
44
 
39
45
  To verify the syntax of a vat number:
40
46
 
41
47
  Valvat.new("DE345789003").valid?
42
48
  => true or false
43
49
 
44
- To check if the given vat number exists via the VIES web service:
45
-
46
- Valvat.new("DE345789003").exists?
47
- => true or false or nil
50
+ It is also possible to bypass initializing a Valvat instance and check the syntax of a vat number string directly with:
48
51
 
49
- *IMPORTANT* Keep in mind that the VIES web service might be offline at some time for some countries. If this happens `exists?` or `Valvat::Lookup.validate` will return `nil`.
52
+ Valvat::Syntax.validate("DE345789003")
53
+ => true or false
50
54
 
51
- Visit [http://ec.europa.eu/taxation_customs/vies/viesspec.do](http://ec.europa.eu/taxation_customs/vies/viesspec.do) for more accurate information at what time the service for a specific country will be down.
55
+ ## Validate agains the VIES web service
52
56
 
53
- It is also possible to bypass initializing a Valvat instance and check the syntax of a var number string directly with:
57
+ To check if the given vat number exists via the VIES web service:
54
58
 
55
- Valvat::Syntax.validate("DE345789003")
56
- => true or false
59
+ Valvat.new("DE345789003").exists?
60
+ => true or false or nil
57
61
 
58
62
  Or to lookup a vat number string directly via VIES web service:
59
63
 
60
64
  Valvat::Lookup.validate("DE345789003")
61
65
  => true or false or nil
62
66
 
63
- ## Experimental checksum verification
64
-
65
- valvat allows to check vat numbers from AT, BE, BG, DE, DK, ES, FR, FI, GR, IE, IT, LU, NL, PL, PT, SE and SI against a checksum calculation. All other countries will fall back to a simple syntax check:
67
+ *IMPORTANT* Keep in mind that the VIES web service might be offline at some time for all or some member states. If this happens `exists?` or `Valvat::Lookup.validate` will return `nil`. See *Handling of VIES maintenance errors* for further details.
66
68
 
67
- Valvat.new("DE345789003").valid_checksum?
68
- => true or false
69
-
70
- These results are more valuable than a simple syntax check, but keep in mind: they can not replace a lookup via VIES.
71
-
72
- *IMPORTANT* This feature was tested against all vat numbers I could get my hand on, but it is still marked as *experimental* because these calculations are not documented and may return wrong results.
73
-
74
- To bypass initializing a Valvat instance:
69
+ ### Details & request identifier
75
70
 
76
- Valvat::Checksum.validate("DE345789003")
77
- => true or false
78
-
79
- ## Details & request identifier
80
-
81
- If you need all details and not only if the VAT is valid, pass {:detail => true} as second parameter to the lookup call.
71
+ If you need all details and not only if the VAT is valid, pass {detail: true} as second parameter to the lookup call.
82
72
 
83
- Valvat.new("IE6388047V").exists?(:detail => true)
73
+ Valvat.new("IE6388047V").exists?(detail: true)
84
74
  => {
85
- :country_code=>"IE", :vat_number => "6388047V",
75
+ :country_code=>"IE", :vat_number => "6388047V", :valid => true,
86
76
  :request_date => Date.today, :name=>"GOOGLE IRELAND LIMITED",
87
77
  :address=>"1ST & 2ND FLOOR ,GORDON HOUSE ,BARROW STREET ,DUBLIN 4"
88
78
  } or false or nil
89
79
 
90
- According to EU law, or at least as Austria sees it, it's mandatory to verify the UID number of every new customer, but also to check the UID Number periodicaly. To prove that you have checked the UID number, the VIES Web service can return a requestIdentifier.
80
+ According to EU law, or at least as Austria sees it, it's mandatory to verify the VAT number of every new customer, but also to check the VAT number periodicaly. To prove that you have checked the VAT number, the VIES Web service can return a `request_identifier`.
91
81
 
92
- To receive a requestIdentifier you need to pass your own VAT number in the options hash. In this Example, Google (VAT IE6388047V) is checking the validity of eBays VAT number (LU21416127)
82
+ To receive a `request_identifier` you need to pass your own VAT number in the options hash. In this example, Google (VAT IE6388047V) is checking the validity of eBays VAT number (LU21416127)
93
83
 
94
- Valvat.new("LU21416127").exists?(:requester_vat => "IE6388047V")
84
+ Valvat.new("LU21416127").exists?(requester: "IE6388047V")
95
85
  => {
96
- :country_code=>"LU", :vat_number => "21416127",
86
+ :country_code=>"LU", :vat_number => "21416127", :valid => true,
97
87
  :request_date => Date.today, :name=>"EBAY EUROPE S.A R.L.",
98
88
  :address => "22, BOULEVARD ROYAL\nL-2449 LUXEMBOURG",
99
89
  :company_type => nil, :request_identifier => "some_uniq_string"
100
90
  } or false or nil
101
91
 
102
- ## Usage with ActiveModel / Rails 3
92
+ If the given `requester` is invalid, a `Valvat::InvalidRequester` error is thrown.
93
+
94
+ ### Handling of VIES maintenance errors
95
+
96
+ From time to time the VIES web service for one or all member states is down for maintenance. To handle this kind of temporary errors, `Valvat::Lookup#validate` returns `nil` by default to indicate that there is no way at the moment to say if the given VAT is valid or not. You should revalidate the VAT later. If you prefer an error, use the `raise_error` option:
97
+
98
+ Valvat.new("IE6388047V").exists?(raise_error: true)
99
+
100
+ This raises `Valvat::ServiceUnavailable` or `Valvat::MemberStateUnavailable` instead of returning `nil`.
101
+
102
+ Visit [http://ec.europa.eu/taxation_customs/vies/viesspec.do](http://ec.europa.eu/taxation_customs/vies/viesspec.do) for more accurate information at what time the service for a specific member state will be down.
103
+
104
+ ### Handling of other VIES errors
105
+
106
+ All other errors accuring while validating against the VIES web service are raised and must be handled by you. These include:
107
+
108
+ * `Valvat::InvalidRequester`
109
+ * `Valvat::BlockedError`
110
+ * `Valvat::RateLimitError`
111
+ * `Valvat::Timeout`
112
+ * all IO errors
113
+
114
+ If you want to suppress all known error cases. Pass in the `raise_error` option set to `false`:
115
+
116
+ Valvat.new("IE6388047V").exists?(raise_error: false)
117
+
118
+ This will return `nil` instead of raising a known error.
119
+
120
+ ### Set options for the savon client
121
+
122
+ Use the `:savon` key to set options for the used savon SOAP client. For example to log all requests:
123
+
124
+ Valvat.new("IE6388047V").exists?(savon: {log: true})
125
+
126
+ Or to use higher timeouts for the requests:
127
+
128
+ Valvat.new("IE6388047V").exists?(savon: {open_timeout: 10, read_timeout: 10})
129
+
130
+ ### Skip local validation before lookup
131
+
132
+ To prevent unnecessary requests, valvat performs a local syntax check before making the request to the VIES web service. If you want to skip this step (for any reason), set the `:skip_local_validation` option to `true`.
133
+
134
+ ## Experimental checksum verification
135
+
136
+ valvat allows to check vat numbers from AT, BE, BG, DE, DK, ES, FR, FI, GR, IE, IT, LU, NL, PL, PT, SE and SI against a checksum calculation. All other member states will fall back to a basic syntax check:
137
+
138
+ Valvat.new("DE345789003").valid_checksum?
139
+ => true or false
140
+
141
+ These results are more valuable than a simple syntax check, but keep in mind: they can not replace a lookup via VIES.
142
+
143
+ *IMPORTANT* This feature was tested against all vat numbers I could get my hand on, but it is still marked as *experimental* because these calculations are not documented and may return wrong results.
144
+
145
+ To bypass initializing a Valvat instance:
146
+
147
+ Valvat::Checksum.validate("DE345789003")
148
+ => true or false
149
+
150
+ ## Usage with ActiveModel / Rails
103
151
 
104
152
  ### Loading
105
153
 
@@ -114,30 +162,34 @@ after ActiveModel has been loaded.
114
162
  To validate the attribute `vat_number` add this to your model:
115
163
 
116
164
  class MyModel < ActiveRecord::Base
117
- validates :vat_number, :valvat => true
165
+ validates :vat_number, valvat: true
118
166
  end
119
167
 
120
168
  ### Additional lookup validation
121
169
 
122
170
  To additionally perform a lookup via VIES:
123
171
 
124
- validates :vat_number, :valvat => {:lookup => true}
172
+ validates :vat_number, valvat: {lookup: true}
125
173
 
126
174
  By default this will validate to true if the VIES web service is down. To fail in this case simply add the `:fail_if_down` option:
127
175
 
128
- validates :vat_number, :valvat => {:lookup => :fail_if_down}
176
+ validates :vat_number, valvat: {lookup: {fail_if_down: true}}
177
+
178
+ You can pass in any options accepted by `Valvat::Lookup#validate`:
179
+
180
+ validates :vat_number, valvat: {lookup: {raise_error: true, savon: {log: true}}}
129
181
 
130
182
  ### Additional (and experimental) checksum validation
131
183
 
132
184
  To additionally perform a checksum validation:
133
185
 
134
- validates :vat_number, :valvat => {:checksum => true}
186
+ validates :vat_number, valvat: {checksum: true}
135
187
 
136
188
  ### Additional ISO country code validation
137
189
 
138
190
  If you want the vat number’s (ISO) country to match another country attribute, use the _match_country_ option:
139
191
 
140
- validates :vat_number, :valvat => {:match_country => :country}
192
+ validates :vat_number, valvat: {match_country: :country}
141
193
 
142
194
  where it is supposed that your model has a method named _country_ which returns the country ISO code you want to match.
143
195
 
@@ -145,17 +197,17 @@ where it is supposed that your model has a method named _country_ which returns
145
197
 
146
198
  By default blank vat numbers validate to false. To change this add the `:allow_blank` option:
147
199
 
148
- validates :vat_number, :valvat => {:allow_blank => true}
200
+ validates :vat_number, valvat: {allow_blank: true}
149
201
 
150
202
  ### Allow vat numbers outside of europe
151
203
 
152
204
  To allow vat numbers from outside of europe, add something like this to your model (country_code should return a upcase ISO country code):
153
205
 
154
206
  class MyModel < ActiveRecord::Base
155
- validates :vat_number, :valvat => true, :if => :eu?
207
+ validates :vat_number, valvat: true, if: :eu?
156
208
 
157
209
  def eu?
158
- Valvat::Utils::EU_COUNTRIES.include?(country_code)
210
+ Valvat::Utils::EU_MEMBER_STATES.include?(country_code)
159
211
  end
160
212
  end
161
213
 
@@ -206,7 +258,7 @@ https://github.com/yolk/valvat/graphs/contributors
206
258
 
207
259
  ## BlaBla
208
260
 
209
- Copyright (c) 2011-2019 Yolk Sebastian Munz & Julia Soergel GbR
261
+ Copyright (c) 2011-2020 Yolk Sebastian Munz & Julia Soergel GbR
210
262
 
211
263
  Beyond that, the implementation is licensed under the MIT License.
212
264
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler'
2
4
  Bundler::GemHelper.install_tasks
3
5
 
@@ -5,4 +7,4 @@ require 'rspec/core/rake_task'
5
7
 
6
8
  RSpec::Core::RakeTask.new(:spec)
7
9
 
8
- task :default => :spec
10
+ task default: :spec
data/certs/yolk.pem CHANGED
@@ -1,25 +1,25 @@
1
1
  -----BEGIN CERTIFICATE-----
2
2
  MIIELDCCApSgAwIBAgIBATANBgkqhkiG9w0BAQsFADAgMR4wHAYDVQQDDBVzZWJh
3
- c3RpYW4vREM9eW8vREM9bGswHhcNMTkxMTE1MTIzMzUwWhcNMjAxMTE0MTIzMzUw
3
+ c3RpYW4vREM9eW8vREM9bGswHhcNMjEwMTA2MTAzMDU3WhcNMjIwMTA2MTAzMDU3
4
4
  WjAgMR4wHAYDVQQDDBVzZWJhc3RpYW4vREM9eW8vREM9bGswggGiMA0GCSqGSIb3
5
- DQEBAQUAA4IBjwAwggGKAoIBgQC96oQ16N6R0H69fWFfsfHo2oIJHtLgETPK6ly+
6
- tLeznJsZomCkZgFS0wNwnExr9qlH+AmygvNoaniVq/Pp2+2jwMuLgk5hkZMRM8Rf
7
- i3wp5LCb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+ 986sKab5AjlJ7TnsmPphCv/UXans7rAVB2lnozlt/kw6dcct5JD4kz1tD6AmO5Qd
21
+ jWRuKNZs66GBglRvseKoypXz1XDCCu1m/uI1IGmKnq8Ry+IeRq9RnlvbfPvSxRIx
22
+ 9aowoL79T9plhcEcEX/KYRp8ht1z+3Vyk2UVZP8Xl5x+K44co5xdhljYi1gtw0w8
23
+ KzzULF0bF9oNpXwBEamlH2myNb19u1W8ijobQ7Y19ca8UFHr5LI32ZW5Zlmep8je
24
+ vb+o07oLRx3t2T/EO4DZ1w==
25
+ -----END CERTIFICATE-----