universign 0.2.0 → 0.2.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
  SHA1:
3
- metadata.gz: 37fcda1aff466ea92b52af39d74396b7fbed250a
4
- data.tar.gz: 5043df18c256466473d81a35a9578deccbeffcc5
3
+ metadata.gz: 4a162d62ec1ebc95ac4c719c2bebe7b47f64f7df
4
+ data.tar.gz: bc40b9c1401827933fd9d4223f7d199447929cb1
5
5
  SHA512:
6
- metadata.gz: 79116490f911fabbf5ece6549efdf1c203b3af42f943d39a4e4083700be8ef906ca8485f6f0d01994a10d5c9932461ad56f7c274b9a0620f17178b079d9714b6
7
- data.tar.gz: b51c6c92cdba641ed41c703792b8a731069429268710e9493ec4b860d55b5829fd180ca9482af13a24c1fc0b255caaf524e1b92d3abede29d9b3aa1d2cbd2df2
6
+ metadata.gz: 55c5e8b2e43b16ba960f67d7400b53791123da170f4a81a3611bfdc06557b8ec539a18108251faec05b3ae8a71314f7e5b0e60834a652384f04117e23a23071d
7
+ data.tar.gz: 4b215f199a03f964cfb78118cfc14032de3f723c91f376c83f742253deb41d4d02489c5cb5b4ae562b4c031df206297d949ff1e8382f9167efa6eb068066a50a
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ Documentation:
2
+ Enabled: false
3
+ Style/FirstParameterIndentation:
4
+ IndentationWidth: 4
data/Rakefile CHANGED
@@ -1,6 +1,15 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RuboCop::RakeTask.new(:rubocop) do |task|
6
+ task.patterns = ['Rakefile', 'lib/**/*.rb']
7
+ # only show the files with failures
8
+ # task.formatters = ['files']
9
+ # don't abort rake on failure
10
+ task.fail_on_error = false
11
+ end
3
12
 
4
13
  RSpec::Core::RakeTask.new(:spec)
5
14
 
6
- task :default => :spec
15
+ task default: [:rubocop, :spec]
data/lib/universign.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  # encoding: utf-8
2
2
  require 'universign/version'
3
+ require 'universign/hash'
3
4
  require 'base64'
4
5
  require 'xmlrpc/client'
5
6
 
6
7
  module Universign
7
-
8
8
  class << self
9
9
  attr_accessor :configuration
10
10
  end
@@ -14,6 +14,7 @@ module Universign
14
14
  yield(configuration) if block_given?
15
15
  end
16
16
 
17
+ # Configuration class
17
18
  class Configuration
18
19
  attr_accessor :language, :production, :user, :password, :debug,
19
20
  :profile
@@ -27,79 +28,82 @@ module Universign
27
28
  end
28
29
 
29
30
  module Sign
30
-
31
31
  class << self
32
+ SignerDefaultOptions = { firstname: nil,
33
+ lastname: nil,
34
+ organization: nil,
35
+ profile: 'default',
36
+ emailAddress: nil,
37
+ phoneNum: nil,
38
+ role: 'signer',
39
+ signatureField: nil,
40
+ successURL: nil,
41
+ cancelURL: nil,
42
+ failURL: nil,
43
+ certificateType: 'simple',
44
+ idDocuments: nil
45
+ }.freeze
46
+ SANDBOX_URL = 'sign.test.cryptolog.com'.freeze
47
+ PROD_URL = 'sign.cryptolog.com'.freeze
32
48
 
33
49
  def client
34
- raise 'You need to set config options' if Universign.configuration.nil?
35
- host = Universign.configuration.production ? 'sign.cryptolog.com' : 'sign.test.cryptolog.com'
50
+ fail 'You need to set config options' if Universign.configuration.nil?
51
+ host = Universign.configuration.production ? PROD_URL : SANDBOX_URL
36
52
  path = '/sign/rpc'
37
53
  client = Universign::Sign::Client.new(
38
- host, path, nil, nil, nil, Universign.configuration.user, Universign.configuration.password, true
54
+ host, path, nil, nil, nil,
55
+ Universign.configuration.user,
56
+ Universign.configuration.password, true
39
57
  )
40
58
  client.set_debug if Universign.configuration.debug
41
59
  client
42
60
  end
43
61
 
44
- end
62
+ def transaction_signer(options = {})
63
+ options = options.reverse_merge(SignerDefaultOptions)
64
+ validate_transaction_signer_argument options
65
+ options.reject! { |_, v| v.nil? }
66
+ end
45
67
 
