Skip to content
This repository was archived by the owner on Oct 17, 2023. It is now read-only.

Commit b602128

Browse files
Merge pull request #65 from hellosign/v3
Back merge
2 parents cf3e249 + 4829787 commit b602128

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

hellosign_sdk/hsclient.py

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def get_signature_request(self, signature_request_id):
296296
return request.get(self.SIGNATURE_REQUEST_INFO_URL + signature_request_id, parameters=parameters)
297297

298298
@api_resource_list(SignatureRequest)
299-
def get_signature_request_list(self, page=1):
299+
def get_signature_request_list(self, page=1, page_size=None):
300300
''' Get a list of SignatureRequest that you can access
301301
302302
This includes SignatureRequests you have sent as well as received, but
@@ -305,6 +305,8 @@ def get_signature_request_list(self, page=1):
305305
Args:
306306
307307
page (int, optional): Which page number of the SignatureRequest list to return. Defaults to 1.
308+
page_size (int, optional): Number of SignatureRequests to return per page. When not explicit
309+
it defaults to 20.
308310
309311
Returns:
310312
A ResourceList object
@@ -313,7 +315,8 @@ def get_signature_request_list(self, page=1):
313315

314316
request = self._get_request()
315317
parameters = {
316-
"page": page
318+
"page": page,
319+
"page_size": page_size
317320
}
318321

319322
return request.get(self.SIGNATURE_REQUEST_LIST_URL, parameters=parameters)
@@ -341,14 +344,16 @@ def get_signature_request_file(self, signature_request_id, path_or_file=None, fi
341344
'''
342345
request = self._get_request()
343346
url = self.SIGNATURE_REQUEST_DOWNLOAD_PDF_URL + signature_request_id
344-
if file_type:
345-
url += '?file_type=%s' % file_type
346-
return request.get_file(url, path_or_file or filename)
347347

348348
if response_type == 'url':
349349
url += '?get_url=1'
350350
elif response_type == 'data_uri':
351351
url += '?get_data_uri=1'
352+
else:
353+
if file_type:
354+
url += '?file_type=%s' % file_type
355+
return request.get_file(url, path_or_file or filename)
356+
352357
return request.get(url)
353358

