Skip to content

Commit 0af844b

Browse files
author
Chris Paul
committed
Changes requested by Jon
1 parent 779418b commit 0af844b

4 files changed

Lines changed: 29 additions & 213 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>com.hellosign</groupId>
66
<artifactId>hellosign-java-sdk</artifactId>
77
<packaging>jar</packaging>
8-
<version>3.6.0</version>
8+
<version>4.0.0</version>
99
<name>HelloSign Java SDK</name>
1010
<url>https://github.com/HelloFax/hellosign-java-sdk</url>
1111
<properties>

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

Lines changed: 22 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class HelloSignClient {
6868

6969
public static final String DEFAULT_ENCODING = "UTF-8";
7070
public static final String DEFAULT_BASE_API_URL = "https://api.hellosign.com/v3";
71-
public static final String DEFAULT_OAUTH_TOKEN_URL = "https://www.hellosign.com/oauth/token";
71+
public static final String DEFAULT_OAUTH_TOKEN_URL = "https://app.hellosign.com/oauth/token";
7272

7373
public static final String ACCOUNT_URI = "/account";
7474
public static final String VALIDATE_ACCOUNT_URI = "/account/validate";
@@ -135,14 +135,13 @@ public class HelloSignClient {
135135
private String OAUTH_TOKEN_URL;
136136

137137
/**
138-
* Default constructor that allows the injection of an HttpClient.
139-
*
140-
* In most cases, you should use the constructor that accepts your API key:
138+
* Default constructor for injection of dependencies (testing).
141139
*
142140
* @see #HelloSignClient(String)
143141
*/
144-
public HelloSignClient() {
145-
setHttpClient(new HttpClient());
142+
protected HelloSignClient(HttpClient client, Authentication auth) {
143+
this.httpClient = client;
144+
this.auth = auth;
146145

147146
// Set overrides if present
148147
BASE_URI = DEFAULT_BASE_API_URL;
@@ -168,71 +167,20 @@ public HelloSignClient() {
168167
* Settings</a>
169168
*/
170169
public HelloSignClient(String apiKey) throws HelloSignException {
171-
this();
172-
Authentication a = new Authentication();
173-
a.setApiKey(apiKey);
174-
setAuth(a);
175-
}
176-
177-
/**
178-
* Creates a new HelloSign client using your website account's email address
179-
* and password.
180-
*
181-
* @param email String email
182-
* @param password String password
183-
* @throws HelloSignException thrown if there is a problem setting the
184-
* credentials
185-
* @deprecated Use {@link #HelloSignClient(String)} instead.
186-
*/
187-
public HelloSignClient(String email, String password) throws HelloSignException {
188-
this();
189-
Authentication a = new Authentication();
190-
a.setWebsiteCredentials(email, password);
191-
setAuth(a);
192-
}
193-
194-
/**
195-
* Create a client with the provided authentication object.
196-
*
197-
* @param auth HelloSignAuthentication
198-
* @throws HelloSignException thrown if the HelloSignAuthentication
199-
* parameters are invalid or null
200-
*/
201-
public HelloSignClient(Authentication auth) throws HelloSignException {
202-
this();
203-
setAuth(auth);
204-
}
205-
206-
/**
207-
* Stores the Authentication that should be used for HTTP requests against
208-
* the HelloSign API.
209-
*
210-
* @param auth Authentication
211-
* @throws HelloSignException thrown if there's a problem initializing the
212-
* authentication credentials
213-
*/
214-
public void setAuth(Authentication auth) throws HelloSignException {
215-
this.auth = new Authentication(auth);
170+
this(new HttpClient(), new Authentication(apiKey));
171+
auth.setApiKey(apiKey);
216172
}
217173

218174
/**
219-
* Retrieves the authentication details being used by this client.
175+
* Retrieves the authentication details being used by this client. Used for
176+
* testing purposes.
220177
*
221178
* @return Authentication
222179
*/
223-
public Authentication getAuth() {
180+
protected Authentication getAuth() {
224181
return auth;
225182
}
226183

227-
/**
228-
* Set the HttpClient that should be used for HTTP requests.
229-
*
230-
* @param client HttpClient
231-
*/
232-
public void setHttpClient(HttpClient client) {
233-
httpClient = client;
234-
}
235-
236184
/**
237185
* Returns the current user's account information.
238186
*
@@ -250,24 +198,23 @@ public Account getAccount() throws HelloSignException {
250198
*
251199
* @param email String email address
252200
* @return true if the account exists, false otherwise
201+
* @throws HelloSignException Thrown if there's a problem communicating with
202+
* the HelloSign API.
253203
*/
254-
public boolean isAccountValid(String email) {
255-
boolean isValid = false;
256-
if (email != null && !email.isEmpty()) {
257-
try {
258-
Account account = new Account(
259-
httpClient.withAuth(auth).withPostField(Account.ACCOUNT_EMAIL_ADDRESS, email)
260-
.post(BASE_URI + VALIDATE_ACCOUNT_URI).asJson());
261-
isValid = (account.hasEmail() && email.equalsIgnoreCase(account.getEmail()));
262-
} catch (HelloSignException ex) {
263-
// Ignore
264-
}
204+
public boolean isAccountValid(String email) throws HelloSignException {
205+
if (email == null || email.isEmpty()) {
206+
return false;
265207
}
266-
return isValid;
208+
Account account = new Account(httpClient.withAuth(auth).withPostField(Account.ACCOUNT_EMAIL_ADDRESS, email)
209+
.post(BASE_URI + VALIDATE_ACCOUNT_URI).asJson());
210+
return (account.hasEmail() && email.equalsIgnoreCase(account.getEmail()));
267211
}
268212

269213
/**
270-
* Updates the current user's callback URL.
214+
* Update your account callback URL.
215+
*
216+
* This URL is used to notify you of any signature request events that occur
217+
* when your account is a party -- e.g., sender or signer/recipient.
271218
*
272219
* @param callback String URL
273220
* @return Account
@@ -294,24 +241,6 @@ public Account createAccount(String email) throws HelloSignException {
294241
return createAccount(email, null, null);
295242
}
296243

297-
/**
298-
* Creates a new HelloSign account. The user will still need to validate
299-
* their email address to complete the creation process.
300-
*
301-
* Note: This request does not require authentication, so just performs the
302-
* basic POST.
303-
*
304-
* @param email String New user's email address
305-
* @param password String New user's password
306-
* @return Account New user's account information
307-
* @throws HelloSignException thrown if there's a problem processing the
308-
* HTTP request or the JSON response.
309-
* @deprecated as of 3.1.1, replaced by {@link #createAccount(String)}
310-
*/
311-
public Account createAccount(String email, String password) throws HelloSignException {
312-
return createAccount(email, password, null, null);
313-
}
314-
315244
/**
316245
* Creates a new HelloSign account and provides OAuth app credentials to
317246
* automatically generate an OAuth token with the user Account response.
@@ -341,68 +270,6 @@ public Account createAccount(String email, String clientId, String clientSecret)
341270
return account;
342271
}
343272

344-
/**
345-
* Creates a new HelloSign account and provides OAuth app credentials to
346-
* automatically generate an OAuth token with the user Account response.
347-
*
348-
* @param email String New user's email address
349-
* @param password String New user's password (NOTE: WILL BE IGNORED BY THE
350-
* API)
351-
* @param clientId String Client ID
352-
* @param clientSecret String App secret
353-
* @return Account New user's account information
354-
* @throws HelloSignException thrown if there's a problem processing the
355-
* HTTP request or the JSON response.
356-
* @deprecated as of 3.1.1, replaced by
357-
* {@link #createAccount(String, String, String)}
358-
*/
359-
public Account createAccount(String email, String password, String clientId, String clientSecret)
360-
throws HelloSignException {
361-
return createAccount(email, clientId, clientSecret);
362-
}
363-
364-
/**
365-
* Performs an OAuth request and returns the necessary data for authorizing
366-
* an API application.
367-
*
368-
* @param code String OAuth code
369-
* @param clientId String OAuth client ID
370-
* @param secret String OAuth secret
371-
* @return OauthData object containing OAuth token details
372-
* @throws HelloSignException thrown if there's a problem processing the
373-
* HTTP request or the JSON response.
374-
* @deprecated Use
375-
* {@link #getOauthData(String, String, String, String, boolean)}
376-
*/
377-
public OauthData getOauthData(String code, String clientId, String secret) throws HelloSignException {
378-
return getOauthData(code, clientId, secret, "demo", false);
379-
}
380-
381-
/**
382-
* Performs an OAuth request and returns the necessary data for authorizing
383-
* an API application, and will automatically set the access token and code
384-
* for making authenticated requests with this client.
385-
*
386-
* NOTE: This method does not provide a state parameter and is deprecated.
387-
* Please update your references to this method as it will be removed in a
388-
* future release.
389-
*
390-
* @param code String OAuth code
391-
* @param clientId String OAuth client ID
392-
* @param secret String OAuth secret
393-
* @param autoSetRequestToken true if the token should be immediately
394-
* applied to this client
395-
* @return OauthData object containing OAuth token details
396-
* @throws HelloSignException thrown if there's a problem processing the
397-
* HTTP request or the JSON response.
398-
* @deprecated Use
399-
* {@link #getOauthData(String, String, String, String, boolean)}
400-
*/
401-
public OauthData getOauthData(String code, String clientId, String secret, boolean autoSetRequestToken)
402-
throws HelloSignException {
403-
return getOauthData(code, clientId, secret, "demo", autoSetRequestToken);
404-
}
405-
406273
/**
407274
* Performs an OAuth request and returns the necessary data for authorizing
408275
* an API application, and will automatically set the access token and code

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

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,17 @@ public class Authentication {
4545

4646
private static final Logger logger = LoggerFactory.getLogger(Authentication.class);
4747

48-
private String email = new String();
49-
private String password = new String();
5048
private String apiKey = new String();
5149
private String accessToken = new String();
5250
private String accessTokenType = new String();
5351

5452
private static final String[] allowedOauthOps = { "account", "signature_request", "reusable_form", "template" };
5553

56-
public Authentication() {
54+
public Authentication(String apiKey) {
55+
this.apiKey = apiKey;
5756
}
5857

5958
public Authentication(Authentication clone) throws HelloSignException {
60-
if (clone.hasWebsiteCredentials()) {
61-
setWebsiteCredentials(clone.getEmail(), clone.getPassword());
62-
}
6359
if (clone.hasApiKey()) {
6460
setApiKey(clone.getApiKey());
6561
}
@@ -68,52 +64,6 @@ public Authentication(Authentication clone) throws HelloSignException {
6864
}
6965
}
7066

71-
/**
72-
* Sets the email and password to use for authenticating the client.
73-
*
74-
* @param email String email address
75-
* @param password String password
76-
* @throws HelloSignException thrown if either the email or password are
77-
* null
78-
*/
79-
public void setWebsiteCredentials(String email, String password) throws HelloSignException {
80-
if (email == null) {
81-
throw new HelloSignException("Email cannot be null");
82-
}
83-
if (password == null) {
84-
throw new HelloSignException("Password cannot be null");
85-
}
86-
this.email = new String(email);
87-
this.password = new String(password);
88-
}
89-
90-
/**
91-
* Returns the email address for this client.
92-
*
93-
* @return String email
94-
*/
95-
public String getEmail() {
96-
return email;
97-
}
98-
99-
/**
100-
* Returns the password for this client.
101-
*
102-
* @return String password
103-
*/
104-
public String getPassword() {
105-
return password;
106-
}
107-
108-
/**
109-
* Returns true if an email and password have been set.
110-
*
111-
* @return true, or false if either are empty
112-
*/
113-
public boolean hasWebsiteCredentials() {
114-
return !("".equals(email) || "".equals(password));
115-
}
116-
11767
/**
11868
* Returns a protected copy of the API key String.
11969
*
@@ -208,13 +158,12 @@ private boolean isOperationOauth(String url) {
208158
public void authenticate(HttpURLConnection httpConn, String url) {
209159
String authorization = null;
210160
if (hasAccessToken() && isOperationOauth(url)) {
161+
logger.debug("Using OAuth token to authenticate");
211162
authorization = getAccessTokenType() + " " + getAccessToken();
212163
} else if (hasApiKey()) {
164+
logger.debug("Using API Key to authenticate");
213165
String apiKey = getApiKey() + ":";
214166
authorization = "Basic " + DatatypeConverter.printBase64Binary(apiKey.getBytes()).trim();
215-
} else if (hasWebsiteCredentials()) {
216-
String authStr = getEmail() + ":" + getPassword();
217-
authorization = "Basic " + DatatypeConverter.printBase64Binary(authStr.getBytes()).trim();
218167
}
219168
if (authorization != null) {
220169
logger.debug("Authorization: " + authorization);

src/test/java/com/hellosign/sdk/HelloSignClientTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.junit.Test;
2121
import org.junit.rules.TestName;
2222

23+
import com.hellosign.sdk.http.Authentication;
2324
import com.hellosign.sdk.http.HttpClient;
2425
import com.hellosign.sdk.resource.AbstractRequest;
2526
import com.hellosign.sdk.resource.Account;
@@ -82,8 +83,7 @@ public class HelloSignClientTest {
8283
@Before
8384
public void setup() throws Exception {
8485
spy = spy(new HttpClient());
85-
client = new HelloSignClient("testapikey");
86-
client.setHttpClient(spy);
86+
client = new HelloSignClient(spy, new Authentication("testapikey"));
8787

8888
// Don't actually make HTTP requests
8989
doReturn(spy).when(spy).post(any(String.class));

0 commit comments

Comments
 (0)