ruby-vies 2.0.0 → 3.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: ab9ed1bf496e498fe99493e190f49f4028ad48f9cfcacccd8b645bf86895d5fa
4
+ data.tar.gz: e70ba42691232c29181936fc770ca94434690ace2c0354024353e36c27b0cccd
5
5
  SHA512:
6
- metadata.gz: 173ffc5a917b502c3dbbce85e399377b9f146e3a52b89974035cd5bf5f51d877df78b4bdfe33b4eaedbb51240d58817df391c304ded6ebcaf2a33e1c43c7a7dd
7
- data.tar.gz: bb2f1d72e564a971ff55809ce5a6ca95ad17a1d1697362d009182b971ae837ff933318d054c582195171fb03ca476e00af7aef43ffebd40f3ce305238ba3d8bd
6
+ metadata.gz: f4aca22b25c5fe0661879ab1bc98d2f4ba8dc6cd0a92d427ac4cd09755263915d480abdfab16ac9429fc5f0a21d530f2aa10935f6bcc14abb6a3eb72bc70b1e2
7
+ data.tar.gz: 42c9b06c452d45e24251b085773f4b6243deed28846dfba869d2a43667d7c51e1b2280ebe5e19d7d3a52d47317be6ca95582d878b2645a2cf02718c03b7640b8
data/.idea/ruby-vies.iml CHANGED
@@ -16,82 +16,51 @@
16
16
  <orderEntry type="library" scope="PROVIDED" name="akami (v1.3.1, rbenv: 3.1.2) [gem]" level="application" />
17
17
  <orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, rbenv: 3.1.2) [gem]" level="application" />
18
18
  <orderEntry type="library" scope="PROVIDED" name="builder (v3.2.4, rbenv: 3.1.2) [gem]" level="application" />
19
- <orderEntry type="library" scope="PROVIDED" name="bundler (v2.2.24, rbenv: 3.1.2) [gem]" level="application" />
20
19
  <orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.10, rbenv: 3.1.2) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="date (v3.3.3, rbenv: 3.1.2) [gem]" level="application" />
21
21
  <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.5.0, rbenv: 3.1.2) [gem]" level="application" />
22
22
  <orderEntry type="library" scope="PROVIDED" name="finest-builder (v2.0.0, rbenv: 3.1.2) [gem]" level="application" />
23
23
  <orderEntry type="library" scope="PROVIDED" name="gyoku (v1.4.0, rbenv: 3.1.2) [gem]" level="application" />
24
24
  <orderEntry type="library" scope="PROVIDED" name="httparty (v0.20.0, rbenv: 3.1.2) [gem]" level="application" />
25
25
  <orderEntry type="library" scope="PROVIDED" name="httpi (v3.0.1, rbenv: 3.1.2) [gem]" level="application" />
26
26
  <orderEntry type="library" scope="PROVIDED" name="i18n (v1.12.0, rbenv: 3.1.2) [gem]" level="application" />
27
- <orderEntry type="library" scope="PROVIDED" name="json (v2.6.2, rbenv: 3.1.2) [gem]" level="application" />
28
- <orderEntry type="library" scope="PROVIDED" name="mail (v2.7.1, rbenv: 3.1.2) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="json (v2.6.3, rbenv: 3.1.2) [gem]" level="application" />
28
+ <orderEntry type="library" scope="PROVIDED" name="mail (v2.8.0, rbenv: 3.1.2) [gem]" level="application" />
29
29
  <orderEntry type="library" scope="PROVIDED" name="mime-types (v3.4.1, rbenv: 3.1.2) [gem]" level="application" />
30
30
  <orderEntry type="library" scope="PROVIDED" name="mime-types-data (v3.2022.0105, rbenv: 3.1.2) [gem]" level="application" />
31
31
  <orderEntry type="library" scope="PROVIDED" name="mini_mime (v1.1.2, rbenv: 3.1.2) [gem]" level="application" />
32
32
  <orderEntry type="library" scope="PROVIDED" name="minitest (v5.16.3, rbenv: 3.1.2) [gem]" level="application" />
