@@ -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
0 commit comments