ruby_universign 1.3.1 → 1.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6cb709339136cbd0245b7d798db80c7107c11bba63390dcfbd602d4f1c69e03c
4
- data.tar.gz: 14eb0891dee9adc855633c65cbd011ff01d9afc7e4ce639ee840ac3e25d02433
3
+ metadata.gz: 9b39566328cf7e2edb2c55e4c22139129f91adb7cdfeb5120d5c7f40b98b73db
4
+ data.tar.gz: b87ec0c9ad5888959c2e42f2d16425777da5d68aae108e5970a498fef4345416
5
5
  SHA512:
6
- metadata.gz: 506698f5430b9d49ec75a69f46351c926fcba8d5d62e5c4af2869dec95e4bcbf55a1670ecb761a4613813b4a552830deb4f7adaf1dc9b0b543eb0c4efdd77468
7
- data.tar.gz: 87b9d900f92c102ce365d3b71c2a2e21c81ad3ad03dcefab8ccd17695fa561c9cbd642684d7e53f426cc4ef6fdca4b61b5dd0dd535e8e46a3d6144b1f9bc09ac
6
+ metadata.gz: 973c59f15e06122b52d812ec50bcbeb993db6b145f8435aedca5c72f33bdd0f0bbb13d5308460fc51bb9f4079dd6c7073e8a6728020ded5257502918bd69498c
7
+ data.tar.gz: acd708d77ab30e7dc2f5b6645ced38f2e4c9210fed1041fe7e809d58b16abd186b65fd487b5fa0a1ce8f9d071eac817fbd76369e1b62c95c624e31442320640b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ v1.4.0
2
+ -------------------------
3
+ - Refactor and rename errors. They now all inherit from `Universign::Error`.
4
+
1
5
  v1.3.1
2
6
  -------------------------
3
7
 
data/lib/universign.rb CHANGED
@@ -10,11 +10,10 @@ require 'universign/transaction'
10
10
  require 'universign/signature_field'
11
11
  require 'universign/signer_infos'
12
12
  require 'universign/transaction_signer'
13
+ require 'universign/error'
13
14
  require 'universign/client'
14
15
  require 'universign/document'
15
16
  require 'universign/configuration'
16
- require 'universign/error'
17
17
 
18
18
  module Universign
19
- include Error
20
19
  end
@@ -22,15 +22,5 @@ module Universign
22
22
  super(method, *args, &block)
23
23
  end
24
24
  end
25
-
26
- # _ _
27
- # _____ _____ ___ _ __ | |_(_) ___ _ __ ___
28
- # / _ \ \/ / __/ _ \ '_ \| __| |/ _ \| '_ \/ __|
29
- # | __/> < (_| __/ |_) | |_| | (_) | | | \__ \
30
- # \___/_/\_\___\___| .__/ \__|_|\___/|_| |_|___/
31
- # |_|
32
- class InvalidCredentials < StandardError; end
33
- class ErrorWhenSigningPDF < StandardError; end
34
- class UnknownException < StandardError; end
35
25
  end
36
26
  end
@@ -103,27 +103,5 @@ module Universign
103
103
  @meta_data = data
104
104
  params['metaData'] = data
105
105
  end
106
-
107
- # _ _
108
- # _____ _____ ___ _ __ | |_(_) ___ _ __ ___
109
- # / _ \ \/ / __/ _ \ '_ \| __| |/ _ \| '_ \/ __|
110
- # | __/> < (_| __/ |_) | |_| | (_) | | | \__ \
111
- # \___/_/\_\___\___| .__/ \__|_|\___/|_| |_|___/
112
- # |_|
113
- class UnknownDocument < StandardError; end
114
- class NotSigned < StandardError; end
115
- class MissingDocument < StandardError; end
116
- class MetaDataMustBeAHash < StandardError; end
117
- class DocumentURLInvalid < StandardError
118
- attr_accessor :url
119
-
120
- def initialize(url)
121
- @url = url
122
- end
123
-
124
- def to_s
125
- "Can't find document at '#{@url}''"
126
- end
127
- end
128
106
  end
