ruby-vies 2.0.0 → 2.0.1
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 +4 -4
- data/Gemfile.lock +28 -14
- data/lib/ruby/vies/version.rb +1 -1
- data/lib/ruby/vies.rb +23 -12
- 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: 8acb99fb51bb2f419f66efe09820d25c024a1b825c6c6b51aaf00fd1fc2555d7
|
4
|
+
data.tar.gz: 63b872131431a1073a677719fa39c8ba8f009ff2d9cfbc6799c86447e573c850
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c973b7561ea0208482b8beaf5e9fd1758ba13ea7187f8fc11f5c5aadebd38f7408bc59a0c0bb06cb3705353ad04de86a71397520177f9ded86e2eeb88692e10e
|
7
|
+
data.tar.gz: bf08224fd1c457e272bfd8a5c3c942d537c2b3957183779c4e846ad1270f425bb65ae7c10098ef0f59ebb5f5b2528ea9c96587a07a73eab587f1ca23ed37906c
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ruby-vies (2.0.
|
4
|
+
ruby-vies (2.0.1)
|
5
5
|
activesupport (~> 7.0)
|
6
6
|
finest-builder (~> 2.0)
|
7
7
|
httparty (~> 0.18)
|
@@ -26,6 +26,7 @@ GEM
|
|
26
26
|
ast (2.4.2)
|
27
27
|
builder (3.2.4)
|
28
28
|
concurrent-ruby (1.1.10)
|
29
|
+
date (3.3.3)
|
29
30
|
diff-lcs (1.5.0)
|
30
31
|
finest-builder (2.0.0)
|
31
32
|
gyoku (1.4.0)
|
@@ -38,27 +39,39 @@ GEM
|
|
38
39
|
rack
|
39
40
|
i18n (1.12.0)
|
40
41
|
concurrent-ruby (~> 1.0)
|
41
|
-
json (2.6.
|
42
|
-
mail (2.
|
42
|
+
json (2.6.3)
|
43
|
+
mail (2.8.0)
|
43
44
|
mini_mime (>= 0.1.1)
|
45
|
+
net-imap
|
46
|
+
net-pop
|
47
|
+
net-smtp
|
44
48
|
mime-types (3.4.1)
|
45
49
|
mime-types-data (~> 3.2015)
|
46
50
|
mime-types-data (3.2022.0105)
|
47
51
|
mini_mime (1.1.2)
|
48
52
|
minitest (5.16.3)
|
49
53
|
multi_xml (0.6.0)
|
50
|
-
|
54
|
+
net-imap (0.3.4)
|
55
|
+
date
|
56
|
+
net-protocol
|
57
|
+
net-pop (0.1.2)
|
58
|
+
net-protocol
|
59
|
+
net-protocol (0.2.1)
|
60
|
+
timeout
|
61
|
+
net-smtp (0.3.3)
|
62
|
+
net-protocol
|
63
|
+
nokogiri (1.13.10-x86_64-linux)
|
51
64
|
racc (~> 1.4)
|
52
65
|
nori (2.6.0)
|
53
66
|
parallel (1.22.1)
|
54
|
-
parser (3.1.
|
67
|
+
parser (3.1.3.0)
|
55
68
|
ast (~> 2.4.1)
|
56
|
-
public_suffix (5.0.
|
57
|
-
racc (1.6.
|
58
|
-
rack (3.0.
|
69
|
+
public_suffix (5.0.1)
|
70
|
+
racc (1.6.2)
|
71
|
+
rack (3.0.2)
|
59
72
|
rainbow (3.1.1)
|
60
73
|
rake (13.0.6)
|
61
|
-
regexp_parser (2.6.
|
74
|
+
regexp_parser (2.6.1)
|
62
75
|
rexml (3.2.5)
|
63
76
|
rspec (3.12.0)
|
64
77
|
rspec-core (~> 3.12.0)
|
@@ -66,14 +79,14 @@ GEM
|
|
66
79
|
rspec-mocks (~> 3.12.0)
|
67
80
|
rspec-core (3.12.0)
|
68
81
|
rspec-support (~> 3.12.0)
|
69
|
-
rspec-expectations (3.12.
|
82
|
+
rspec-expectations (3.12.1)
|
70
83
|
diff-lcs (>= 1.2.0, < 2.0)
|
71
84
|
rspec-support (~> 3.12.0)
|
72
|
-
rspec-mocks (3.12.
|
85
|
+
rspec-mocks (3.12.1)
|
73
86
|
diff-lcs (>= 1.2.0, < 2.0)
|
74
87
|
rspec-support (~> 3.12.0)
|
75
88
|
rspec-support (3.12.0)
|
76
|
-
rubocop (1.
|
89
|
+
rubocop (1.41.1)
|
77
90
|
json (~> 2.3)
|
78
91
|
parallel (~> 1.10)
|
79
92
|
parser (>= 3.1.2.1)
|
@@ -83,10 +96,10 @@ GEM
|
|
83
96
|
rubocop-ast (>= 1.23.0, < 2.0)
|
84
97
|
ruby-progressbar (~> 1.7)
|
85
98
|
unicode-display_width (>= 1.4.0, < 3.0)
|
86
|
-
rubocop-ast (1.
|
99
|
+
rubocop-ast (1.24.0)
|
87
100
|
parser (>= 3.1.1.0)
|
88
101
|
ruby-progressbar (1.11.0)
|
89
|
-
savon (2.
|
102
|
+
savon (2.14.0)
|
90
103
|
akami (~> 1.2)
|
91
104
|
builder (>= 2.1.2)
|
92
105
|
gyoku (~> 1.2)
|
@@ -95,6 +108,7 @@ GEM
|
|
95
108
|
nokogiri (>= 1.8.1)
|
96
109
|
nori (~> 2.4)
|
97
110
|
wasabi (~> 3.4)
|
111
|
+
timeout (0.3.1)
|
98
112
|
tzinfo (2.0.5)
|
99
113
|
concurrent-ruby (~> 1.0)
|
100
114
|
unicode-display_width (2.3.0)
|
data/lib/ruby/vies/version.rb
CHANGED
data/lib/ruby/vies.rb
CHANGED
@@ -4,7 +4,8 @@ require_relative "vies/version"
|
|
4
4
|
require "savon"
|
5
5
|
require "httparty"
|
6
6
|
require "finest/builder"
|
7
|
-
require
|
7
|
+
require "active_support/isolated_execution_state"
|
8
|
+
require "active_support/core_ext/hash/indifferent_access"
|
8
9
|
require "active_support/core_ext/module"
|
9
10
|
require "active_support/core_ext/object"
|
10
11
|
|
@@ -12,6 +13,16 @@ module Ruby
|
|
12
13
|
module Vies
|
13
14
|
class Error < StandardError; end
|
14
15
|
|
16
|
+
mattr_accessor :endpoints, default: {
|
17
|
+
siren: "https://api.avis-situation-sirene.insee.fr/identification/siren/%<siren>s",
|
18
|
+
vat: "https://ec.europa.eu/taxation_customs/vies/services/checkVatService.wsdl"
|
19
|
+
}
|
20
|
+
|
21
|
+
# Setup data from initializer
|
22
|
+
def self.setup
|
23
|
+
yield(self)
|
24
|
+
end
|
25
|
+
|
15
26
|
class Client
|
16
27
|
include Savon
|
17
28
|
include HTTParty
|
@@ -19,30 +30,30 @@ module Ruby
|
|
19
30
|
|
20
31
|
mattr_reader :id_numbers, default: { FR: "((12 + 3 * ( %d.divmod(97)[1])).divmod(97)[1])" }
|
21
32
|
|
22
|
-
def initialize(args =
|
23
|
-
super args
|
33
|
+
def initialize(args = nil)
|
34
|
+
super args || {}
|
24
35
|
end
|
25
36
|
|
26
|
-
def check_vat_details(args
|
27
|
-
args[:country_code].upcase == "FR" ? check_siren(args) : check_vat(args)
|
28
|
-
rescue => e
|
37
|
+
def check_vat_details(args)
|
38
|
+
(args[:country_code].upcase == "FR" ? check_siren(args) : check_vat(args)).with_indifferent_access
|
39
|
+
rescue StandardError => e
|
29
40
|
{ error: e&.message, valid: false }
|
30
41
|
end
|
31
42
|
|
32
43
|
protected
|
33
44
|
|
34
|
-
def generate_id(vat
|
45
|
+
def generate_id(vat)
|
35
46
|
id_numbers[vat[:country_code].to_sym] &&
|
36
47
|
"%02<digit>d%<vat>d" % {
|
37
48
|
digit: eval(id_numbers[vat[:country_code].to_sym] % vat[:vat_number]),
|
38
49
|
vat: vat[:vat_number]
|
39
50
|
} || vat[:vat_number]
|
40
|
-
rescue
|
51
|
+
rescue StandardError
|
41
52
|
vat[:vat_number]
|
42
53
|
end
|
43
54
|
|
44
|
-
def check_vat(args
|
45
|
-
Savon::Client.new(wsdl:
|
55
|
+
def check_vat(args)
|
56
|
+
Savon::Client.new(wsdl: Ruby::Vies.endpoints[:vat])
|
46
57
|
.call(
|
47
58
|
:check_vat,
|
48
59
|
message: args.merge({ vat_number: generate_id(args) }).as_json.transform_keys! { |i| i.camelize(:lower) },
|
@@ -50,8 +61,8 @@ module Ruby
|
|
50
61
|
).body[:check_vat_response].as_json(except: :@xmlns)
|
51
62
|
end
|
52
63
|
|
53
|
-
def check_siren(args
|
54
|
-
url =
|
64
|
+
def check_siren(args)
|
65
|
+
url = Ruby::Vies.endpoints[:siren] % { siren: args.fetch(:vat_number) }
|
55
66
|
if (resp = JSON.parse(self.class.method(:get).call(url).body))["code"]
|
56
67
|
{ error: resp["message"], valid: false }
|
57
68
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-vies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduard Garcia Castelló
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: finest-builder
|