diff --git a/.gitignore b/.gitignore index c4c5bd9d..963fddd3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ web.properties .project .classpath src/test/webapp +.idea/ +*.iml \ No newline at end of file diff --git a/src/main/java/com/hellosign/sdk/HelloSignClient.java b/src/main/java/com/hellosign/sdk/HelloSignClient.java index 85288789..512b131a 100644 --- a/src/main/java/com/hellosign/sdk/HelloSignClient.java +++ b/src/main/java/com/hellosign/sdk/HelloSignClient.java @@ -461,6 +461,22 @@ public SignatureRequestList getSignatureRequests(int page) throws HelloSignExcep .get(BASE_URI + SIGNATURE_REQUEST_LIST_URI).asJson()); } + /** + * Retrieves a specific page of the current user's signature requests. + * + * @param page int + * @param pageSize int Must be between 1 and 100. + * @return SignatureRequestList + * @throws HelloSignException thrown if there's a problem processing the + * HTTP request or the JSON response. + */ + public SignatureRequestList getSignatureRequests(int page, int pageSize) throws HelloSignException { + return new SignatureRequestList( + httpClient.withAuth(auth).withGetParam(AbstractResourceList.PAGE, Integer.toString(page)) + .withGetParam(AbstractResourceList.PAGE_SIZE, Integer.toString(pageSize)) + .get(BASE_URI + SIGNATURE_REQUEST_LIST_URI).asJson()); + } + /** * Sends the provided signature request to HelloSign. * @@ -512,7 +528,7 @@ public TemplateList getTemplates() throws HelloSignException { } /** - * Retreives a page of templates for the current user account. + * Retrieves a page of templates for the current user account. * * @param page int * @return TemplateList @@ -525,6 +541,21 @@ public TemplateList getTemplates(int page) throws HelloSignException { .get(BASE_URI + TEMPLATE_LIST_URI).asJson()); } + /** + * Retrieves a page of templates with a specific pageSize + * @param page int + * @param pageSize int Must be between 1 and 100. + * @return TemplateList + * @throws HelloSignException thrown if there's a problem processing the + * HTTP request or the JSON response. + */ + public TemplateList getTemplates(int page, int pageSize) throws HelloSignException { + return new TemplateList( + httpClient.withAuth(auth).withGetParam(AbstractResourceList.PAGE, Integer.toString(page)) + .withGetParam(AbstractResourceList.PAGE_SIZE, Integer.toString(pageSize)) + .get(BASE_URI + TEMPLATE_LIST_URI).asJson()); + } + /** * Retrieves the PDF file backing the Template specified by the provided * Template ID. diff --git a/src/test/java/com/hellosign/sdk/HelloSignClientTest.java b/src/test/java/com/hellosign/sdk/HelloSignClientTest.java index 7c42190b..9e8e9e99 100644 --- a/src/test/java/com/hellosign/sdk/HelloSignClientTest.java +++ b/src/test/java/com/hellosign/sdk/HelloSignClientTest.java @@ -350,6 +350,21 @@ public void testGetSignatureRequestsPageInvalid() throws Exception { assertFalse(list.iterator().hasNext()); } + @Test + public void testGetSignatureRequestsPageSize() throws Exception { + SignatureRequestList list = client.getSignatureRequests(1, 20); + for (SignatureRequest s : list) { + assertNotNull(s); + assertNotNull(s.getId()); + } + } + + @Test + public void testGetSignatureRequestsPageSizeInvalid() throws Exception { + SignatureRequestList list = client.getSignatureRequests(1, 200); + assertFalse(list.iterator().hasNext()); + } + @Test public void testSendSignatureRequest() throws Exception { String subject = "From the Mare"; @@ -432,6 +447,26 @@ public void testGetTemplatesPageInvalid() throws Exception { assertFalse(templates.iterator().hasNext()); } + @Test + public void testGetTemplatePageSize() throws Exception { + TemplateList templates = client.getTemplates(1, 20); + assertNotNull(templates); + for (Template t : templates) { + assertNotNull(t); + assertTrue(t.hasId()); + } + } + + @Test + public void testGetTemplatePageSizeInvalid() throws Exception { + TemplateList templates = client.getTemplates(1, 200); + assertNotNull(templates); + for (Template t : templates) { + assertNotNull(t); + assertTrue(t.hasId()); + } + } + @Test public void testGetTemplateFile() throws Exception { // Mock a random byte size written diff --git a/src/test/resources/HelloSignClientTest/testGetSignatureRequestsPageSize.json b/src/test/resources/HelloSignClientTest/testGetSignatureRequestsPageSize.json new file mode 100644 index 00000000..7845b1d2 --- /dev/null +++ b/src/test/resources/HelloSignClientTest/testGetSignatureRequestsPageSize.json @@ -0,0 +1,46 @@ +{ + "list_info": { + "page": 1, + "num_pages": 1, + "num_results": 1, + "page_size": 100 + }, + "signature_requests": [ + { + "signature_request_id": "c946eddbcc89583d9ed3173ea3fa2f98ee47f1c6", + "test_mode": false, + "title": "Test Document", + "original_title": "Test Document", + "subject": "Test Document", + "message": null, + "metadata": {}, + "is_complete": false, + "is_declined": false, + "has_error": false, + "custom_fields": [], + "response_data": [], + "signing_url": "https://app.dev-hellosign.com/sign/c946eddbcc89583d9ed3173ea3fa2f98ee47f1c6", + "signing_redirect_url": null, + "final_copy_uri": "/v3/signature_request/final_copy/c946eddbcc89583d9ed3173ea3fa2f98ee47f1c6", + "files_url": "https://api.dev-hellosign.com/apiapp_dev.php/v3/signature_request/files/c946eddbcc89583d9ed3173ea3fa2f98ee47f1c6", + "details_url": "https://app.dev-hellosign.com/home/manage?guid=c946eddbcc89583d9ed3173ea3fa2f98ee47f1c6", + "requester_email_address": "john.spaetzel@hellosign.com", + "signatures": [ + { + "signature_id": "12af84fa86c652212ba78da66a71ad6e", + "has_pin": false, + "signer_email_address": "john@hellosign.com", + "signer_name": "John", + "signer_role": null, + "order": null, + "status_code": "awaiting_signature", + "signed_at": null, + "last_viewed_at": null, + "last_reminded_at": null, + "error": null + } + ], + "cc_email_addresses": [] + } + ] +} \ No newline at end of file diff --git a/src/test/resources/HelloSignClientTest/testGetSignatureRequestsPageSizeInvalid.json b/src/test/resources/HelloSignClientTest/testGetSignatureRequestsPageSizeInvalid.json new file mode 100644 index 00000000..00e05521 --- /dev/null +++ b/src/test/resources/HelloSignClientTest/testGetSignatureRequestsPageSizeInvalid.json @@ -0,0 +1,9 @@ +{ + "list_info": { + "page": 1, + "num_pages": 0, + "num_results": 0, + "page_size": 200 + }, + "signature_requests": [] +} \ No newline at end of file diff --git a/src/test/resources/HelloSignClientTest/testGetTemplatePageSize.json b/src/test/resources/HelloSignClientTest/testGetTemplatePageSize.json new file mode 100644 index 00000000..3d6448f0 --- /dev/null +++ b/src/test/resources/HelloSignClientTest/testGetTemplatePageSize.json @@ -0,0 +1,77 @@ +{ + "list_info": { + "page": 1, + "num_pages": 1, + "num_results": 1, + "page_size": 20 + }, + "templates": [ + { + "template_id": "6773f5cb6d191248366695ddca468751a3f9578f", + "reusable_form_id": "6773f5cb6d191248366695ddca468751a3f9578f", + "title": "Test Template", + "message": "", + "is_creator": true, + "is_embedded": false, + "can_edit": true, + "metadata": {}, + "is_locked": false, + "signer_roles": [ + { + "name": "Client", + "order": null + } + ], + "cc_roles": [], + "documents": [ + { + "index": 0, + "name": "Test - No tags - 1 page.pdf", + "field_groups": [], + "custom_fields": [], + "form_fields": [ + { + "name": "", + "type": "signature", + "signer": "1", + "x": 609, + "y": 131, + "width": 120, + "height": 30, + "required": true, + "api_id": "df80de_9", + "group": null + } + ] + } + ], + "custom_fields": [], + "named_form_fields": [ + { + "name": "", + "type": "signature", + "signer": "1", + "x": 609, + "y": 131, + "width": 120, + "height": 30, + "required": true, + "api_id": "df80de_9", + "group": null + } + ], + "accounts": [ + { + "account_id": "13dd6e424c6d7b6d5fb325f1da907aef968e9fc4", + "email_address": "john.spaetzel@hellosign.com", + "is_locked": false, + "is_paid_hs": true, + "is_paid_hf": true, + "quotas": { + "fax_pages_left": 1010 + } + } + ] + } + ] +} \ No newline at end of file diff --git a/src/test/resources/HelloSignClientTest/testGetTemplatePageSizeInvalid.json b/src/test/resources/HelloSignClientTest/testGetTemplatePageSizeInvalid.json new file mode 100644 index 00000000..16bc09a7 --- /dev/null +++ b/src/test/resources/HelloSignClientTest/testGetTemplatePageSizeInvalid.json @@ -0,0 +1,10 @@ +{ + "list_info": { + "page": 1, + "num_pages": 1, + "num_results": 1, + "page_size": 20 + }, + "templates": [ + ] +} \ No newline at end of file