clicksign-api 1.0.1 → 1.1.0.alpha4

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: e8ff8453d601e58a20996c73def672b647b21b4d92bf815899524f0111d28562
4
- data.tar.gz: 3cf5d3c4f27010afa57c0048aaed5073bad418fa1d48f94541272dda2d740085
3
+ metadata.gz: 53f37c89406853a22420f28ada42cc02f354aaa0faab9f1250929e324befedfc
4
+ data.tar.gz: d5cebece973a0001692b0a4a32e42ca83e064d973835fcf1263c956b2a7ef40b
5
5
  SHA512:
6
- metadata.gz: 25f5cfb1dbe872a9b6625c81d668877e847e18dc318838666dafbd06eeb0fbfdf827ff153f013b8fec11caf6f97831eea5efed323004e0c34df7cca36a220394
7
- data.tar.gz: 8bb72ea19b6be9a5d99ae135771e93ae4b12b4f95b07637831e9d36a58492ddfbfe180842d6b9dd89ba8a856658033e808f78a24091336a88e229f45b80a732f
6
+ metadata.gz: 26d092f0d08e34ed93d431779dd23b1e35c7797eb9ad0f8db741454a5685e61367fbad28cad36dff459cc6da5754a7eb55a975f912c62f307720af63b5aef2e0
7
+ data.tar.gz: a64f4b516b3377ae7bac49a165969179c6150cfca64e3fb013b2aae8315a72d4c5ddb2119342686e07394e9e7d2f330271b04174772e9fe15f86d51f1866abc9
data/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ # Clicksign::API 1.1.0 (Octuber 29, 2021)
2
+
3
+ Add support to multiple credentials.
4
+ This is useful to work with different environments, providing flexibility.
5
+ For example, applications have different tokens for each environment.
6
+ Other useful case, occurs working with multiple companies.
7
+
8
+ The credentials should be a hash.
9
+ It is possible use a `.yml` file to configure the authentication tokens.
10
+ The `.yml` file can get the tokens using environment variables.
11
+ Now all requests receive token parameter, that represents the key associated with the token.
12
+
13
+ ## Examples:
14
+
15
+ YML file
16
+ ```ruby
17
+ => key.production: ENV['CLICKSIGN_ACCESS_TOKEN_PRODUCTION']
18
+ => key.sandbox: ENV['CLICKSIGN_ACCESS_TOKEN_SANDBOX']
19
+ ```
20
+
21
+ Request:
22
+ ```ruby
23
+ => file = File.open('/path/to/file/local/file.pdf', 'r')
24
+ => response = Clicksign::API::Document.create( params: { path: '/path/to/file/on/clicksign.pdf', file: file }, token: 'key.production')
25
+ ```
data/Gemfile.lock CHANGED
@@ -1,60 +1,85 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clicksign-api (1.0.1)
4
+ clicksign-api (1.1.0.alpha4)
5
5
  faraday
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- addressable (2.5.2)
11
- public_suffix (>= 2.0.2, < 4.0)
10
+ addressable (2.8.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
12
  byebug (10.0.2)
13
- crack (0.4.3)
14
- safe_yaml (~> 1.0.0)
15
- diff-lcs (1.3)
16
- docile (1.3.1)
17
- dotenv (2.5.0)
18
- faraday (0.15.4)
13
+ coderay (1.1.3)
14
+ crack (0.4.5)
15
+ rexml
16
+ diff-lcs (1.4.4)
17
+ docile (1.4.0)
18
+ dotenv (2.7.6)
19
+ faraday (1.8.0)
20
+ faraday-em_http (~> 1.0)
21
+ faraday-em_synchrony (~> 1.0)
22
+ faraday-excon (~> 1.1)
23
+ faraday-httpclient (~> 1.0.1)
24
+ faraday-net_http (~> 1.0)
25
+ faraday-net_http_persistent (~> 1.1)
26
+ faraday-patron (~> 1.0)
27
+ faraday-rack (~> 1.0)
19
28
  multipart-post (>= 1.2, < 3)
20
- hashdiff (0.3.7)
21
- json (2.1.0)
22
- multipart-post (2.0.0)
23
- public_suffix (3.0.3)
24
- rake (13.0.1)
25
- rspec (3.8.0)
26
- rspec-core (~> 3.8.0)
27
- rspec-expectations (~> 3.8.0)
28
- rspec-mocks (~> 3.8.0)
29
- rspec-core (3.8.0)
30
- rspec-support (~> 3.8.0)
31
- rspec-expectations (3.8.2)
29
+ ruby2_keywords (>= 0.0.4)
30
+ faraday-em_http (1.0.0)
31
+ faraday-em_synchrony (1.0.0)
32
+ faraday-excon (1.1.0)
33
+ faraday-httpclient (1.0.1)
34
+ faraday-net_http (1.0.1)
35
+ faraday-net_http_persistent (1.2.0)
36
+ faraday-patron (1.0.0)
37
+ faraday-rack (1.0.0)
38
+ hashdiff (1.0.1)
39
+ method_source (1.0.0)
40
+ multipart-post (2.1.1)
41
+ pry (0.14.1)
42
+ coderay (~> 1.1)
43
+ method_source (~> 1.0)
44
+ public_suffix (4.0.6)
45
+ rake (13.0.6)
46
+ rexml (3.2.5)
47
+ rspec (3.10.0)
48
+ rspec-core (~> 3.10.0)
49
+ rspec-expectations (~> 3.10.0)
50
+ rspec-mocks (~> 3.10.0)
51
+ rspec-core (3.10.1)
52
+ rspec-support (~> 3.10.0)
53
+ rspec-expectations (3.10.1)
32
54
  diff-lcs (>= 1.2.0, < 2.0)
33
- rspec-support (~> 3.8.0)
34
- rspec-mocks (3.8.0)
55
+ rspec-support (~> 3.10.0)
56
+ rspec-mocks (3.10.2)
35
57
  diff-lcs (>= 1.2.0, < 2.0)
36
- rspec-support (~> 3.8.0)
37
- rspec-support (3.8.0)
38
- safe_yaml (1.0.4)
39
- simplecov (0.16.1)
58
+ rspec-support (~> 3.10.0)
59
+ rspec-support (3.10.2)
60
+ ruby2_keywords (0.0.5)
61
+ simplecov (0.21.2)
40
62
  docile (~> 1.1)
41
- json (>= 1.8, < 3)
42
- simplecov-html (~> 0.10.0)
43
- simplecov-html (0.10.2)
63
+ simplecov-html (~> 0.11)
64
+ simplecov_json_formatter (~> 0.1)
65
+ simplecov-html (0.12.3)
66
+ simplecov_json_formatter (0.1.3)
44
67
  vcr (4.0.0)
45
- webmock (3.4.2)
46
- addressable (>= 2.3.6)
68
+ webmock (3.14.0)
69
+ addressable (>= 2.8.0)
47
70
  crack (>= 0.3.2)
48
- hashdiff
71
+ hashdiff (>= 0.4.0, < 2.0.0)
49
72
 
50
73
  PLATFORMS
51
- ruby
74
+ x86_64-darwin-20
75
+ x86_64-linux
52
76
 
53
77
  DEPENDENCIES
54
- bundler (~> 1.16)
78
+ bundler (~> 2.2)
55
79
  byebug (~> 10.0)
56
80
  clicksign-api!
57
81
  dotenv (~> 2.5)
82
+ pry
58
83
  rake (~> 13.0)
59
84
  rspec (~> 3.0)
60
85
  simplecov (~> 0.16)
@@ -62,4 +87,4 @@ DEPENDENCIES
62
87
  webmock (~> 3.0)
63
88
 
64
89
  BUNDLED WITH
65
- 1.17.3
90
+ 2.2.29
data/README.md CHANGED
@@ -26,8 +26,14 @@ Or install it yourself as:
26
26
  By default, all requests use Clicksign's SANDBOX.
27
27
 
28
28
  ```ruby
29
+ credentials = {
30
+ "key.production" => ENV["CLICKSIGN_ACCESS_TOKEN_PRODUCTION"]
31
+ "key.sandbox" => ENV["CLICKSIGN_ACCESS_TOKEN_SANDBOX"]
32
+ }
33
+
29
34
  Clicksign::API.configure do |config|
30
- config.access_token = ENV['CLICKSIGN_ACCESS_TOKEN']
35
+ config.credentials = credentials
36
+ config.production = false
31
37
  end
32
38
  ```
33
39
 
@@ -47,41 +53,102 @@ To see all available parameters, please, check the [API docs](https://developers
47
53
  #### Create documents
48
54
 
49
55
  ```ruby
50
- response = Clicksign::API::Document.create(path: '/path/to/file.pdf', file: file)
56
+ file = File.open('/path/to/file/local/file.pdf', 'r')
57
+ document = Clicksign::API::Document.create( params: { path: '/path/to/file/on/clicksign.pdf', file: file }, token: 'valid_token')
51
58
  => #<Faraday::Response ...>
52
59
 
53
- response.success?
60
+ document.success?
54
61
  => true # false
55
62
 
56
- JSON.parse(response.body)
63
+ response_document = JSON.parse(document.body)
57
64
  => {:document=> {:key=> '...', :path=> '...', :status => '...', ... }
65
+ => # key: '123abcd' as example!
58
66
  ```
59
67
 
60
68
  #### View documents
61
69
 
62
70
  ```ruby
63
- response = Clicksign::API::Document.find('DOCUMENT_KEY')
71
+ find_document = Clicksign::API::Document.find(params: { key: response_document['document']['key'] }, token: 'valid_token')
64
72
  => #<Faraday::Response ...>
65
73
 
66
- response.success?
74
+ find_document.success?
67
75
  => true # false
68
76
 
69
- JSON.parse(response.body)
77
+ JSON.parse(find_document.body)
70
78
  => {:document=> {:key=> '...', :path=> '...', :status => '...', ... }
71
79
  ```
72
80
 
73
- #### Add signers
81
+ #### Create Signers
74
82
 
75
83
  ```ruby
76
- response = Clicksign::API::Signer.create('DOCUMENT_KEY', signer)
84
+ signer = Clicksign::API::Signer.create(params: { email: 'mail@email.com', auths: ['email'], delivery: 'email' }, token: 'valid_token')
77
85
  => #<Faraday::Response ...>
78
86
 
79
- response.success?
87
+ signer.success?
80
88
  => true # false
81
89
 
82
- JSON.parse(response.body)
90
+ response_signer = JSON.parse(signer.body)
83
91
  => {:document=> {:key=> '...', :path=> '...', :status => '...', ... }
92
+ => # signer_key: '999poo' as example!
84
93
  ```
94
+ #### Add Signers to Document
95
+
96
+ ```ruby
97
+
98
+ signer_document = Clicksign::API::DocumentsSigners.create(params: { document_key: response_document['document']['key'], signer_key: response_signer['key'], sign_as: 'sign_as' }, token: 'valid_token')
99
+ => #<Faraday::Response ...>
100
+
101
+ signer_document.success?
102
+ => true # false
103
+
104
+ response_signer_document = JSON.parse(signer_document.body)
105
+ => {:document=> {:key=> '...', :path=> '...', :status => '...', ... }
106
+ ```
107
+
108
+ ##### Creating Documents in Batches
109
+
110
+ ```ruby
111
+
112
+ batch = Clicksign::API::Batch.create(params: { document_keys: [response_document['document']['key'], 'other_document_key'], signer_key: response_signer['key'], summary: true}, token: 'valid_token')
113
+ => #<Faraday::Response ...>
114
+
115
+ batch.success?
116
+ => true # false
117
+
118
+ rseponse_batch = JSON.parse(batch.body)
119
+ => #{"batch"=> {"key"=>"3dd7fa89-15f7-48b6-81e8-7d14a273bbb8"
120
+
121
+ ```
122
+ #### Notifying Signer by e-mail
123
+
124
+ ```ruby
125
+ request_signature_key = JSON.parse(response_document_above.body)['document']['signers'].first['request_signature_key']
126
+ notify = Clicksign::API::Notifier.notify(params: { request_signature_key: request_signature_key }, token: 'valid_token')
127
+ => #<Faraday::Response ...>
128
+
129
+ notify.success?
130
+ => true # false
131
+
132
+ JSON.parse(notify.body)
133
+ => ##<struct Faraday::Env, method=:post request_body="{\"request_signature_key\":
134
+
135
+ ```
136
+
137
+ #### Notifying Signer by whatsapp
138
+
139
+ ```ruby
140
+ => # To deliver this content, its necessary add `phone_number` on Signer
141
+
142
+ request_signature_key = JSON.parse(response_document_above.body)['document']['signers'].first['request_signature_key']
143
+ notify = Clicksign::API::Notifier.notify(params: { request_signature_key: request_signature_key }, token: 'valid_token')
144
+ => #<Faraday::Response ...>
145
+
146
+ notify.success?
147
+ => true # false
148
+
149
+ JSON.parse(notify.body)
150
+ => ##<struct Faraday::Env, method=:post request_body="{\"request_signature_key\":
151
+
85
152
 
86
153
  ## Development
87
154
 
@@ -5,7 +5,7 @@ require "clicksign/api/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'clicksign-api'
8
- spec.version = Clicksign::Api::VERSION
8
+ spec.version = Clicksign::API::VERSION
9
9
  spec.authors = ['Francisco Martins']
10
10
  spec.email = ['franciscomxs@gmail.com']
11
11
 
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ['lib']
23
23
 
24
- spec.add_development_dependency 'bundler', '~> 1.16'
24
+ spec.add_development_dependency 'bundler', '~> 2.2'
25
25
  spec.add_development_dependency 'rake', '~> 13.0'
26
26
  spec.add_development_dependency 'rspec', '~> 3.0'
27
27
  spec.add_dependency 'faraday'
@@ -31,4 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency 'webmock', '~> 3.0'
32
32
  spec.add_development_dependency 'byebug', '~> 10.0'
33
33
  spec.add_development_dependency 'dotenv', '~> 2.5'
34
+ spec.add_development_dependency 'pry'
34
35
  end
@@ -7,10 +7,11 @@ module Clicksign
7
7
  ATTRIBUTES = [:signer_key, :document_keys, :summary]
8
8
 
9
9
  class << self
10
- def create(params = {})
10
+ def create(token:, params: {})
11
11
  post(
12
12
  REQUEST_PATH,
13
- body(params)
13
+ body(params),
14
+ token,
14
15
  )
15
16
  end
16
17
 
@@ -4,18 +4,20 @@ module Clicksign
4
4
  extend Requests
5
5
 
6
6
  REQUEST_PATH = '/api/v1/documents/'
7
- ATTRIBUTES = [:path, :deadline_at, :auto_close, :locale]
7
+ ATTRIBUTES = [:path, :deadline_at, :auto_close, :locale, :content_base64]
8
8
 
9
9
  class << self
10
- def create(params = {})
11
- post(REQUEST_PATH, body(params))
10
+ def create(token:, params: {})
11
+ post(REQUEST_PATH, body(params), token)
12
12
  end
13
13
 
14
- def find(key)
15
- get(REQUEST_PATH + key)
14
+ def find(token:, params:)
15
+ get(REQUEST_PATH + params[:key], token)
16
16
  end
17
17
 
18
18
  def body(params)
19
+ params = params.transform_keys(&:to_sym)
20
+
19
21
  document = ATTRIBUTES.each.with_object({}) do |attribute, hash|
20
22
  hash[attribute] = params[attribute] if params.has_key?(attribute)
21
23
  end
@@ -9,16 +9,17 @@ module Clicksign
9
9
  ]
10
10
 
11
11
  class << self
12
- def create(params)
12
+ def create(token:, params: {})
13
13
  post(
14
14
  REQUEST_PATH,
15
- body(params)
15
+ body(params),
16
+ token
16
17
  )
17
18
  end
18
19
 
19
- def batch_create(batch)
20
+ def batch_create(token:, batch:)
20
21
  batch.map do |params|
21
- create(params)
22
+ create(token: token, params: params)
22
23
  end
23
24
  end
24
25
 
@@ -7,10 +7,11 @@ module Clicksign
7
7
  ATTRIBUTES = [:request_signature_key, :message, :url]
8
8
 
9
9
  class << self
10
- def notify(params = {})
10
+ def notify(token:, params: {})
11
11
  post(
12
12
  REQUEST_PATH,
13
- body(params)
13
+ body(params),
14
+ token
14
15
  )
15
16
  end
16
17
 
@@ -1,17 +1,17 @@
1
1
  module Clicksign
2
2
  module API
3
3
  module Requests
4
- def post(request_path, body)
4
+ def post(request_path, body, token)
5
5
  conn.post do |req|
6
- req.url request_path, { access_token: Clicksign::API.access_token }
6
+ req.url request_path, { access_token: Clicksign::API.credentials[token] }
7
7
  req.headers['Content-Type'] = 'application/json'
8
8
  req.body = body.to_json
9
9
  end
10
10
  end
11
11
 
12
- def get(request_path)
12
+ def get(request_path, token)
13
13
  conn.get do |req|
14
- req.url request_path, { access_token: Clicksign::API.access_token }
14
+ req.url request_path, { access_token: Clicksign::API.credentials[token] }
15
15
  req.headers['Content-Type'] = 'application/json'
16
16
  end
17
17
  end
@@ -10,14 +10,17 @@ module Clicksign
10
10
  ]
11
11
 
12
12
  class << self
13
- def create(params)
13
+ def create(token:, params:)
14
14
  post(
15
15
  REQUEST_PATH,
16
- body(params)
16
+ body(params),
17
+ token
17
18
  )
18
19
  end
19
20
 
20
21
  def body(params)
22
+ params = params.transform_keys(&:to_sym)
23
+
21
24
  signer = ATTRIBUTES.each.with_object({}) do |key, hash|
22
25
  hash[key] = params[key] if params.has_key?(key)
23
26
  end
@@ -1,5 +1,5 @@
1
1
  module Clicksign
2
- module Api
3
- VERSION = "1.0.1"
2
+ module API
3
+ VERSION = "1.1.0.alpha4"
4
4
  end
5
5
  end
@@ -7,10 +7,11 @@ module Clicksign
7
7
  ATTRIBUTES = [:request_signature_key]
8
8
 
9
9
  class << self
10
- def notify(params = {})
10
+ def notify(token:, params: {})
11
11
  post(
12
12
  REQUEST_PATH,
13
- body(params)
13
+ body(params),
14
+ token
14
15
  )
15
16
  end
16
17
 
data/lib/clicksign/api.rb CHANGED
@@ -1,27 +1,30 @@
1
- require "clicksign/api/version"
1
+ require 'clicksign/api/version'
2
2
 
3
- require "faraday"
4
- require "base64"
3
+ require 'faraday'
4
+ require 'base64'
5
+ require 'json'
6
+ require 'yaml'
7
+ require 'erb'
5
8
 
6
9
  begin
7
- require "dotenv/load"
8
- require "byebug"
10
+ require 'dotenv/load'
11
+ require 'byebug'
12
+ require 'pry'
9
13
  rescue LoadError
10
14
  end
11
15
 
12
- require "clicksign/api/requests"
13
- require "clicksign/api/batch"
14
- require "clicksign/api/document"
15
- require "clicksign/api/documents_signers"
16
- require "clicksign/api/signer"
17
- require "clicksign/api/notifier"
18
- require "clicksign/api/whatsapp_notifier"
19
-
16
+ require 'clicksign/api/requests'
17
+ require 'clicksign/api/batch'
18
+ require 'clicksign/api/document'
19
+ require 'clicksign/api/documents_signers'
20
+ require 'clicksign/api/signer'
21
+ require 'clicksign/api/notifier'
22
+ require 'clicksign/api/whatsapp_notifier'
20
23
 
21
24
  module Clicksign
22
25
  module API
23
26
  class << self
24
- attr_accessor :access_token, :production
27
+ attr_accessor :credentials, :production
25
28
 
26
29
  def configure
27
30
  yield(self)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clicksign-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0.alpha4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francisco Martins
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-01 00:00:00.000000000 Z
11
+ date: 2021-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '2.2'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: '2.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '2.5'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  description:
140
154
  email:
141
155
  - franciscomxs@gmail.com
@@ -149,6 +163,7 @@ files:
149
163
  - ".ruby-gemset"
150
164
  - ".ruby-version"
151
165
  - ".travis.yml"
166
+ - CHANGELOG.md
152
167
  - Gemfile
153
168
  - Gemfile.lock
154
169
  - README.md
@@ -179,11 +194,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
194
  version: '0'
180
195
  required_rubygems_version: !ruby/object:Gem::Requirement
181
196
  requirements:
182
- - - ">="
197
+ - - ">"
183
198
  - !ruby/object:Gem::Version
184
- version: '0'
199
+ version: 1.3.1
185
200
  requirements: []
186
- rubygems_version: 3.0.3
201
+ rubygems_version: 3.1.6
187
202
  signing_key:
188
203
  specification_version: 4
189
204
  summary: Clicksign API ruby interface