Skip to content
This repository was archived by the owner on Oct 17, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion src/main/java/com/hellosign/sdk/HelloSignClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.hellosign.sdk.resource.AbstractResourceList;
import com.hellosign.sdk.resource.Account;
import com.hellosign.sdk.resource.ApiApp;
import com.hellosign.sdk.resource.BulkSendJobById;
import com.hellosign.sdk.resource.EmbeddedRequest;
import com.hellosign.sdk.resource.EmbeddedResponse;
import com.hellosign.sdk.resource.FileUrlResponse;
Expand All @@ -20,6 +21,7 @@
import com.hellosign.sdk.resource.support.Signature;
import com.hellosign.sdk.resource.support.SignatureRequestList;
import com.hellosign.sdk.resource.support.TemplateList;
import com.hellosign.sdk.resource.support.types.BulkSendJobsList;
import com.hellosign.sdk.resource.support.types.FieldType;
import java.io.File;
import java.lang.reflect.Constructor;
Expand Down Expand Up @@ -80,9 +82,10 @@ public class HelloSignClient {
public static final String UNCLAIMED_DRAFT_CREATE_EMBEDDED_WITH_TEMPLATE_URI = "/unclaimed_draft/create_embedded_with_template";
public static final String API_APP_URI = "/api_app";
public static final String API_APP_LIST_URI = "/api_app/list";
public static final String BULK_SEND_JOBS_LIST = "/bulk_send_job/list";
public static final String BULK_SEND_JOBS = "/bulk_send_job/";
public static final String SIGNATURE_REQUEST_REMOVE_URI = "/signature_request/remove";


public static final String PARAM_FILE_TYPE_URI = "file_type";
public static final String PARAM_GET_URL = "get_url";
public static final String FINAL_COPY_FILE_NAME = "final-copy";
Expand Down Expand Up @@ -1040,6 +1043,61 @@ public void setAccessToken(String accessToken, String tokenType) throws HelloSig
auth.setAccessToken(accessToken, tokenType);
}

/**
* Returns a list of BulkSendJob that you can access.
*
* @return bulkSendJobsList
* @throws HelloSignException thrown if there's a problem processing the HTTP request or the
* JSON response.
*/
public BulkSendJobsList getBulkSendJobList() throws HelloSignException {
return new BulkSendJobsList(httpClient.withAuth(auth).get(BASE_URI + BULK_SEND_JOBS_LIST).asJson());
}

/**
* Retrieves a specific page number of the BulkSendJob List.
*
* @param page int
* @return BulkSendJobsList
* @throws HelloSignException thrown if there's a problem processing the HTTP request or the
* JSON response.
*/
public BulkSendJobsList getBulkSendJobList(int page) throws HelloSignException {
return new BulkSendJobsList(
httpClient.withAuth(auth)
.withGetParam(AbstractResourceList.PAGE, Integer.toString(page))
.get(BASE_URI + BULK_SEND_JOBS_LIST).asJson());
}

/**
* Retrieves a specific page number of the BulkSendJob List, with Number of objects to be returned per page.
* Must be between 1 and 100. Default is 20.
*
* @param page int
* @param pageSize int Must be between 1 and 100.
* @return BulkSendJobsList
* @throws HelloSignException thrown if there's a problem processing the HTTP request or the
* JSON response.
*/
public BulkSendJobsList getBulkSendJobList(int page, int pageSize) throws HelloSignException {
return new BulkSendJobsList(
httpClient.withAuth(auth)
.withGetParam(AbstractResourceList.PAGE, Integer.toString(page))
.withGetParam(AbstractResourceList.PAGE_SIZE, Integer.toString(pageSize))
.get(BASE_URI + BULK_SEND_JOBS_LIST).asJson());
}

/**
* Returns the status of the BulkSendJob and its SignatureRequests specified by the bulk_send_job_id parameter.
* @param bulk_send_job_id
* @return
* @throws HelloSignException
*/
public BulkSendJobById getBulkSendByJobId(String bulk_send_job_id) throws HelloSignException{
String url = BASE_URI + BULK_SEND_JOBS + "/" + bulk_send_job_id;
return new BulkSendJobById(httpClient.withAuth(auth).get(url).asJson());
}