354359
def send_signature_request(self, test_mode=False, client_id=None, files=None, file_urls=None,
@@ -391,7 +396,7 @@ def send_signature_request(self, test_mode=False, client_id=None, files=None, fi
391396
392397
cc_email_addresses (list, optional): A list of email addresses that should be CC'd on the request.
393398
394-
form_fields_per_document (str): The signer components that should appear on the document, expressed as a serialized
399+
form_fields_per_document (str or list of dict, optional): The signer components that should appear on the document, expressed as a serialized
395400
JSON data structure which is a list of lists of the form fields. Please refer to the API reference of HelloSign for more details (https://app.hellosign.com/api/reference#SignatureRequest).
396401
397402
use_text_tags (bool, optional): Use text tags in the provided file(s) to specify signer components.
@@ -659,7 +664,7 @@ def send_signature_request_embedded(self, test_mode=False, client_id=None,
659664
660665
cc_email_addresses (list, optional): A list of email addresses that should be CCed
661666
662-
form_fields_per_document (str): The fields that should appear on the document, expressed as a serialized
667+
form_fields_per_document (str or list of dict, optional): The fields that should appear on the document, expressed as a serialized
663668
JSON data structure which is a list of lists of the form fields. Please refer to the API reference of HelloSign for more details (https://www.hellosign.com/api/reference#SignatureRequest)
664669
665670
use_text_tags (bool, optional): Use text tags in the provided file(s) to create form fields
@@ -1421,7 +1426,7 @@ def create_unclaimed_draft(self, test_mode=False, files=None, file_urls=None,
14211426
14221427
signing_redirect_url (str, optional): The URL you want the signer redirected to after they successfully sign.
14231428
1424-
form_fields_per_document (str, optional): The fields that should appear on the document, expressed as a serialized JSON
1429+
form_fields_per_document (str or list of dict, optional): The fields that should appear on the document, expressed as a serialized JSON
14251430
data structure which is a list of lists of the form fields. Please refer to the API reference of HelloSign for more details (https://www.hellosign.com/api/reference#SignatureRequest)
14261431
14271432
metadata (dict, optional): Metadata to associate with the draft
@@ -1516,7 +1521,7 @@ def create_embedded_unclaimed_draft(self, test_mode=False, client_id=None,
15161521
15171522
requesting_redirect_url (str, optional): The URL you want the signer to be redirected to after the request has been sent.
15181523
1519-
form_fields_per_document (str, optional): The fields that should appear on the document, expressed as a serialized JSON data structure which is a list of lists of the form fields. Please refer to the API reference of HelloSign for more details (https://www.hellosign.com/api/reference#SignatureRequest)
1524+
form_fields_per_document (str or list of dict, optional): The fields that should appear on the document, expressed as a serialized JSON data structure which is a list of lists of the form fields. Please refer to the API reference of HelloSign for more details (https://www.hellosign.com/api/reference#SignatureRequest)
15201525
15211526
metadata (dict, optional): Metadata to associate with the draft
15221527
@@ -1890,7 +1895,7 @@ def _send_signature_request(self, test_mode=False, client_id=None, files=None,
18901895
18911896
cc_email_addresses (list, optional): A list of email addresses that should be CCed
18921897
1893-
form_fields_per_document (str): The fields that should appear on the document, expressed as a serialized JSON data structure which is a list of lists of the form fields. Please refer to the API reference of HelloSign for more details (https://www.hellosign.com/api/reference#SignatureRequest)
1898+
form_fields_per_document (str or list of dict, optional): The fields that should appear on the document, expressed as a serialized JSON data structure which is a list of lists of the form fields. Please refer to the API reference of HelloSign for more details (https://www.hellosign.com/api/reference#SignatureRequest)
18941899
18951900
use_text_tags (bool, optional): Use text tags in the provided file(s) to create form fields
18961901
@@ -1923,6 +1928,12 @@ def _send_signature_request(self, test_mode=False, client_id=None, files=None,
19231928
# Custom fields
19241929
custom_fields_payload = HSFormat.format_custom_fields(custom_fields)
19251930

1931+
# Form fields per document
1932+
if type(form_fields_per_document) is str:
1933+
form_fields_payload = form_fields_per_document
1934+
else:
1935+
form_fields_payload = HSFormat.format_json_data(form_fields_per_document)
1936+
19261937
# CCs
19271938
cc_email_addresses_payload = HSFormat.format_param_list(cc_email_addresses, 'cc_email_addresses')
19281939

@@ -1939,11 +1950,12 @@ def _send_signature_request(self, test_mode=False, client_id=None, files=None,
19391950
"subject": subject,
19401951
"message": message,
19411952
"signing_redirect_url": signing_redirect_url,
1942-
"form_fields_per_document": form_fields_per_document,
1953+
"form_fields_per_document": form_fields_payload,
19431954
"use_text_tags": self._boolean(use_text_tags),
19441955
"hide_text_tags": self._boolean(hide_text_tags),
19451956
"allow_decline": self._boolean(allow_decline),
19461957
"allow_reassign": self._boolean(allow_reassign),
1958+
"signing_options": HSFormat.format_json_data(signing_options)
19471959
}
19481960

19491961
# remove attributes with none value
@@ -2057,6 +2069,8 @@ def _send_signature_request_with_template(self, test_mode=False, client_id=None,
20572069
"message": message,
20582070
"signing_redirect_url": signing_redirect_url,
20592071
"allow_decline": self._boolean(allow_decline),
2072+
"signing_options": HSFormat.format_json_data(signing_options)
2073+
20602074
}
20612075

20622076
# remove attributes with empty value
@@ -2125,7 +2139,7 @@ def _create_unclaimed_draft(self, test_mode=False, client_id=None,
21252139
21262140
requesting_redirect_url (str, optional): The URL you want the signer to be redirected to after the request has been sent.
21272141
2128-
form_fields_per_document (str): The fields that should appear on the document, expressed as a serialized JSON data structure which is a list of lists of the form fields. Please refer to the API reference of HelloSign for more details (https://www.hellosign.com/api/reference#SignatureRequest).
2142+
form_fields_per_document (str or list of dict, optional): The fields that should appear on the document, expressed as a serialized JSON data structure which is a list of lists of the form fields. Please refer to the API reference of HelloSign for more details (https://www.hellosign.com/api/reference#SignatureRequest).
21292143
21302144
metadata (dict, optional): Metadata to associate with the draft
21312145
@@ -2171,6 +2185,12 @@ def _create_unclaimed_draft(self, test_mode=False, client_id=None,
21712185
# Custom fields
21722186
custom_fields_payload = HSFormat.format_custom_fields(custom_fields)
21732187

2188+
# Form fields per document
2189+
if type(form_fields_per_document) is str:
2190+
form_fields_payload = form_fields_per_document
2191+
else:
2192+
form_fields_payload = HSFormat.format_json_data(form_fields_per_document)
2193+
21742194
# Metadata
21752195
metadata_payload = HSFormat.format_single_dict(metadata, 'metadata')
21762196

@@ -2183,13 +2203,15 @@ def _create_unclaimed_draft(self, test_mode=False, client_id=None,
21832203
"subject": subject,
21842204
"message": message,
21852205
"signing_redirect_url": signing_redirect_url,
2186-
"form_fields_per_document": form_fields_per_document,
2206+
"form_fields_per_document": form_fields_payload,
21872207
"use_preexisting_fields": self._boolean(use_preexisting_fields),
21882208
"use_text_tags": self._boolean(use_text_tags),
21892209
"hide_text_tags": self._boolean(hide_text_tags),
21902210
"skip_me_now": self._boolean(skip_me_now),
21912211
"allow_reassign": self._boolean(allow_reassign),
21922212
"allow_decline": self._boolean(allow_decline),
2213+
"signing_options": HSFormat.format_json_data(signing_options),
2214+
21932215
"allow_ccs": self._boolean(allow_ccs)
21942216
}
21952217

@@ -2379,6 +2401,7 @@ def _create_embedded_unclaimed_draft_with_template(self, test_mode=False,
23792401
"skip_me_now": self._boolean(skip_me_now),
23802402
"allow_decline": self._boolean(allow_decline),
23812403
"allow_reassign": self._boolean(allow_reassign),
2404+
"signing_options": HSFormat.format_json_data(signing_options)
23822405
}
23832406

23842407
#format multi params

hellosign_sdk/utils/hsformat.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
# SOFTWARE.
2323
#
24+
2425
import json
2526

2627
class HSFormat(object):
@@ -151,3 +152,13 @@ def format_signing_options(listed_params, output_name):
151152
def strip_none_values(dictionary):
152153
if dictionary:
153154
return dict((key, value) for (key, value) in dictionary.items() if value)
155+
156+
@staticmethod
157+
def format_json_data(options):
158+
'''
159+
Utility method to convert to JSON data were required. Several of the signing parameters require JSON data
160+
Args:
161+
options (list of options) - the list of options passed to convert to JSON data
162+
'''
163+
json_data = json.dumps(options).replace('null', '')
164+
return json_data

0 commit comments

Comments
 (0)