33
33
  <orderEntry type="library" scope="PROVIDED" name="multi_xml (v0.6.0, rbenv: 3.1.2) [gem]" level="application" />
34
- <orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.13.9, rbenv: 3.1.2) [gem]" level="application" />
34
+ <orderEntry type="library" scope="PROVIDED" name="net-imap (v0.3.4, rbenv: 3.1.2) [gem]" level="application" />
35
+ <orderEntry type="library" scope="PROVIDED" name="net-pop (v0.1.2, rbenv: 3.1.2) [gem]" level="application" />
36
+ <orderEntry type="library" scope="PROVIDED" name="net-protocol (v0.2.1, rbenv: 3.1.2) [gem]" level="application" />
37
+ <orderEntry type="library" scope="PROVIDED" name="net-smtp (v0.3.3, rbenv: 3.1.2) [gem]" level="application" />
38
+ <orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.13.10, rbenv: 3.1.2) [gem]" level="application" />
35
39
  <orderEntry type="library" scope="PROVIDED" name="nori (v2.6.0, rbenv: 3.1.2) [gem]" level="application" />
36
40
  <orderEntry type="library" scope="PROVIDED" name="parallel (v1.22.1, rbenv: 3.1.2) [gem]" level="application" />
37
- <orderEntry type="library" scope="PROVIDED" name="parser (v3.1.2.1, rbenv: 3.1.2) [gem]" level="application" />
38
- <orderEntry type="library" scope="PROVIDED" name="public_suffix (v5.0.0, rbenv: 3.1.2) [gem]" level="application" />
39
- <orderEntry type="library" scope="PROVIDED" name="racc (v1.6.0, rbenv: 3.1.2) [gem]" level="application" />
40
- <orderEntry type="library" scope="PROVIDED" name="rack (v3.0.0, rbenv: 3.1.2) [gem]" level="application" />
41
+ <orderEntry type="library" scope="PROVIDED" name="parser (v3.1.3.0, rbenv: 3.1.2) [gem]" level="application" />
42
+ <orderEntry type="library" scope="PROVIDED" name="public_suffix (v5.0.1, rbenv: 3.1.2) [gem]" level="application" />
43
+ <orderEntry type="library" scope="PROVIDED" name="racc (v1.6.2, rbenv: 3.1.2) [gem]" level="application" />
41
44
  <orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, rbenv: 3.1.2) [gem]" level="application" />
42
45
  <orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, rbenv: 3.1.2) [gem]" level="application" />
43
- <orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.6.0, rbenv: 3.1.2) [gem]" level="application" />
46
+ <orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.6.1, rbenv: 3.1.2) [gem]" level="application" />
44
47
  <orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.5, rbenv: 3.1.2) [gem]" level="application" />
45
48
  <orderEntry type="library" scope="PROVIDED" name="rspec (v3.12.0, rbenv: 3.1.2) [gem]" level="application" />
46
49
  <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.12.0, rbenv: 3.1.2) [gem]" level="application" />
47
- <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.12.0, rbenv: 3.1.2) [gem]" level="application" />
48
- <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.12.0, rbenv: 3.1.2) [gem]" level="application" />
50
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.12.1, rbenv: 3.1.2) [gem]" level="application" />
51
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.12.1, rbenv: 3.1.2) [gem]" level="application" />
49
52
  <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.12.0, rbenv: 3.1.2) [gem]" level="application" />
50
- <orderEntry type="library" scope="PROVIDED" name="rubocop (v1.39.0, rbenv: 3.1.2) [gem]" level="application" />
51
- <orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.23.0, rbenv: 3.1.2) [gem]" level="application" />
53
+ <orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.24.0, rbenv: 3.1.2) [gem]" level="application" />
52
54
  <orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.11.0, rbenv: 3.1.2) [gem]" level="application" />