/**
* Removes your access to a completed signature request. This action is not reversible.
*
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/hellosign/sdk/resource/AbstractResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.hellosign.sdk.resource.support.Warning;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -151,6 +152,32 @@ protected <T> List<T> getList(Class<T> clazz, String key) {
return getList(clazz, key, null, null);
}

/**
* Get Type castable object.
* @param Class Pass Class type to be type casted.
* @param obj Provide Object needs to be type casted.
* @param key Key for Object.
* @param <T> Object
* @return
*/
protected <T> Object getObject(Class<T> Class, Object obj, String key){

Constructor<?> constructor = getConstructor(Class, obj.getClass());

@SuppressWarnings("unchecked")
T newItem = null;
try {
newItem = (T) constructor.newInstance(dataObj.get(key));
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return newItem;
}

protected <T> List<T> getList(Class<T> clazz, String key, Serializable filterValue,
String filterColumnName) {
List<T> returnList = new ArrayList<>();
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/com/hellosign/sdk/resource/BulkSendJobById.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.hellosign.sdk.resource;

import com.hellosign.sdk.HelloSignException;
import org.json.JSONObject;

import java.util.List;

/**
* Returns the status of the BulkSendJob and its SignatureRequests specified by the bulk_send_job_id parameter.
* Response for GET /bulk_send_job/[:bulk_send_job_id] gives bulk_send_job, list_info and signature_requests.
*/
public class BulkSendJobById extends AbstractResource {

public static final String BULKSENDJOB = "bulk_send_job";
public static final String BULKSENDBYJOBID = "bulk_send_job_id";
public static final String LIST_INFO = "list_info";
public static final String SIGNATURE_REQUESTS = "signature_requests";

public BulkSendJobById(){
super();
}

public BulkSendJobById(JSONObject json) throws HelloSignException{
super(json,BULKSENDBYJOBID);
}

/**
* Get bulk_send_job Object.
* @return
* @throws Exception
*/
public BulkSendJobs getBulkSendJob() throws Exception{
return (BulkSendJobs) getObject(BulkSendJobs.class, dataObj.get(BULKSENDJOB), BULKSENDJOB);
}

/**
* Get list_info Object.
* @return
*/
public Object getListInfo() {
return getJSONObject().get(LIST_INFO);
}

/**
* Get List of signature_requests.
* @return
*/
public List<SignatureRequest> getSignatureRequests(){
return getList(SignatureRequest.class, SIGNATURE_REQUESTS);
}
}
55 changes: 55 additions & 0 deletions src/main/java/com/hellosign/sdk/resource/BulkSendJobs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.hellosign.sdk.resource;

import com.hellosign.sdk.HelloSignException;
import org.json.JSONObject;

import java.util.Date;

public class BulkSendJobs extends AbstractResource {

public static final String BULKSENDJOB_ID = "bulk_send_job_id";
public static final String BULKSENDJOB_TOTAL = "total";
public static final String BULKSENDJOB_ISCREATOR = "is_creator";
public static final String BULKSENDJOB_CREATEDAT = "created_at";
public static final String BULKSENDJOB = "bulk_send_job";

public BulkSendJobs(){
super();
}

public BulkSendJobs(JSONObject jsonObject)throws HelloSignException{
super(jsonObject, BULKSENDJOB);
}

/**
* Get Bulk send job id.
* @return
*/
public String getBulkSendJobId() {
return getString(BULKSENDJOB_ID);
}

/**
* Get Bulk send job total.
* @return
*/
public String getBulkSendJobTotal() {
return getString(BULKSENDJOB_TOTAL);
}

/**
* Get Bulk send job is Creator.
* @return
*/
public Boolean getBulkSendJobIsCreator() {
return getBoolean(BULKSENDJOB_ISCREATOR);
}

/**
* Get Bulk send job created at.
* @return
*/
public Date getBulkSendJobCreatedAt() {
return getDate(BULKSENDJOB_CREATEDAT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.hellosign.sdk.resource.support.types;

import com.hellosign.sdk.HelloSignException;
import com.hellosign.sdk.resource.AbstractResourceList;
import com.hellosign.sdk.resource.BulkSendJobs;
import org.json.JSONObject;

public class BulkSendJobsList extends AbstractResourceList<BulkSendJobs> {

public static final String BULK_SEND_JOBS = "bulk_send_jobs";

public BulkSendJobsList(JSONObject json) throws HelloSignException {
super(json, BULK_SEND_JOBS);
}
}
85 changes: 85 additions & 0 deletions src/test/java/com/hellosign/sdk/HelloSignClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.hellosign.sdk.resource.AbstractRequest;
import com.hellosign.sdk.resource.Account;
import com.hellosign.sdk.resource.ApiApp;
import com.hellosign.sdk.resource.BulkSendJobs;
import com.hellosign.sdk.resource.BulkSendJobById;
import com.hellosign.sdk.resource.EmbeddedRequest;
import com.hellosign.sdk.resource.EmbeddedResponse;
import com.hellosign.sdk.resource.SignatureRequest;
Expand All @@ -36,6 +38,7 @@
import com.hellosign.sdk.resource.support.TemplateRole;
import com.hellosign.sdk.resource.support.WhiteLabelingOptions;
import com.hellosign.sdk.resource.support.Attachment;
import com.hellosign.sdk.resource.support.types.BulkSendJobsList;
import com.hellosign.sdk.resource.support.types.FieldType;
import com.hellosign.sdk.resource.support.types.UnclaimedDraftType;
import java.io.File;
Expand Down Expand Up @@ -1116,6 +1119,88 @@ public void testRemovingSignersByEmail() throws HelloSignException {
Assert.assertEquals(0, set.size());
}

/**
* Test for Get bulk send job list.
* @throws Exception
*/
@Test
public void testGetBulkSendJobList() throws Exception {
BulkSendJobsList bulkSendJobList = client.getBulkSendJobList();
Assert.assertEquals(bulkSendJobList.getPage().toString(), "1");
Assert.assertEquals(bulkSendJobList.getNumPages().toString(), "1");
Assert.assertEquals(bulkSendJobList.getNumResults().toString(), "3");
Assert.assertEquals(bulkSendJobList.getPageSize().toString(), "20");

for(BulkSendJobs bulkSendJob : bulkSendJobList){
assertNotNull(bulkSendJob.getBulkSendJobId());
Assert.assertEquals(bulkSendJob.getBulkSendJobTotal().toString(),"2");
Assert.assertEquals(bulkSendJob.getBulkSendJobIsCreator(), true);
assertNotNull(bulkSendJob.getBulkSendJobCreatedAt());
}
}

/**
* Test for Get bulk send job list with Page.
* @throws Exception
*/
@Test
public void testGetBulkSendJobListWithPage() throws Exception {
BulkSendJobsList bulkSendJobList = client.getBulkSendJobList(1);
Assert.assertEquals(bulkSendJobList.getPage().toString(), "1");
Assert.assertEquals(bulkSendJobList.getNumPages().toString(), "1");
Assert.assertEquals(bulkSendJobList.getNumResults().toString(), "3");
Assert.assertEquals(bulkSendJobList.getPageSize().toString(), "20");

for(BulkSendJobs bulkSendJob : bulkSendJobList){
assertNotNull(bulkSendJob.getBulkSendJobId());
Assert.assertEquals(bulkSendJob.getBulkSendJobTotal().toString(),"2");
Assert.assertEquals(bulkSendJob.getBulkSendJobIsCreator(), true);
assertNotNull(bulkSendJob.getBulkSendJobCreatedAt());
}
}

/**
* Test for Get bulk send job list with Page and Page size.
* @throws Exception
*/
@Test
public void testGetBulkSendJobListWithPageAndSize() throws Exception {
BulkSendJobsList bulkSendJobList = client.getBulkSendJobList(1,15);
Assert.assertEquals(bulkSendJobList.getPage().toString(), "1");
Assert.assertEquals(bulkSendJobList.getNumPages().toString(), "1");
Assert.assertEquals(bulkSendJobList.getNumResults().toString(), "3");
Assert.assertEquals(bulkSendJobList.getPageSize().toString(), "15");

for(BulkSendJobs bulkSendJob : bulkSendJobList){
assertNotNull(bulkSendJob.getBulkSendJobId());
Assert.assertEquals(bulkSendJob.getBulkSendJobTotal().toString(),"2");
Assert.assertEquals(bulkSendJob.getBulkSendJobIsCreator(), true);
assertNotNull(bulkSendJob.getBulkSendJobCreatedAt());
}
}

/**
* Test for Get bulk send job by id.
* @throws Exception
*/
@Test
public void testGetBulkSendJobById() throws Exception {
String testBulkSendJobId = "eb05b91f81570b2558b4f343a98a91386da3a848";
String testSignatureRequestId = "9abf3a388188314702370cde71a079863b3fb4ed";
BulkSendJobById bulkSendJobId = client.getBulkSendByJobId(testBulkSendJobId);

assertNotNull(bulkSendJobId);
assertNotNull(bulkSendJobId.getListInfo());
assertNotNull(bulkSendJobId.getBulkSendJob());
assertNotNull(bulkSendJobId.getSignatureRequests());

BulkSendJobs bulkSendJob = bulkSendJobId.getBulkSendJob();
Assert.assertEquals(bulkSendJob.getBulkSendJobId(), testBulkSendJobId);

List<SignatureRequest> signatureRequests = bulkSendJobId.getSignatureRequests();
Assert.assertEquals(signatureRequests.get(0).getId(), testSignatureRequestId);
}

/**
* Test to verify Remove your access to a completed signature request.
* @throws Exception
Expand Down
Loading