This repository has been archived by the owner on Oct 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
/
signature_request.rb
372 lines (356 loc) · 19.2 KB
/
signature_request.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
#
# The MIT License (MIT)
#
# Copyright (C) 2014 hellosign.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
module HelloSign
module Api
#
# Contains all the api about the SignatureRequest resource.
# Take a look at our {https://www.hellosign.com/api/reference#SignatureRequest signature request api document}
# for more information about this.
#
# @author [hellosign]
#
module SignatureRequest
#
# Retrieves a Signature Request with the given ID.
# @option opts [String] signature_request_id The id of the SignatureRequest to retrieve.
# @option opts [Integer] ux_version sets the version of the signer page to use
#
# @return [HelloSign::Resource::SignatureRequest] a SignatureRequest object
#
# @example
# signature_request = @client.get_signature_request :signature_request_id => 'fa5c8a0b0f492d768749333ad6fcc214c111e967'
#
def get_signature_request(opts)
path = "/signature_request/#{opts[:signature_request_id]}"
query = create_query_string(opts, [:ux_version])
path += query
HelloSign::Resource::SignatureRequest.new get(path)
end
#
# Returns a list of SignatureRequests that you can access. This includes SignatureRequests you have sent as well as received, but not ones that you have been CCed on.
# @option opts[:page] [Integer] page (1) Which page number of the Template List to return.
# @option opts[:ux_version] [Integer] ux_version sets the version of the signer page to use
# @option opts[:query] [String] query string to search on, such as "title:Field Trip Release AND from:me"
#
# @return [HelloSign::Resource::ResourceArray]
#
# @example
# signature_requests = @client.get_signature_requests :page => 1
#
def get_signature_requests(opts={})
path = '/signature_request/list'
opts[:query] = create_search_string(opts[:query]) if opts[:query]
query = create_query_string(opts, [:page, :page_size, :ux_version, :query])
path += query
HelloSign::Resource::ResourceArray.new get(path, opts), 'signature_requests', HelloSign::Resource::SignatureRequest
end
#
# Creates and sends a new SignatureRequest with the submitted documents.
# If form_fields_per_document is not specified, a signature page will be affixed at the end
# and all signers will be required to add their signature there.
# @option opts [Integer] test_mode (0) Whether this is a test, the signature request will not be legally binding if set to 1.
# @option opts [Array<String>] files Use files to indicate the uploaded file(s) to send for signature. Currently we only support use of either the files parameter or file_urls parameter, not both.
# @option opts [Array<String>] file_urls Use file_urls to have HelloSign download the file(s) to send for signature. Currently we only support use of either the files parameter or file_urls parameter, not both.
# @option opts [String] title The title you want to assign to the SignatureRequest.
# @option opts [String] subject The subject in the email that will be sent to the signers.
# @option opts [String] message The custom message in the email that will be sent to the signers.
# @option opts [String] signing_redirect_url The URL you want the signer redirected to after they successfully sign. (optional)
# @option opts [Array<Hash>] signers List of signers, each item is a Hash with these keys:
# * :name (String) Sender' name
# * :email_address (String) Sender's email address
# * :order (Integer) The order the signer is required to sign in
# * :pin (Integer) The 4- to 12-character access code that will secure this signer's signature page. You must have a business plan to use this feature.
# @option opts [Array<String>] cc_email_addresses The email addresses that should be CCed.
# @option opts [String] form_fields_per_document
#
# @return [HelloSign::Resource::SignatureRequest] a SignatureRequest
#
# @example
# signature_request = @client.send_signature_request(
# :test_mode => 1,
# :title => 'NDA with Acme Co.',
# :subject => 'The NDA we talked about',
# :message => 'Please sign this NDA and then we can discuss more. Let me know if you have any questions.',
# :metadata => {
# :client_id => '1234',
# :custom_text => 'NDA #9'
# },
# :signers => [{
# :email_address => 'jack@example.com',
# :name => 'Jack',
# :order => 0,
# },{
# :email_address => 'jill@example.com',
# :name => 'Jill',
# :order => 1,
# }
# ],
# :cc_email_addresses => ['lawyer@example.com', 'lawyer@example2.com'],
# :files => ['NDA.pdf', 'AppendixA.pdf']
# )
#
def send_signature_request(opts)
prepare_files opts
prepare_signers opts
HelloSign::Resource::SignatureRequest.new post('/signature_request/send', :body => opts)
end
#
# Creates and sends a new SignatureRequest based off of the Template specified with the template_id parameter.
# @option opts [Integer] test_mode (0) Whether this is a test, the signature request will not be legally binding if set to 1.
# @option opts [String] template_id The id of the Template to use when creating the SignatureRequest.
# @option opts [String] title The title you want to assign to the SignatureRequest.
# @option opts [String] subject The subject in the email that will be sent to the signers.
# @option opts [String] message The custom message in the email that will be sent to the signers.
# @option opts [String] signing_redirect_url The URL you want the signer redirected to after they successfully sign. (optional)
# @option opts [Array<Hash>] signers List of signers
# * :name (String) Sender' name
# * :email_address (String) Sender's email address
# * :order (Integer) The order the signer is required to sign in
# * :pin (Integer) The 4- to 12-character access code that will secure this signer's signature page. You must have a business plan to use this feature.
# @option opts [Array<Hash>] ccs The email addresses CC destinations. Required when a CC role exists for the Template.
# @option opts [Hash] custom_fields (deprecated) The value to fill in for the custom field with the name of CustomFieldName.
# @option opts [Array<Hash>] custom_fields An array of custom merge fields, representing those present in the template. Only specify this when NOT specifying custom_fields by hash (the old way).
# @option opts [Integer] ux_version sets the version of the signer page to use
#
# @return [HelloSign::Resource::SignatureRequest] a SignatureRequest
# @example
# signature_request = @client.send_signature_request_with_template(
# :test_mode => 1,
# :template_ids => [
# 'c26b8a16784a872da37ea946b9ddec7c1e11dff6',
# 'c7ab48e9a9ee7102dd6229dbbc719abc7d90ff9f'
# ],
# :title => 'Purchase Order',
# :subject => 'Purchase Order',
# :message => 'Glad we could come to an agreement.',
# :metadata => {
# :client_id => '1234',
# :custom_text => 'NDA #9'
# },
# :signers => [
# {
# :email_address => 'george@example.com',
# :name => 'George',
# :role => 'Client'
# },
# {
# :email_address => 'mary@example.com',
# :name => 'Mary',
# :role => 'Manager'
# }
# ]
# )
# @example
# signature_request = @client.send_signature_request_with_template(
# :test_mode => 1,
# :template_id => 'c26b8a16784a872da37ea946b9ddec7c1e11dff6',
# :title => 'Purchase Order',
# :subject => 'Purchase Order',
# :message => 'Glad we could come to an agreement.',
# :metadata => {
# :client_id => '1234',
# :custom_text => 'NDA #9'
# },
# :signers => [
# {
# :email_address => 'george@example.com',
# :name => 'George',
# :role => 'Client'
# }
# ],
# :ccs => [
# {
# :email_address =>'accounting@example.com',
# :role => "Accounting"
# }
# ],
# :custom_fields =>
# {
# :CustomFieldName => '$20,000'
# }
# )
#
def send_signature_request_with_template(opts)
prepare_signers opts
prepare_ccs opts
prepare_templates opts
prepare_custom_fields opts
HelloSign::Resource::SignatureRequest.new post('/signature_request/send_with_template', :body => opts)
end
#
# Sends an email to the signer reminding them to sign the signature request.
# @option opts [String] signature_request_id The id of the SignatureRequest to send a reminder for.
# @option opts [String] email_address The email address of the signer to send a reminder to.
# @option opts [Integer] ux_version sets the version of the signer page to use
#
# @return [HelloSign::Resource::SignatureRequest] a SignatureRequest
# @example
# signature_request = @client.remind_signature_request :signature_request_id => '75cdf7dc8b323d43b347e4a3614d1f822bd09491', :email_address => 'john@example.com'
#
def remind_signature_request(opts)
HelloSign::Resource::SignatureRequest.new post("/signature_request/remind/#{opts[:signature_request_id]}", :body => opts)
end
#
# Cancels a SignatureRequest.
# @option opts [String] signature_request_id The id of the SignatureRequest to cancel.
#
# @example
# @client.cancel_signature_request :signature_request_id => '75cdf7dc8b323d43b347e4a3614d1f822bd09491'
def cancel_signature_request(opts)
post("/signature_request/cancel/#{opts[:signature_request_id]}", :body => opts)
end
#
# Download the PDF copy of the current documents specified by the signature_request_id parameter.
# @option opts [String] file_type Either 'pdf' or 'zip' depending on the file type desired. Defaults to pdf.
# @option opts [String] signature_request_id The id of the SignatureRequest to retrieve.
#
# @return a PDF
#
# @example
# pdf = @client.signature_request_files :signature_request_id => '75cdf7dc8b323d43b347e4a3614d1f822bd09491'
#
def signature_request_files(opts)
path = "/signature_request/files/#{opts[:signature_request_id]}"
if opts[:file_type]
path = path + "?file_type=#{opts[:file_type]}"
end
get(path)
end
#
# Creates a new SignatureRequest with the submitted documents to be signed in an embedded iFrame.
# If form_fields_per_document is not specified, a signature page will be affixed where all signers will be required to add their signature, signifying their agreement to all contained documents.
# Note that embedded signature requests can only be signed in embedded iFrames whereas normal signature requests can only be signed on HelloSign.
# @option opts [Integer] test_mode (0) Whether this is a test, the signature request will not be legally binding if set to 1.
# @option opts [String] client_id Client id of the app you're using to create this embedded signature request. Visit our {https://www.hellosign.com/api/reference#Embedded embedded page} page to learn more about this parameter.
# @option opts [Array<String>] files Use files to indicate the uploaded file(s) to send for signature. Currently we only support use of either the files parameter or file_urls parameter, not both.
# @option opts [Array<String>] file_urls Use file_urls to have HelloSign download the file(s) to send for signature. Currently we only support use of either the files parameter or file_urls parameter, not both.
# @option opts [String] title The title you want to assign to the SignatureRequest.
# @option opts [String] subject The subject in the email that will be sent to the signers.
# @option opts [String] message The custom message in the email that will be sent to the signers.
# @option opts [String] signing_redirect_url The URL you want the signer redirected to after they successfully sign. (optional)
# @option opts [Array<Hash>] signers List of signers, each item is a Hash with these keys:
# * :name (String) Sender' name
# * :email_address (String) Sender's email address
# * :order (Integer) The order the signer is required to sign in
# * :pin (Integer) The 4- to 12-character access code that will secure this signer's signature page. You must have a business plan to use this feature.
# @option opts [Array<String>] cc_email_addresses The email addresses that should be CCed.
# @option opts [String] form_fields_per_document
# @option opts [Integer] ux_version sets the version of the signer page to use
#
# @return [HelloSign::Resource::SignatureRequest] a SignatureRequest
# @example
# request = @client.create_embedded_signature_request(
# :test_mode => 1,
# :client_id => 'b6b8e7deaf8f0b95c029dca049356d4a2cf9710a',
# :title => 'NDA with Acme Co.',
# :subject => 'The NDA we talked about',
# :message => 'Please sign this NDA and then we can discuss more. Let me know if you have any questions.',
# :metadata => {
# :client_id => '1234',
# :custom_text => 'NDA #9'
# },
# :signers => [{
# :email_address => 'jack@example.com',
# :name => 'Jack',
# :order => 0,
# },{
# :email_address => 'jill@example.com',
# :name => 'Jill',
# :order => 1,
# }
# ],
# :cc_email_addresses => ['lawyer@example.com', 'lawyer@example2.com'],
# :files => ['NDA.pdf', 'AppendixA.pdf']
# )
#
def create_embedded_signature_request(opts)
opts[:client_id] ||= self.client_id
prepare_files opts
prepare_signers opts
HelloSign::Resource::SignatureRequest.new post('/signature_request/create_embedded', :body => opts)
end
#
# Creates a new SignatureRequest based on the given Template to be signed in an embedded iFrame.
# Note that embedded signature requests can only be signed in embedded iFrames whereas normal signature requests can only be signed on HelloSign.
# @option opts [Integer] test_mode (0) Whether this is a test, the signature request will not be legally binding if set to 1.
# @option opts [String] client_id Client id of the app you're using to create this embedded signature request. Visit our {https://www.hellosign.com/api/reference#Embedded embedded page} page to learn more about this parameter.
# @option opts [String] template_id The id of the Template to use when creating the SignatureRequest.
# @option opts [String] title The title you want to assign to the SignatureRequest.
# @option opts [String] subject The subject in the email that will be sent to the signers.
# @option opts [String] message The custom message in the email that will be sent to the signers.
# @option opts [String] signing_redirect_url The URL you want the signer redirected to after they successfully sign. (optional)
# @option opts [Integer] hide_text_tags Whether or not your text tags hidden after parsing
# @option opts [Integer] use_text_tags Whether or not your document contains parseable text-tags
# @option opts [Array<Hash>] signers List of signers, each item is a Hash with these keys:
# * :name (String) Sender' name
# * :email_address (String) Sender's email address
# * :order (Integer) The order the signer is required to sign in
# * :pin (Integer) The 4- to 12-character access code that will secure this signer's signature page. You must have a business plan to use this feature.
# @option opts [Hash] ccs The email address of the CC filling the role of RoleName. Required when a CC role exists for the Template.
# @option opts [Hash] custom_fields (deprecated) The value to fill in for custom field with the name of CustomFieldName.
# @option opts [Array<Hash>] custom_fields An array of custom merge fields, representing those present in the template. Only specify this when NOT specifying custom_fields by hash (the old way)
# @option opts [Integer] ux_version sets the version of the signer page to use
#
# @return [HelloSign::Resource::SignatureRequest] a SignatureRequest
# @example
# request = @client.create_embedded_signature_request_with_template(
# :test_mode => 1,
# :client_id => 'b6b8e7deaf8f0b95c029dca049356d4a2cf9710a',
# :template_id => 'c26b8a16784a872da37ea946b9ddec7c1e11dff6',
# :title => 'Purchase Order',
# :subject => 'Purchase Order',
# :message => 'Glad we could come to an agreement.',
# :metadata => {
# :client_id => '1234',
# :custom_text => 'NDA #9'
# },
# :signers => [
# {
# :email_address => 'george@example.com',
# :name => 'George',
# :role => 'Client'
# }
# ],
# :ccs => [
# {
# :email_address =>'accounting@example.com',
# :role => "Accounting"
# }
# ],
# :custom_fields => {
# :Cost => '$20,000'
# }
# )
#
def create_embedded_signature_request_with_template(opts)
opts[:client_id] ||= self.client_id
prepare_signers opts
prepare_ccs opts
prepare_templates opts
prepare_custom_fields opts
HelloSign::Resource::SignatureRequest.new post('/signature_request/create_embedded_with_template', :body => opts)
end
end
end
end