ruby-vies 2.0.0 → 2.0.1

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: 9908cb1be6ad7dda61a86461a517cf18b86172cef0204b08474609a6c30ee579
4
- data.tar.gz: d57105660e5fd91e21aeda6546997296ceb36bc37414006c2627a8b3bc37c3c8
3
+ metadata.gz: 8acb99fb51bb2f419f66efe09820d25c024a1b825c6c6b51aaf00fd1fc2555d7
4
+ data.tar.gz: 63b872131431a1073a677719fa39c8ba8f009ff2d9cfbc6799c86447e573c850
5
5
  SHA512:
6
- metadata.gz: 173ffc5a917b502c3dbbce85e399377b9f146e3a52b89974035cd5bf5f51d877df78b4bdfe33b4eaedbb51240d58817df391c304ded6ebcaf2a33e1c43c7a7dd
7
- data.tar.gz: bb2f1d72e564a971ff55809ce5a6ca95ad17a1d1697362d009182b971ae837ff933318d054c582195171fb03ca476e00af7aef43ffebd40f3ce305238ba3d8bd
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.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.2)
42
- mail (2.7.1)
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
- nokogiri (1.13.9-x86_64-linux)
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.2.1)
67
+ parser (3.1.3.0)
55
68
  ast (~> 2.4.1)
56
- public_suffix (5.0.0)
57
- racc (1.6.0)
58
- rack (3.0.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.0)
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.0)
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.0)
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.39.0)
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.23.0)
99
+ rubocop-ast (1.24.0)
87
100
  parser (>= 3.1.1.0)
88
101
  ruby-progressbar (1.11.0)
89
- savon (2.13.1)
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)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ruby
4
4
  module Vies
5
- VERSION = "2.0.0"
5
+ VERSION = "2.0.1"
6
6
  end
7
7
  end
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 'active_support/isolated_execution_state'
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: "https://ec.europa.eu/taxation_customs/vies/checkVatService.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 = "https://api.avis-situation-sirene.insee.fr/identification/siren/#{args.fetch(:vat_number)}"
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.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-14 00:00:00.000000000 Z
11
+ date: 2022-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: finest-builder