53
- <orderEntry type="library" scope="PROVIDED" name="savon (v2.13.1, rbenv: 3.1.2) [gem]" level="application" />
55
+ <orderEntry type="library" scope="PROVIDED" name="savon (v2.14.0, rbenv: 3.1.2) [gem]" level="application" />
56
+ <orderEntry type="library" scope="PROVIDED" name="timeout (v0.3.1, rbenv: 3.1.2) [gem]" level="application" />
54
57
  <orderEntry type="library" scope="PROVIDED" name="tzinfo (v2.0.5, rbenv: 3.1.2) [gem]" level="application" />
55
58
  <orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.3.0, rbenv: 3.1.2) [gem]" level="application" />
56
59
  <orderEntry type="library" scope="PROVIDED" name="wasabi (v3.8.0, rbenv: 3.1.2) [gem]" level="application" />
57
60
  </component>
58
61
  <component name="RakeTasksCache">
59
62
  <option name="myRootTask">
60
- <RakeTaskImpl id="rake">
61
- <subtasks>
62
- <RakeTaskImpl description="Build ruby-vies-0.1.0.gem into the pkg directory" fullCommand="build" id="build" />
63
- <RakeTaskImpl id="build">
64
- <subtasks>
65
- <RakeTaskImpl description="Generate SHA512 checksum if ruby-vies-0.1.0.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
66
- </subtasks>
67
- </RakeTaskImpl>
68
- <RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
69
- <RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
70
- <RakeTaskImpl description="Build and install ruby-vies-0.1.0.gem into system gems" fullCommand="install" id="install" />
71
- <RakeTaskImpl id="install">
72
- <subtasks>
73
- <RakeTaskImpl description="Build and install ruby-vies-0.1.0.gem into system gems without network access" fullCommand="install:local" id="local" />
74
- </subtasks>
75
- </RakeTaskImpl>
76
- <RakeTaskImpl description="Create tag v0.1.0 and build and push ruby-vies-0.1.0.gem to TODO: Set to 'https://mygemserver.com'" fullCommand="release[remote]" id="release[remote]" />
77
- <RakeTaskImpl description="Run RuboCop" fullCommand="rubocop" id="rubocop" />
78
- <RakeTaskImpl id="rubocop">
79
- <subtasks>
80
- <RakeTaskImpl description="Auto-correct RuboCop offenses" fullCommand="rubocop:auto_correct" id="auto_correct" />
81
- </subtasks>
82
- </RakeTaskImpl>
83
- <RakeTaskImpl description="Run RSpec code examples" fullCommand="spec" id="spec" />
84
- <RakeTaskImpl description="" fullCommand="default" id="default" />
85
- <RakeTaskImpl description="" fullCommand="release" id="release" />
86
- <RakeTaskImpl id="release">
87
- <subtasks>
88
- <RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
89
- <RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
90
- <RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
91
- </subtasks>
92
- </RakeTaskImpl>
93
- </subtasks>
94
- </RakeTaskImpl>
63
+ <RakeTaskImpl id="rake" />
95
64
  </option>
96
65
  </component>
97
66
  </module>
data/Gemfile.lock CHANGED
@@ -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 = "3.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,19 @@ module Ruby
12
13
  module Vies
13
14
  class Error < StandardError; end
14
15
 
16
+ mattr_accessor :endpoints, default: {
17
+ siren: "https://api.insee.fr/entreprises/sirene/siren/%<siren>s",
18
+ siren_token: "https://api.insee.fr/token?grant_type=client_credentials&client_id=%<id>s&client_secret=%<secret>s&validity_period=%<period>s",
19
+ vat: "https://ec.europa.eu/taxation_customs/vies/services/checkVatService.wsdl"
20
+ }
21
+ mattr_accessor :customer_key, default: ENV["SIREN_CUSTOMER_KEY"]
22
+ mattr_accessor :customer_secret, default: ENV["SIREN_CUSTOMER_SECRET"]
23
+
24
+ # Setup data from initializer
25
+ def self.setup
26
+ yield(self)
27
+ end
28
+
15
29
  class Client
16
30
  include Savon
17
31
  include HTTParty
@@ -19,30 +33,30 @@ module Ruby
19
33
 
20
34
  mattr_reader :id_numbers, default: { FR: "((12 + 3 * ( %d.divmod(97)[1])).divmod(97)[1])" }