129
107
  end
@@ -1,14 +1,34 @@
1
1
  module Universign
2
- module Error
3
- autoload :Client, 'client'
4
- ERROR_CODE = {
5
- 73002 => Universign::Client::ErrorWhenSigningPDF, # An error occured when signing the PDF document
6
- 73010 => Universign::Client::InvalidCredentials, # The login and/or password are invalid.
7
- 73025 => Universign::Document::UnknownDocument, # The used transaction id or custom id is invalid
8
- 73027 => Universign::Document::NotSigned
9
- }
10
-
11
- class UniversignError < StandardError; end
12
- class NotEnoughTokens < UniversignError; end
2
+ class Error < ::StandardError
3
+ def self.match_class(code)
4
+ {
5
+ 73002 => Universign::ErrorWhenSigningPDF, # An error occured when signing the PDF document
6
+ 73010 => Universign::InvalidCredentials, # The login and/or password are invalid.
7
+ 73025 => Universign::UnknownDocument, # The used transaction id or custom id is invalid
8
+ 73027 => Universign::DocumentNotSigned
9
+ }.fetch(code, nil)
10
+ end
11
+ end
12
+
13
+ class NotEnoughTokens < Error; end
14
+
15
+ class ErrorWhenSigningPDF < Error; end
16
+ class InvalidCredentials < Error; end
17
+ class UnknownException < Error; end
18
+
19
+ class UnknownDocument < Error; end
20
+ class DocumentNotSigned < Error; end
21
+ class MissingDocument < Error; end
22
+ class MetaDataMustBeAHash < Error; end
23
+ class DocumentURLInvalid < Error
24
+ attr_accessor :url
25
+
26
+ def initialize(url)
27
+ @url = url
28
+ end
29
+
30
+ def to_s
31
+ "Can't find document at '#{@url}'"
32
+ end
13
33
  end
14
34
  end
@@ -16,27 +16,27 @@ module Universign
16
16
  raise ex
17
17
  end
18
18
 
19
- known_exception = Universign::ERROR_CODE[ex.faultCode]
19
+ known_exception = Universign::Error.match_class(ex.faultCode)
20
20
 
21
21
  if known_exception
22
22
  raise known_exception
23
23
  elsif ex.faultString.include?('Error on document download for this URL')
24
24
  url = ex.faultString.match(/<(.+)>/)[1] rescue 'unknown URL'
25
- raise Universign::Document::DocumentURLInvalid.new(url)
25
+ raise Universign::DocumentURLInvalid.new(url)
26
26
  elsif ex.faultString.include?('Invalid document URL')
27
27
  url = ex.faultString.match(/<(.+)>/)[1] rescue 'unknown URL'
28
- raise Universign::Document::DocumentURLInvalid.new(url)
28
+ raise Universign::DocumentURLInvalid.new(url)
29
29
  elsif ex.faultString.include?('Not enough tokens')
30
30
  raise Universign::NotEnoughTokens
31
31
  elsif ex.faultString.include?('ID is unknown')
32
- raise Universign::Document::UnknownDocument
32
+ raise Universign::UnknownDocument
33
33
  else
34
34
  handle_exception(ex, callback)
35
35
  end
36
36
 
37
37
  rescue RuntimeError => ex
38
38
  if ex.message.include?('Authorization failed')
39
- raise Universign::Client::InvalidCredentials
39
+ raise Universign::InvalidCredentials
40
40
  end
41
41
  raise ex
42
42
  end
@@ -1,3 +1,3 @@
1
1
  module Universign
2
- VERSION = "1.3.1"
2
+ VERSION = "1.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_universign
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Besnard
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-11-12 00:00:00.000000000 Z
13
+ date: 2021-02-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport