ruby_universign 1.2.0 → 1.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a826c0040b24885ccbde5486f9fcc16a582ced8fd0e37b2c363836d69bff16d2
4
- data.tar.gz: 2fe254d5364b8b085082cf1bd2b57b3c51a6d19ffbd6947af4d7e8a067abdcbd
3
+ metadata.gz: b7f7b34b6f2e64791dbf6910f67dc2d39fda890db4e90c0c6e20a3516a50b26e
4
+ data.tar.gz: 24b47db3af2b7dd0a644649e80fc61880e06ef546909c2479d0c3b93fac7aa66
5
5
  SHA512:
6
- metadata.gz: 6ef9c2d6c3df55be722c2cc113a04dfa6d5114ffba6d6814ac2c054d982666ea9838807eea9918c46937228768e83b95b025339364a1c2c8637da2e044485826
7
- data.tar.gz: 7c7655992acb0e7983b09cd1931ab184b6c9d1a1979b30513005a18f6f6bb731af14f0f9623e8fe38aa98530255ad9900d4c20bd4621c0728da01384d2bac7e9
6
+ metadata.gz: b868fd44745e5fc5671f17977249d538a406de57c04219448eec046f7f053c5325bfdaa78ca70e0c8f4fd67fb1bcda738590725f01ba692e207ac4b0c80794d4
7
+ data.tar.gz: 6a7fbc730e6687ad99fb528f638cc3b43121f5728229b634065545fedff9bc111ed487f06f71d10fbc448173e46eb77856d8363376d4e3a6d40a99af2b89e7a4
data/.gitignore CHANGED
@@ -8,4 +8,6 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .env
11
- .idea
11
+ .idea
12
+ *.swp
13
+ *.swo
data/CHANGELOG.md CHANGED
@@ -1,3 +1,30 @@
1
+ v1.5.1
2
+ -------------------------
3
+ - Fix bugs on multi-threads requests.
4
+
5
+ v1.5.0
6
+ -------------------------
7
+ - Add `xmlrpc` as dependency, and raise required ruby version to 2.3.
8
+
9
+ v1.4.0
10
+ -------------------------
11
+ - Refactor and rename errors. They now all inherit from `Universign::Error`.
12
+
13
+ v1.3.1
14
+ -------------------------
15
+
16
+ - Fixing regressions added
17
+
18
+ v1.3.0 - NOT WORKING
19
+ -------------------------
20
+
21
+ - Adding the possibility to configure proxy and timeout options for the XMLRPC Client
22
+
23
+ v1.2.1
24
+ -------------------------
25
+
26
+ - Bumping rake development dependancy due to security issues
27
+
1
28
  v1.2.0
2
29
  -------------------------
3
30
 
data/README.md CHANGED
@@ -38,9 +38,11 @@ Configuration:
38
38
  ```ruby
39
39
  # if you're using Rails, put this in an initializer
40
40
  Universign.configure do |config|
41
- config.endpoint = ENV['UNIVERSIGN_ENDPOINT']
42
- config.login = ENV['UNIVERSIGN_LOGIN']
43
- config.password = ENV['UNIVERSIGN_PASSWORD']
41
+ config.endpoint = 'your_universign_endpoint' # Required ...
42
+ config.login = 'your_login' # Required ...
43
+ config.password = 'your_password' # Required ...
44
+ config.proxy = 'your_proxy_uri:your_proxy_port' # Optionnal ...
45
+ config.timeout = 30 # Optionnal if you wanna change the default XMLRPC Timeout ...
44
46
  end
45
47
  ```
46
48
 
@@ -57,12 +59,12 @@ document_from_content = Universign::Document.new(
57
59
  )
58
60
 
59
61
  signer = Universign::TransactionSigner.new(
60
- first_name: "Signer's first name",
61
- last_name: "Signer's last name",
62
- email: 'test@gmail.com',
63
- phone_number: '0101010101',
64
- success_url: 'https://google.com/',
65
- signature: Universign::SignatureField.new(coordinate: [20, 20], page: 1)
62
+ first_name: "Signer's first name",
63
+ last_name: "Signer's last name",
64
+ email: 'test@gmail.com',
65
+ phone_number: '0101010101',
66
+ success_url: 'https://google.com/',
67
+ signature_field: Universign::SignatureField.new(coordinate: [20, 20], page: 1)
66
68
  )
67
69
 
68
70
  transaction = Universign::Transaction.create(
@@ -83,6 +85,33 @@ transaction = Universign::Transaction.new('9696179e-a43d-4803-beeb-9e5c02fd159b'
83
85
  transaction.signed?
84
86
  ```
85
87
 
88
+ The gem also supports the updated way of creating multiple signature fields per document:
89
+
90
+ ```ruby
91
+ doc_1 = Universign::Document.new(
92
+ name: 'one.pdf',
93
+ content: File.open('spec/fixtures/universign-guide-8.8.pdf').read,
94
+ signature_fields: [
95
+ Universign::SignatureField.new(coordinate: [20, 20], page: 1, signer_index: 0),
96
+ Universign::SignatureField.new(coordinate: [80, 20], page: 1, signer_index: 0)
97
+ ]
98
+ )
99
+
100
+ doc_2 = Universign::Document.new(
101
+ name: 'two.pdf',
102
+ content: File.open('spec/fixtures/universign-guide-8.8.pdf').read,
103
+ signature_fields: [
104
+ Universign::SignatureField.new(coordinate: [100, 120], page: 4, signer_index: 0),
105
+ ]
106
+ )
107
+
108
+ transaction = Universign::Transaction.create(
109
+ documents: [doc_1, doc_2],
110
+ signers: [signer],
111
+ options: { profile: 'default', final_doc_sent: true }
112
+ )
113
+ ```
114
+
86
115
  ### `Universign::Document`
87
116
 
88
117
  It can be created with either your file's content or your file's url.
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
@@ -2,11 +2,14 @@ require 'singleton'
2
2
 
3
3
  module Universign
4
4
  class Client
5
- include ::Singleton
6
5
  attr_reader :client
7
6
 
8
7
  def initialize
9
- @client = XMLRPC::Client.new2(Universign.configuration.endpoint)
8
+ @client = XMLRPC::Client.new2(
9
+ Universign.configuration.endpoint,
10
+ Universign.configuration.proxy,
11
+ Universign.configuration.timeout
12
+ )
10
13
  @client.user = Universign.configuration.login
11
14
  @client.password = Universign.configuration.password
12
15
  end
@@ -18,15 +21,5 @@ module Universign
18
21
  super(method, *args, &block)
19
22
  end
20
23
  end
21
-
22
- # _ _
23
- # _____ _____ ___ _ __ | |_(_) ___ _ __ ___
24
- # / _ \ \/ / __/ _ \ '_ \| __| |/ _ \| '_ \/ __|
25
- # | __/> < (_| __/ |_) | |_| | (_) | | | \__ \
26
- # \___/_/\_\___\___| .__/ \__|_|\___/|_| |_|___/
27
- # |_|
28
- class InvalidCredentials < StandardError; end
29
- class ErrorWhenSigningPDF < StandardError; end
30
- class UnknownException < StandardError; end
31
24
  end
32
25
  end
@@ -1,11 +1,13 @@
1
1
  module Universign
2
2
  class Configuration
3
- attr_accessor :login, :password, :endpoint
3
+ attr_accessor :login, :password, :endpoint, :proxy, :timeout
4
4
 
5
5
  def initialize
6
- @login = ''
7
- @password = ''
8
- @endpoint = ''
6
+ @login = nil
7
+ @password = nil
8
+ @endpoint = nil
9
+ @proxy = nil
10
+ @timeout = nil
9
11
  end
10
12
  end
11
13
 
@@ -75,6 +75,19 @@ module Universign
75
75
  params['name'] = data
76
76
  end
77
77
 
78
+ def signature_fields=(data)
79
+ if !data.is_a?(Array)
80
+ raise 'SignatureFieldsMustBeAnArray'
81
+ end
82
+
83
+ @signature_fields = data
84
+ params['signatureFields'] = data.map do |d|
85
+ raise 'BadSignatureFieldType' unless d.instance_of?(SignatureField)
86
+
87
+ d.params
88
+ end
89
+ end
90
+
78
91
  # The meta data of the PDF document
79
92
  #
80
93
  # @return [Hash]
@@ -90,27 +103,5 @@ module Universign
90
103
  @meta_data = data
91
104
  params['metaData'] = data
92
105
  end
93
-
94
- # _ _
95
- # _____ _____ ___ _ __ | |_(_) ___ _ __ ___
96
- # / _ \ \/ / __/ _ \ '_ \| __| |/ _ \| '_ \/ __|
97
- # | __/> < (_| __/ |_) | |_| | (_) | | | \__ \
98
- # \___/_/\_\___\___| .__/ \__|_|\___/|_| |_|___/
99
- # |_|
100
- class UnknownDocument < StandardError; end
101
- class NotSigned < StandardError; end
102
- class MissingDocument < StandardError; end
103
- class MetaDataMustBeAHash < StandardError; end
104
- class DocumentURLInvalid < StandardError
105
- attr_accessor :url
106
-
107
- def initialize(url)
108
- @url = url
109
- end
110
-
111
- def to_s
112
- "Can't find document at '#{@url}''"
113
- end
114
- end
115
106
  end
116
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
@@ -5,7 +5,7 @@ module Universign
5
5
  #
6
6
  # @return [Array<Universign::Document>]
7
7
  def documents
8
- @client = Universign::Client.instance
8
+ @client = Universign::Client.new
9
9
 
10
10
  @documents ||= safeguard do
11
11
  result = @client.call('requester.getDocuments', @transaction_id)
@@ -26,7 +26,7 @@ module Universign
26
26
  #
27
27
  # @return [Universign::Transaction]
28
28
  def get
29
- @client = Universign::Client.instance
29
+ @client = Universign::Client.new
30
30
 
31
31
  safeguard do
32
32
  result = @client.call('requester.getTransactionInfo', @transaction_id)
@@ -59,7 +59,7 @@ module Universign
59
59
  #
60
60
  # @return [Universign::Transaction]
61
61
  def create(documents:, signers:, options: {})
62
- @client = Universign::Client.instance
62
+ @client = Universign::Client.new
63
63
 
64
64
  sign_options = DEFAULT_OPTIONS.merge(
65
65
  documents: documents.map(&:params),
@@ -2,15 +2,17 @@ module Universign
2
2
  class SignatureField
3
3
  attr_reader :params
4
4
 
5
- def initialize(coordinate:, name: nil, page:)
5
+ def initialize(coordinate:, name: nil, page:, signer_index: 0)
6
6
  @coordinate = coordinate || [0, 0]
7
7
  @name = name
8
8
  @page = page
9
+ @signer_index = signer_index
9
10
 
10
11
  @params = {
11
- page: @page,
12
- x: @coordinate[0],
13
- y: @coordinate[1]
12
+ page: @page,
13
+ x: @coordinate[0],
14
+ y: @coordinate[1],
15
+ 'signerIndex': @signer_index
14
16
  }
15
17
 
16
18
  @params[:name] = @name unless @name.nil?
@@ -95,7 +95,7 @@ module Universign
95
95
  private
96
96
 
97
97
  def client
98
- @client ||= Universign::Client.new.client
98
+ Universign::Client.new.client
99
99
  end
100
100
  end
101
101
  end
@@ -1,3 +1,3 @@
1
1
  module Universign
2
- VERSION = "1.2.0"
2
+ VERSION = "1.5.1"
3
3
  end
@@ -23,12 +23,13 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ["lib"]
25
25
 
26
- spec.required_ruby_version = '>= 2.0'
26
+ spec.required_ruby_version = '>= 2.3'
27
27
 
28
28
  spec.add_runtime_dependency 'activesupport', '>= 4.1'
29
+ spec.add_runtime_dependency "xmlrpc"
29
30
 
30
- spec.add_development_dependency "bundler", "~> 1.10"
31
- spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "bundler", ">= 1.10"
32
+ spec.add_development_dependency "rake", ">= 12.3.3"
32
33
  spec.add_development_dependency "rspec", "~> 3.0"
33
34
  spec.add_development_dependency "dotenv", "~> 2.0"
34
35
  spec.add_development_dependency "webmock", "~> 3.0"
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.2.0
4
+ version: 1.5.1
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-07-01 00:00:00.000000000 Z
13
+ date: 2021-03-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -26,34 +26,48 @@ dependencies:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  version: '4.1'
29
+ - !ruby/object:Gem::Dependency
30
+ name: xmlrpc
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
29
43
  - !ruby/object:Gem::Dependency
30
44
  name: bundler
31
45
  requirement: !ruby/object:Gem::Requirement
32
46
  requirements:
33
- - - "~>"
47
+ - - ">="
34
48
  - !ruby/object:Gem::Version
35
49
  version: '1.10'
36
50
  type: :development
37
51
  prerelease: false
38
52
  version_requirements: !ruby/object:Gem::Requirement
39
53
  requirements:
40
- - - "~>"
54
+ - - ">="
41
55
  - !ruby/object:Gem::Version
42
56
  version: '1.10'
43
57
  - !ruby/object:Gem::Dependency
44
58
  name: rake
45
59
  requirement: !ruby/object:Gem::Requirement
46
60
  requirements:
47
- - - "~>"
61
+ - - ">="
48
62
  - !ruby/object:Gem::Version
49
- version: '10.0'
63
+ version: 12.3.3
50
64
  type: :development
51
65
  prerelease: false
52
66
  version_requirements: !ruby/object:Gem::Requirement
53
67
  requirements:
54
- - - "~>"
68
+ - - ">="
55
69
  - !ruby/object:Gem::Version
56
- version: '10.0'
70
+ version: 12.3.3
57
71
  - !ruby/object:Gem::Dependency
58
72
  name: rspec
59
73
  requirement: !ruby/object:Gem::Requirement
@@ -161,7 +175,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
161
175
  requirements:
162
176
  - - ">="
163
177
  - !ruby/object:Gem::Version
164
- version: '2.0'
178
+ version: '2.3'
165
179
  required_rubygems_version: !ruby/object:Gem::Requirement
166
180
  requirements:
167
181
  - - ">="