21
35
 
22
- def initialize(args = {})
23
- super args
36
+ def initialize(args = nil)
37
+ super args || {}
24
38
  end
25
39
 
26
- def check_vat_details(args = {})
27
- args[:country_code].upcase == "FR" ? check_siren(args) : check_vat(args)
28
- rescue => e
40
+ def check_vat_details(args)
41
+ (args[:country_code].upcase == "FR" ? check_siren(args) : check_vat(args)).with_indifferent_access
42
+ rescue StandardError => e
29
43
  { error: e&.message, valid: false }
30
44
  end
31
45
 
32
46
  protected
33
47
 
34
- def generate_id(vat = {})
48
+ def generate_id(vat)
35
49
  id_numbers[vat[:country_code].to_sym] &&
36
50
  "%02<digit>d%<vat>d" % {
37
51
  digit: eval(id_numbers[vat[:country_code].to_sym] % vat[:vat_number]),
38
52
  vat: vat[:vat_number]
39
53
  } || vat[:vat_number]
40
- rescue
54
+ rescue StandardError
41
55
  vat[:vat_number]
42
56
  end
43
57
 
44
- def check_vat(args = {})
45
- Savon::Client.new(wsdl: "https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl")
58
+ def check_vat(args)
59
+ Savon::Client.new(wsdl: Ruby::Vies.endpoints[:vat])
46
60
  .call(
47
61
  :check_vat,
48
62
  message: args.merge({ vat_number: generate_id(args) }).as_json.transform_keys! { |i| i.camelize(:lower) },
@@ -50,22 +64,43 @@ module Ruby
50
64
  ).body[:check_vat_response].as_json(except: :@xmlns)
51
65
  end
52
66
 
53
- def check_siren(args = {})
54
- url = "https://api.avis-situation-sirene.insee.fr/identification/siren/#{args.fetch(:vat_number)}"
55
- if (resp = JSON.parse(self.class.method(:get).call(url).body))["code"]
56
- { error: resp["message"], valid: false }
67
+ def check_siren(args)
68
+ url = Ruby::Vies.endpoints[:siren] % { siren: args.fetch(:vat_number) }
69
+ if (
70
+ resp = JSON.parse(
71
+ self.class.method(:get).call(
72
+ url,
73
+ headers: {
74
+ authorization: "Bearer #{siren_token}",
75
+ 'Content-Type': 'application/json'
76
+ }
77
+ ).body
78
+ )
79
+ ).dig("header", "statut") != 200
80
+ { error: resp["header"]["message"], valid: false }
57
81
  else
58
82
  {
59
83
  valid: true,
60
84
  name: resp.dig("uniteLegale", "periodesUniteLegale")&.first&.dig("denominationUniteLegale"),
61
- address: resp.dig("etablissements")&.first&.dig("adresseEtablissement").values.join(" "),
62
- siren: resp.dig("etablissements")&.first&.dig("siren"),
63
- siret: resp.dig("etablissements")&.first&.dig("siret"),
64
- nic: resp.dig("etablissements")&.first&.dig("nic"),
65
- created: resp.dig("etablissements")&.first&.dig("dateCreationEtablissement")
85
+ address: "",
86
+ siren: resp.dig("uniteLegale", "siren"),
87
+ siret: "",
88
+ nic: resp.dig("uniteLegale", "periodesUniteLegale")&.first&.dig("nicSiegeUniteLegale"),
89
+ created: resp.dig("uniteLegale", "periodesUniteLegale")&.first&.dig("dateDebut"),
66
90
  }
67
91
  end
92
+ end
93
+
94
+ private
68
95
 
96
+ def siren_token
97
+ url = Ruby::Vies.endpoints[:siren_token] % {
98
+ id: Ruby::Vies.customer_key,
99
+ secret: Ruby::Vies.customer_secret,
100
+ period: 604800
101
+ }
102
+ resp = self.class.method(:post).call(url)
103
+ JSON.parse(resp.body)["access_token"]
69
104
  end
70
105
  end
71
106
  end
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: 3.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: 2023-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: finest-builder