active_call-zoho_sign 0.1.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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +70 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +401 -0
- data/Rakefile +12 -0
- data/lib/zoho_sign/access_token/facade.rb +13 -0
- data/lib/zoho_sign/access_token/get_service.rb +53 -0
- data/lib/zoho_sign/base_service.rb +180 -0
- data/lib/zoho_sign/current_user/facade.rb +63 -0
- data/lib/zoho_sign/current_user/get_service.rb +37 -0
- data/lib/zoho_sign/document/action/embed_token/facade.rb +9 -0
- data/lib/zoho_sign/document/action/embed_token/get_service.rb +51 -0
- data/lib/zoho_sign/document/create_service.rb +70 -0
- data/lib/zoho_sign/document/delete_service.rb +29 -0
- data/lib/zoho_sign/document/facade.rb +50 -0
- data/lib/zoho_sign/document/get_service.rb +43 -0
- data/lib/zoho_sign/document/list_service.rb +98 -0
- data/lib/zoho_sign/document/update_service.rb +63 -0
- data/lib/zoho_sign/error.rb +46 -0
- data/lib/zoho_sign/locale/en.yml +18 -0
- data/lib/zoho_sign/template/document/create_service.rb +82 -0
- data/lib/zoho_sign/template/document/facade.rb +47 -0
- data/lib/zoho_sign/template/facade.rb +35 -0
- data/lib/zoho_sign/template/get_service.rb +43 -0
- data/lib/zoho_sign/template/list_service.rb +98 -0
- data/lib/zoho_sign/version.rb +5 -0
- data/lib/zoho_sign.rb +22 -0
- data/sig/zoho_sign.rbs +4 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 467acc9fbdcce17c52dbd1aefc3308d36769d371b3db5affb6de1a0b6428cef2
|
4
|
+
data.tar.gz: ddc9291cc32c8a3d6c238d98dfdbf5b18d540b1193d219c4527c5be53a1eda2a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9542b5eaa353d895ecabb9f7424f3da2096ecd1d358b887a8f502294678384bf8ccacec711a38435d6fd7f0a4e7e79de7840ad11d5e9469a582cd268374a3c9f
|
7
|
+
data.tar.gz: 697afb22b9060a6fcc3370a7bb94d17e65c760a983b380ae664890fe71f2c407139ee34c089a9357785c4c7ff8a01a4830d262f648e89b280eac107134fe28d0
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
plugins:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rake
|
4
|
+
- rubocop-rspec
|
5
|
+
|
6
|
+
AllCops:
|
7
|
+
TargetRubyVersion: 3.1
|
8
|
+
NewCops: enable
|
9
|
+
Exclude:
|
10
|
+
- zoho_sign.gemspec
|
11
|
+
- bin/*
|
12
|
+
- 'vendor/**/*'
|
13
|
+
- 'gem/**/*'
|
14
|
+
|
15
|
+
Layout/ArgumentAlignment:
|
16
|
+
EnforcedStyle: with_fixed_indentation
|
17
|
+
|
18
|
+
Layout/HashAlignment:
|
19
|
+
EnforcedHashRocketStyle: table
|
20
|
+
EnforcedColonStyle: table
|
21
|
+
|
22
|
+
Lint/MissingSuper:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Metrics/AbcSize:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Metrics/BlockLength:
|
29
|
+
Exclude:
|
30
|
+
- spec/*/**.rb
|
31
|
+
|
32
|
+
Metrics/ClassLength:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Metrics/CyclomaticComplexity:
|
36
|
+
Exclude:
|
37
|
+
- lib/zoho_sign/document/list_service.rb
|
38
|
+
|
39
|
+
Metrics/MethodLength:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
Metrics/PerceivedComplexity:
|
43
|
+
Exclude:
|
44
|
+
- lib/zoho_sign/document/list_service.rb
|
45
|
+
|
46
|
+
Naming/MemoizedInstanceVariableName:
|
47
|
+
EnforcedStyleForLeadingUnderscores: required
|
48
|
+
|
49
|
+
RSpec/ExampleLength:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
RSpec/MultipleExpectations:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
Style/ClassAndModuleChildren:
|
56
|
+
EnforcedStyle: compact
|
57
|
+
Exclude:
|
58
|
+
- lib/zoho_sign.rb
|
59
|
+
|
60
|
+
Style/Documentation:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
Style/StringLiterals:
|
64
|
+
EnforcedStyle: single_quotes
|
65
|
+
|
66
|
+
Style/StringLiteralsInInterpolation:
|
67
|
+
EnforcedStyle: single_quotes
|
68
|
+
|
69
|
+
Style/SymbolArray:
|
70
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Kobus Joubert
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,401 @@
|
|
1
|
+
# Active Call - Zoho Sign
|
2
|
+
|
3
|
+
Zoho Sign exposes the [Zoho Sign API](https://www.zoho.com/sign/api) endpoints through service objects.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
```bash
|
12
|
+
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
13
|
+
```
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
```bash
|
18
|
+
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
19
|
+
```
|
20
|
+
|
21
|
+
## Configuration
|
22
|
+
|
23
|
+
Configure your API credentials.
|
24
|
+
|
25
|
+
In a Rails application, the standard practice is to place this code in a file named `zoho_sign.rb` within the `config/initializers` directory.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
ZohoSign::BaseService.configure do |config|
|
29
|
+
config.client_id = ''
|
30
|
+
config.client_secret = ''
|
31
|
+
config.refresh_token = ''
|
32
|
+
|
33
|
+
# Optional configuration.
|
34
|
+
config.cache = Rails.cache # Default: ActiveSupport::Cache::MemoryStore.new
|
35
|
+
config.logger = Rails.logger # Default: Logger.new($stdout)
|
36
|
+
config.logger_level = :debug # Default: :info
|
37
|
+
config.log_headers = true # Default: false
|
38
|
+
config.log_bodies = true # Default: false
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
While testing, you can set your temporary development OAuth access token in the `ZOHO_SIGN_ACCESS_TOKEN` environment variable. In your production environment,`config.refresh_token` will be used.
|
43
|
+
|
44
|
+
## Usage
|
45
|
+
|
46
|
+
### Using `.call`
|
47
|
+
|
48
|
+
Each service object returned will undergo validation before the `call` method is invoked to access API endpoints.
|
49
|
+
|
50
|
+
After **successful** validation.
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
service.success? # => true
|
54
|
+
service.errors # => #<ActiveModel::Errors []>
|
55
|
+
```
|
56
|
+
|
57
|
+
After **failed** validation.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
service.success? # => false
|
61
|
+
service.errors # => #<ActiveModel::Errors [#<ActiveModel::Error attribute=name, type=blank, options={}>]>
|
62
|
+
service.errors.full_messages # => ["Name can't be blank"]
|
63
|
+
```
|
64
|
+
|
65
|
+
After a **successful** `call` invocation, the `response` attribute will contain a `Faraday::Response` object.
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
service.success? # => true
|
69
|
+
service.response # => #<Faraday::Response ...>
|
70
|
+
service.response.success? # => true
|
71
|
+
service.response.status # => 200
|
72
|
+
service.response.body # => {"code"=>0, "message"=>"Document has been retrieved", "status"=>"success", "requests"=>{...}}
|
73
|
+
```
|
74
|
+
|
75
|
+
At this point you will also have a `facade` object which will hold all the attributes for the specific resource.
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
service.facade # => #<ZohoSign::Document::Facade @request_status="inprogress" ...>
|
79
|
+
service.facade.request_status # => 'inprogress'
|
80
|
+
```
|
81
|
+
|
82
|
+
For convenience, facade attributes can be accessed directly on the service object.
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
service.request_status # => 'inprogress'
|
86
|
+
```
|
87
|
+
|
88
|
+
After a **failed** `call` invocation, the `response` attribute will still contain a `Faraday::Response` object.
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
service.success? # => false
|
92
|
+
service.errors # => #<ActiveModel::Errors [#<ActiveModel::Error attribute=base, type=Not found, options={}>]>
|
93
|
+
service.errors.full_messages # => ["No match found"]
|
94
|
+
service.response # => #<Faraday::Response ...>
|
95
|
+
service.response.success? # => false
|
96
|
+
service.response.status # => 400
|
97
|
+
service.response.body # => {"code"=>9004, "message"=>"No match found", "status"=>"failure"}
|
98
|
+
```
|
99
|
+
|
100
|
+
### Using `.call!`
|
101
|
+
|
102
|
+
Each service object returned will undergo validation before the `call!` method is invoked to access API endpoints.
|
103
|
+
|
104
|
+
After **successful** validation.
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
service.success? # => true
|
108
|
+
```
|
109
|
+
|
110
|
+
After **failed** validation, a `ZohoSign::ValidationError` exception will be raised with an `errors` attribute which
|
111
|
+
will contain an `ActiveModel::Errors` object.
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
rescue ZohoSign::ValidationError => exception
|
115
|
+
exception.message # => ''
|
116
|
+
exception.errors # => #<ActiveModel::Errors [#<ActiveModel::Error attribute=name, type=blank, options={}>]>
|
117
|
+
exception.errors.full_messages # => ["Name can't be blank"]
|
118
|
+
```
|
119
|
+
|
120
|
+
After a **successful** `call!` invocation, the `response` attribute will contain a `Faraday::Response` object.
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
service.success? # => true
|
124
|
+
service.response # => #<Faraday::Response ...>
|
125
|
+
service.response.success? # => true
|
126
|
+
service.response.status # => 200
|
127
|
+
service.response.body # => {"code"=>0, "message"=>"Document has been retrieved", "status"=>"success", "requests"=>{...}}
|
128
|
+
```
|
129
|
+
|
130
|
+
At this point you will also have a `facade` object which will hold all the attributes for the specific resource.
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
service.facade # => #<ZohoSign::Document::Facade @request_status="inprogress" ...>
|
134
|
+
service.facade.request_status # => 'inprogress'
|
135
|
+
```
|
136
|
+
|
137
|
+
For convenience, facade attributes can be accessed directly on the service object.
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
service.request_status # => 'inprogress'
|
141
|
+
```
|
142
|
+
|
143
|
+
After a **failed** `call!` invocation, a `ZohoSign::RequestError` will be raised with a `response` attribute which will contain a `Faraday::Response` object.
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
rescue ZohoSign::RequestError => exception
|
147
|
+
exception.message # => ''
|
148
|
+
exception.errors # => #<ActiveModel::Errors [#<ActiveModel::Error attribute=base, type=Not found, options={}>]>
|
149
|
+
exception.errors.full_messages # => ["No match found"]
|
150
|
+
exception.response # => #<Faraday::Response ...>
|
151
|
+
exception.response.status # => 400
|
152
|
+
exception.response.body # => {"code"=>9004, "message"=>"No match found", "status"=>"failure"}
|
153
|
+
```
|
154
|
+
|
155
|
+
### When to use `.call` or `.call!`
|
156
|
+
|
157
|
+
An example of where to use `.call` would be in a **controller** doing an inline synchronous request.
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
class DocumentController < ApplicationController
|
161
|
+
def update
|
162
|
+
@document = ZohoSign::Document::UpdateService.call(params)
|
163
|
+
|
164
|
+
if @document.success?
|
165
|
+
redirect_to [@document], notice: 'Success', status: :see_other
|
166
|
+
else
|
167
|
+
flash.now[:alert] = @document.errors.full_messages.to_sentence
|
168
|
+
render :edit, status: :unprocessable_entity
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
```
|
173
|
+
|
174
|
+
An example of where to use `.call!` would be in a **job** doing an asynchronous request.
|
175
|
+
|
176
|
+
You can use the exceptions to determine which retry strategy to use and which to discard.
|
177
|
+
|
178
|
+
```ruby
|
179
|
+
class DocumentJob < ApplicationJob
|
180
|
+
discard_on ZohoSign::NotFoundError
|
181
|
+
|
182
|
+
retry_on ZohoSign::RequestTimeoutError, wait: 5.minutes, attempts: :unlimited
|
183
|
+
retry_on ZohoSign::TooManyRequestsError, wait: :polynomially_longer, attempts: 10
|
184
|
+
|
185
|
+
def perform
|
186
|
+
ZohoSign::Document::UpdateService.call!(params)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
```
|
190
|
+
|
191
|
+
### Documents
|
192
|
+
|
193
|
+
#### List documents.
|
194
|
+
|
195
|
+
Note that the `offset` starts at `1` for the first item.
|
196
|
+
|
197
|
+
If you don't provide a `limit`, multiple API requests will be made untill all records have been returned. You could be
|
198
|
+
rate limited, so use wisely.
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
service = ZohoSign::Document::ListService.call(offset: 1, limit: 10).each do |facade|
|
202
|
+
facade.description
|
203
|
+
end
|
204
|
+
```
|
205
|
+
|
206
|
+
Sort by column.
|
207
|
+
|
208
|
+
```ruby
|
209
|
+
ZohoSign::Document::ListService.call(sort_column: 'recipient_email', sort_order: 'ASC').map { _1 }
|
210
|
+
```
|
211
|
+
|
212
|
+
Filter by column.
|
213
|
+
|
214
|
+
```ruby
|
215
|
+
ZohoSign::Document::ListService.call(search_columns: { recipient_email: 'eric.cartman@example.com' }).map { _1 }
|
216
|
+
```
|
217
|
+
|
218
|
+
Columns to sort and filter by are `request_name`, `folder_name`, `owner_full_name`, `recipient_email`,
|
219
|
+
`form_name` `created_time`.
|
220
|
+
|
221
|
+
#### Get a document.
|
222
|
+
|
223
|
+
```ruby
|
224
|
+
service = ZohoSign::Document::GetService.call(id: '')
|
225
|
+
service.request_name
|
226
|
+
service.request_id
|
227
|
+
service.request_status
|
228
|
+
service.owner_email
|
229
|
+
service.owner_first_name
|
230
|
+
service.owner_last_name
|
231
|
+
service.attachments
|
232
|
+
service.sign_percentage
|
233
|
+
...
|
234
|
+
```
|
235
|
+
|
236
|
+
#### Create a document.
|
237
|
+
|
238
|
+
```ruby
|
239
|
+
service = ZohoSign::Document::CreateService.call(
|
240
|
+
file: '/path/to/file.pdf', # or File.open('/path/to/file.pdf')
|
241
|
+
file_name: 'file.pdf',
|
242
|
+
file_content_type: 'application/pdf',
|
243
|
+
data: {
|
244
|
+
requests: {
|
245
|
+
request_name: 'Name',
|
246
|
+
is_sequential: false,
|
247
|
+
actions: [{
|
248
|
+
action_type: 'SIGN',
|
249
|
+
recipient_email: 'eric.cartman@example.com',
|
250
|
+
recipient_name: 'Eric Cartman',
|
251
|
+
verify_recipient: true,
|
252
|
+
verification_type: 'EMAIL'
|
253
|
+
}]
|
254
|
+
}
|
255
|
+
}
|
256
|
+
)
|
257
|
+
```
|
258
|
+
|
259
|
+
#### Update a document.
|
260
|
+
|
261
|
+
```ruby
|
262
|
+
service = ZohoSign::Document::UpdateService.call(
|
263
|
+
id: '',
|
264
|
+
data: {
|
265
|
+
requests: {
|
266
|
+
request_name: 'Name Updated',
|
267
|
+
actions: [{
|
268
|
+
action_id: '',
|
269
|
+
action_type: 'SIGN',
|
270
|
+
recipient_email: 'stan.marsh@example.com',
|
271
|
+
recipient_name: 'Stan Marsh'
|
272
|
+
}]
|
273
|
+
}
|
274
|
+
}
|
275
|
+
)
|
276
|
+
```
|
277
|
+
|
278
|
+
#### Delete a document.
|
279
|
+
|
280
|
+
```ruby
|
281
|
+
service = ZohoSign::Document::DeleteService.call(id: '')
|
282
|
+
```
|
283
|
+
|
284
|
+
### Folders
|
285
|
+
|
286
|
+
TODO: ...
|
287
|
+
|
288
|
+
### Field Types
|
289
|
+
|
290
|
+
TODO: ...
|
291
|
+
|
292
|
+
### Request Types
|
293
|
+
|
294
|
+
TODO: ...
|
295
|
+
|
296
|
+
### Templates
|
297
|
+
|
298
|
+
#### List templates.
|
299
|
+
|
300
|
+
Note that the `offset` starts at `1` for the first item.
|
301
|
+
|
302
|
+
If you don't provide a `limit`, multiple API requests will be made untill all records have been returned. You could be
|
303
|
+
rate limited, so use wisely.
|
304
|
+
|
305
|
+
```ruby
|
306
|
+
service = ZohoSign::Template::ListService.call(offset: 1, limit: 10).each do |facade|
|
307
|
+
facade.description
|
308
|
+
end
|
309
|
+
```
|
310
|
+
|
311
|
+
Sort by column.
|
312
|
+
|
313
|
+
```ruby
|
314
|
+
ZohoSign::Template::ListService.call(sort_column: 'template_name', sort_order: 'ASC').map { _1 }
|
315
|
+
```
|
316
|
+
|
317
|
+
Filter by column.
|
318
|
+
|
319
|
+
```ruby
|
320
|
+
ZohoSign::Template::ListService.call(search_columns: { template_name: 'Eric Template' }).map { _1 }
|
321
|
+
```
|
322
|
+
|
323
|
+
Columns to sort and filter by are `template_name`, `owner_first_name`, `modified_time`.
|
324
|
+
|
325
|
+
#### Get a template.
|
326
|
+
|
327
|
+
```ruby
|
328
|
+
service = ZohoSign::Template::GetService.call(id: '')
|
329
|
+
service.description
|
330
|
+
service.document_fields
|
331
|
+
service.email_reminders
|
332
|
+
service.expiration_days
|
333
|
+
service.folder_name
|
334
|
+
service.folder_id
|
335
|
+
service.owner_email
|
336
|
+
service.template_name
|
337
|
+
...
|
338
|
+
```
|
339
|
+
|
340
|
+
#### Create a template.
|
341
|
+
|
342
|
+
TODO: ...
|
343
|
+
|
344
|
+
#### Update a template.
|
345
|
+
|
346
|
+
TODO: ...
|
347
|
+
|
348
|
+
#### Delete a template.
|
349
|
+
|
350
|
+
TODO: ...
|
351
|
+
|
352
|
+
#### Create document from template.
|
353
|
+
|
354
|
+
The auto filled fields specified in the `field_data` object should be marked as **Prefill by you** when creating the document template.
|
355
|
+
|
356
|
+
```ruby
|
357
|
+
service = ZohoSign::Template::Document::CreateService.call!(
|
358
|
+
id: '',
|
359
|
+
is_quicksend: true,
|
360
|
+
data: {
|
361
|
+
templates: {
|
362
|
+
request_name: 'Request Document',
|
363
|
+
field_data: {
|
364
|
+
field_text_data: {
|
365
|
+
'Full name' => 'Eric Cartman',
|
366
|
+
'Email' => 'eric.cartman@example.com'
|
367
|
+
},
|
368
|
+
field_boolean_data: {
|
369
|
+
'Agreed to terms' => true
|
370
|
+
},
|
371
|
+
field_date_data: {
|
372
|
+
'Inception date' => '31/01/2025'
|
373
|
+
}
|
374
|
+
},
|
375
|
+
actions: [{
|
376
|
+
action_type: 'SIGN',
|
377
|
+
recipient_email: 'eric.cartman@example.com',
|
378
|
+
recipient_name: 'Eric Cartman',
|
379
|
+
verify_recipient: false,
|
380
|
+
delivery_mode: 'EMAIL',
|
381
|
+
action_id: '',
|
382
|
+
role: 'Client'
|
383
|
+
}]
|
384
|
+
}
|
385
|
+
}
|
386
|
+
)
|
387
|
+
```
|
388
|
+
|
389
|
+
## Development
|
390
|
+
|
391
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
392
|
+
|
393
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
394
|
+
|
395
|
+
## Contributing
|
396
|
+
|
397
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kobusjoubert/zoho_sign.
|
398
|
+
|
399
|
+
## License
|
400
|
+
|
401
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ZohoSign::AccessToken::Facade
|
4
|
+
attr_reader :access_token, :api_domain, :expires_in, :scope, :token_type
|
5
|
+
|
6
|
+
def initialize(hash)
|
7
|
+
@access_token = hash['access_token']
|
8
|
+
@api_domain = hash['api_domain']
|
9
|
+
@expires_in = hash['expires_in']
|
10
|
+
@scope = hash['scope']
|
11
|
+
@token_type = hash['token_type']
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ZohoSign::AccessToken::GetService < ZohoSign::BaseService
|
4
|
+
after_call :set_facade
|
5
|
+
|
6
|
+
delegate_missing_to :@facade
|
7
|
+
|
8
|
+
# Get access token.
|
9
|
+
#
|
10
|
+
# ==== Examples
|
11
|
+
#
|
12
|
+
# service = ZohoSign::AccessToken::GetService.call
|
13
|
+
# service.access_token # => '1000.xxxx.yyyy'
|
14
|
+
# service.expires_in # => 3600
|
15
|
+
#
|
16
|
+
# POST /oauth/v2/token
|
17
|
+
def call
|
18
|
+
connection.post('oauth/v2/token', params.to_param)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def connection
|
24
|
+
@_connection ||= Faraday.new do |conn|
|
25
|
+
conn.url_prefix = 'https://accounts.zoho.com'
|
26
|
+
conn.request :retry
|
27
|
+
conn.response :json
|
28
|
+
conn.response :logger, logger, **logger_options do |logger|
|
29
|
+
logger.filter(/(refresh_token|client_id|client_secret)=([^&]+)/i, '\1=[FILTERED]')
|
30
|
+
logger.filter(/"access_token":"([^"]+)"/i, '"access_token":"[FILTERED]"')
|
31
|
+
end
|
32
|
+
conn.adapter Faraday.default_adapter
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def params
|
37
|
+
{
|
38
|
+
client_id: client_id,
|
39
|
+
client_secret: client_secret,
|
40
|
+
refresh_token: refresh_token,
|
41
|
+
redirect_uri: 'https://sign.zoho.com',
|
42
|
+
grant_type: 'refresh_token'
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def unauthorized?
|
47
|
+
response.status == 200 && response.body.key?('error')
|
48
|
+
end
|
49
|
+
|
50
|
+
def set_facade
|
51
|
+
@facade = ZohoSign::AccessToken::Facade.new(response.body)
|
52
|
+
end
|
53
|
+
end
|