46
- Document = Struct.new(:content, :name)
47
- Signer = Struct.new(
48
- :phoneNum,
49
- :emailAddress,
50
- :firstname,
51
- :lastname,
52
- :successURL,
53
- :failURL,
54
- :cancelURL
55
- )
68
+ def transaction_document(content, name)
69
+ { content: XMLRPC::Base64.new(content), name: name }
70
+ end
56
71
 
57
- def self.transactionSigner(phoneNum, emailAddress, firstname, lastname, successURL, failURL, cancelURL)
58
- Signer.new(phoneNum, emailAddress, firstname, lastname, successURL, failURL, cancelURL)
59
- end
72
+ private
60
73
 
61
- def self.transactionDocument(content, name)
62
- Document.new(XMLRPC::Base64.new(content), name)
74
+ def validate_transaction_signer_argument(options)
75
+ fail(ArgumentError, 'You have to provide a firstname') if
76
+ options[:firstname].empty?
77
+ fail(ArgumentError, 'You have to provide a lastname') if
78
+ options[:lastname].empty?
79
+ fail(ArgumentError, 'You have to provide an email') if
80
+ options[:emailAddress].empty?
81
+ end
63
82
  end
64
83
 
65
84
  class Client < XMLRPC::Client
66
-
67
- RequestTransaction = Struct.new(
68
- :documents,
69
- :signers,
70
- :handwrittenSignatureMode,
71
- :profile,
72
- :certificateType,
73
- :language
74
- )
75
-
76
85
  # Request signature (Client side)
77
- def requestTransaction(transactionSigners, transactionDocuments)
78
- transactionSigners = [transactionSigners] unless transactionSigners.is_a? Array
79
- transactionDocuments = [transactionDocuments] unless transactionDocuments.is_a? Array
80
- request = RequestTransaction.new(
81
- transactionDocuments,
82
- transactionSigners,
83
- 0,
84
- Universign.configuration.profile,
85
- 'simple',
86
- Universign.configuration.language
87
- )
86
+ def request_transaction(signers, docs)
87
+ signers = [signers] unless signers.is_a? Array
88
+ docs = [docs] unless docs.is_a? Array
89
+ request = { documents: docs, signers: signers,
90
+ handwrittenSignatureMode: 0,
91
+ profile: Universign.configuration.profile,
92
+ language: Universign.configuration.language }
88
93
  call('requester.requestTransaction', request)
89
94
  end
90
95
 
91
- def getTransactionInfo(transactionId)
92
- call('requester.getTransactionInfo', transactionId)
96
+ def get_transaction_info(transaction_id)
97
+ call('requester.getTransactionInfo', transaction_id)
93
98
  end
94
99
 
95
- def getDocuments(transactionId)
96
- call('requester.getDocuments', transactionId)
100
+ def get_documents(transaction_id)
101
+ call('requester.getDocuments', transaction_id)
97
102
  end
98
103
 
99
104
  def set_debug
100
- @http.set_debug_output($stderr);
105
+ @http.set_debug_output($stderr)
101
106
  end
102
-
103
107
  end
104
108
  end
105
109
  end
@@ -0,0 +1,7 @@
1
+ class Hash
2
+ unless Hash.respond_to? :reverse_merge
3
+ def reverse_merge(other_hash)
4
+ other_hash.merge(self)
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Universign
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'.freeze
3
3
  end
data/universign.gemspec CHANGED
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency 'bundler', '~> 1.11'
29
29
  spec.add_development_dependency 'rake', '~> 10.0'
30
30
  spec.add_development_dependency 'rspec', '~> 3.0'
31
+ spec.add_development_dependency 'rubocop', '~> 0.36.0'
31
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: universign
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu Foillard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-27 00:00:00.000000000 Z
11
+ date: 2016-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.36.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.36.0
55
69
  description: 'A ruby client for the Universign XML-RPC api. Note : VERY EXPERIMENTAL
56
70
  AND INCOMPLETE'
57
71
  email:
@@ -63,12 +77,14 @@ files:
63
77
  - ".gitignore"
64
78
  - ".rbenv-gemsets"
65
79
  - ".rspec"
80
+ - ".rubocop.yml"
66
81
  - ".travis.yml"
67
82
  - Gemfile
68
83
  - LICENSE.txt
69
84
  - README.md
70
85
  - Rakefile
71
86
  - lib/universign.rb
87
+ - lib/universign/hash.rb
72
88
  - lib/universign/version.rb
73
89
  - universign.gemspec
74
90
  homepage: https://www.github.com/mgtf/universign