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

Commit c828d67

Browse files
author
Chris Paul
committed
Add support for API app CRUD. Add tests. Update documentation.
1 parent b23dbed commit c828d67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+768
-83
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (C) 2014 hellosign.com
3+
Copyright (C) 2015 hellosign.com
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ https://www.github.com/cmpaul/jellosign -->
105105
```
106106
The MIT License (MIT)
107107
108-
Copyright (C) 2014 hellosign.com
108+
Copyright (C) 2015 hellosign.com
109109
110110
Permission is hereby granted, free of charge, to any person obtaining a copy
111111
of this software and associated documentation files (the "Software"), to deal

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>com.hellosign</groupId>
77
<artifactId>hellosign-java-sdk</artifactId>
88
<packaging>jar</packaging>
9-
<version>3.1.8</version>
9+
<version>3.2.0</version>
1010
<name>HelloSign Java SDK</name>
1111
<url>https://github.com/HelloFax/hellosign-java-sdk</url>
1212
<properties>

src/main/java/com/hellosign/sdk/HelloSignClient.java

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* The MIT License (MIT)
55
*
6-
* Copyright (C) 2014 hellosign.com
6+
* Copyright (C) 2015 hellosign.com
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the "Software"), to deal
@@ -45,11 +45,14 @@
4545
import org.json.JSONObject;
4646

4747
import com.hellosign.sdk.http.Authentication;
48+
import com.hellosign.sdk.http.HttpDeleteRequest;
4849
import com.hellosign.sdk.http.HttpGetRequest;
4950
import com.hellosign.sdk.http.HttpPostRequest;
51+
import com.hellosign.sdk.http.HttpPutRequest;
5052
import com.hellosign.sdk.resource.AbstractRequest;
5153
import com.hellosign.sdk.resource.AbstractResourceList;
5254
import com.hellosign.sdk.resource.Account;
55+
import com.hellosign.sdk.resource.ApiApp;
5356
import com.hellosign.sdk.resource.EmbeddedRequest;
5457
import com.hellosign.sdk.resource.EmbeddedResponse;
5558
import com.hellosign.sdk.resource.SignatureRequest;
@@ -58,6 +61,7 @@
5861
import com.hellosign.sdk.resource.TemplateDraft;
5962
import com.hellosign.sdk.resource.TemplateSignatureRequest;
6063
import com.hellosign.sdk.resource.UnclaimedDraft;
64+
import com.hellosign.sdk.resource.support.ApiAppList;
6165
import com.hellosign.sdk.resource.support.OauthData;
6266
import com.hellosign.sdk.resource.support.SignatureRequestList;
6367
import com.hellosign.sdk.resource.support.TemplateList;
@@ -127,6 +131,8 @@ public class HelloSignClient {
127131
private String URL_UNCLAIMED_DRAFT_CREATE;
128132
private String URL_UNCLAIMED_DRAFT_CREATE_EMBEDDED;
129133
private String URL_UNCLAIMED_DRAFT_CREATE_EMBEDDED_WITH_TEMPLATE;
134+
private String URL_API_APP;
135+
private String URL_API_APP_LIST;
130136

131137
private String URL_PARAM_FILE_TYPE = "file_type";
132138

@@ -197,6 +203,8 @@ private void initApiEndpoints() {
197203
URL_UNCLAIMED_DRAFT_CREATE = URL_API + "/unclaimed_draft/create";
198204
URL_UNCLAIMED_DRAFT_CREATE_EMBEDDED = URL_API + "/unclaimed_draft/create_embedded";
199205
URL_UNCLAIMED_DRAFT_CREATE_EMBEDDED_WITH_TEMPLATE = URL_API + "/unclaimed_draft/create_embedded_with_template";
206+
URL_API_APP = URL_API + "/api_app";
207+
URL_API_APP_LIST = URL_API_APP + "/list";
200208
}
201209

202210
/**
@@ -858,6 +866,63 @@ public TemplateDraft createEmbeddedTemplateDraft(EmbeddedRequest req)
858866
}
859867
}
860868

869+
/**
870+
* Retrieves the API app configuration for the given Client ID.
871+
* @param clientId String
872+
* @return ApiApp
873+
* @throws HelloSignException
874+
*/
875+
public ApiApp getApiApp(String clientId) throws HelloSignException {
876+
HttpGetRequest request = new HttpGetRequest(URL_API_APP + "/" + clientId, auth);
877+
return new ApiApp(request.getJsonResponse());
878+
}
879+
880+
/**
881+
* Retrieves a paged list of API apps for the authenticated account.
882+
* @return ApiAppList
883+
* @throws HelloSignException
884+
*/
885+
public ApiAppList getApiApps() throws HelloSignException {
886+
HttpGetRequest request = new HttpGetRequest(URL_API_APP_LIST, auth);
887+
return new ApiAppList(request.getJsonResponse());
888+
}
889+
890+
/**
891+
* Creates a new ApiApp using the properties set on the provided ApiApp.
892+
* @param app ApiApp
893+
* @return ApiApp newly created ApiApp
894+
* @throws HelloSignException
895+
*/
896+
public ApiApp createApiApp(ApiApp app) throws HelloSignException {
897+
HttpPostRequest request = new HttpPostRequest(URL_API_APP, app.getPostFields(), auth);
898+
return new ApiApp(request.getJsonResponse());
899+
}
900+
901+
/**
902+
* Attempts to delete the API app with the given client ID.
903+
* @param clientId String The Client ID of the app that should be deleted.
904+
* @return boolean true if the API app was successfully deleted
905+
* @throws HelloSignException
906+
*/
907+
public boolean deleteApiApp(String clientId) throws HelloSignException {
908+
HttpDeleteRequest request = new HttpDeleteRequest(URL_API_APP + "/" + clientId, auth);
909+
return HttpURLConnection.HTTP_NO_CONTENT == request.getHttpResponseCode();
910+
}
911+
912+
/**
913+
* Updates the API app with the given ApiApp object properties.
914+
* @param app ApiApp
915+
* @return ApiApp updated ApiApp
916+
* @throws HelloSignException
917+
*/
918+
public ApiApp updateApiApp(ApiApp app) throws HelloSignException {
919+
if (!app.hasClientId()) {
920+
throw new HelloSignException("Cannot update an ApiApp without a client ID. Create one first!");
921+
}
922+
HttpPutRequest request = new HttpPutRequest(URL_API_APP, app.getPostFields(), auth);
923+
return new ApiApp(request.getJsonResponse());
924+
}
925+
861926
/**
862927
* Performs a simple call to the HelloSign API to see if it's available
863928
* with the given credentials.

src/main/java/com/hellosign/sdk/HelloSignException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* The MIT License (MIT)
55
*
6-
* Copyright (C) 2014 hellosign.com
6+
* Copyright (C) 2015 hellosign.com
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the "Software"), to deal

src/main/java/com/hellosign/sdk/http/AbstractHttpRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* The MIT License (MIT)
55
*
6-
* Copyright (C) 2014 hellosign.com
6+
* Copyright (C) 2015 hellosign.com
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the "Software"), to deal

src/main/java/com/hellosign/sdk/http/Authentication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* The MIT License (MIT)
55
*
6-
* Copyright (C) 2014 hellosign.com
6+
* Copyright (C) 2015 hellosign.com
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the "Software"), to deal

src/main/java/com/hellosign/sdk/http/HttpGetRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* The MIT License (MIT)
55
*
6-
* Copyright (C) 2014 hellosign.com
6+
* Copyright (C) 2015 hellosign.com
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the "Software"), to deal
@@ -157,6 +157,7 @@ private static HttpURLConnection get(String url,
157157
logger.debug("GET: " + url);
158158
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
159159
connection.setRequestProperty("Accept-Charset", DEFAULT_ENCODING);
160+
connection.setRequestProperty("user-agent", USER_AGENT);
160161
if (auth != null) {
161162
logger.debug("Authenticating...");
162163
auth.authenticate(connection, url);

src/main/java/com/hellosign/sdk/http/HttpPostRequest.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* The MIT License (MIT)
55
*
6-
* Copyright (C) 2014 hellosign.com
6+
* Copyright (C) 2015 hellosign.com
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the "Software"), to deal
@@ -57,6 +57,8 @@ public class HttpPostRequest extends AbstractHttpRequest {
5757
private final String boundary;
5858
private static final String LINE_FEED = "\r\n";
5959

60+
protected String method = "POST";
61+
6062
private HttpURLConnection httpConn;
6163
private OutputStream outputStream;
6264
private PrintWriter writer;
@@ -106,7 +108,7 @@ public JSONObject getJsonResponse() throws HelloSignException {
106108
try {
107109
int httpCode = connection.getResponseCode();
108110
InputStream response = null;
109-
if (httpCode == HttpURLConnection.HTTP_OK) {
111+
if (httpCode >= 200 && httpCode < 300) {
110112
logger.debug("OK!");
111113
response = connection.getInputStream();
112114
} else {
@@ -123,6 +125,8 @@ public JSONObject getJsonResponse() throws HelloSignException {
123125
validate(json, httpCode);
124126
logger.debug("JSON Response: " + json.toString(2));
125127
}
128+
} catch (HelloSignException e) {
129+
throw e;
126130
} catch (Exception e) {
127131
throw new HelloSignException(e);
128132
}
@@ -156,14 +160,18 @@ private HttpURLConnection post() throws HelloSignException {
156160
}
157161

158162
private HttpURLConnection postQuery() throws HelloSignException {
159-
logger.debug("POST: " + url);
163+
logger.debug(this.method + ": " + url);
160164
HttpURLConnection connection;
161165
try {
162166
connection = (HttpURLConnection) new URL(url).openConnection();
167+
if (!this.method.equals("POST")) {
168+
connection.setRequestMethod(method);
169+
}
163170
} catch (Exception e) {
164171
throw new HelloSignException(e);
165172
}
166173
connection.setDoOutput(true); // sets POST method
174+
167175
connection.setRequestProperty("user-agent", USER_AGENT);
168176
connection.setRequestProperty("accept-encoding", DEFAULT_ENCODING);
169177
auth.authenticate(connection, url);

src/main/java/com/hellosign/sdk/resource/AbstractRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* The MIT License (MIT)
55
*
6-
* Copyright (C) 2014 hellosign.com
6+
* Copyright (C) 2015 hellosign.com
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)