Skip to content

Commit 005d561

Browse files
author
Chris Paul
authored
Merge pull request hellosign#50 from HelloFax/issue-49
Add new callback event types.
2 parents 8b9c961 + 5e214d0 commit 005d561

2 files changed

Lines changed: 40 additions & 14 deletions

File tree

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
import org.json.JSONException;
3535
import org.json.JSONObject;
36+
import org.slf4j.Logger;
37+
import org.slf4j.LoggerFactory;
3638

3739
import com.hellosign.sdk.HelloSignException;
3840
import com.hellosign.sdk.resource.support.Signature;
@@ -46,6 +48,8 @@
4648
*/
4749
public class Event extends AbstractResource {
4850

51+
private static final Logger logger = LoggerFactory.getLogger(Event.class);
52+
4953
public static final String EVENT_KEY = "event";
5054
public static final String EVENT_METADATA = "event_metadata";
5155
public static final String REPORTED_FOR_ACCOUNT_ID = "reported_for_account_id";
@@ -70,21 +74,17 @@ public class Event extends AbstractResource {
7074
*/
7175
public Event(JSONObject json) throws HelloSignException {
7276
super(json, EVENT_KEY);
73-
if (EventType.test.equals(getType())) {
74-
return;
75-
}
76-
if (json.has(SignatureRequest.SIGREQ_KEY)) {
77-
try {
78-
resource = new SignatureRequest(json.getJSONObject(SignatureRequest.SIGREQ_KEY));
79-
} catch (JSONException ex) {
80-
throw new HelloSignException(ex);
77+
try {
78+
if (EventType.test.equals(getType())) {
79+
return;
8180
}
82-
} else if (json.has(Template.TEMPLATE_KEY)) {
83-
try {
81+
if (json.has(SignatureRequest.SIGREQ_KEY)) {
82+
resource = new SignatureRequest(json.getJSONObject(SignatureRequest.SIGREQ_KEY));
83+
} else if (json.has(Template.TEMPLATE_KEY)) {
8484
resource = new Template(json.getJSONObject(Template.TEMPLATE_KEY));
85-
} catch (JSONException ex) {
86-
throw new HelloSignException(ex);
8785
}
86+
} catch (JSONException ex) {
87+
throw new HelloSignException(ex);
8888
}
8989
}
9090

@@ -277,7 +277,14 @@ public boolean hasTemplate() {
277277
* @return EventType enum
278278
*/
279279
public EventType getType() {
280-
return EventType.valueOf(getTypeString());
280+
String typeStr = getTypeString();
281+
EventType type = null;
282+
try {
283+
type = EventType.valueOf(typeStr);
284+
} catch (Exception ex) {
285+
logger.warn("Unexpected type: " + typeStr);
286+
}
287+
return type;
281288
}
282289

283290
/**

src/main/java/com/hellosign/sdk/resource/support/types/EventType.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,24 @@
2525
*/
2626

2727
public enum EventType {
28-
signature_request_viewed, signature_request_signed, signature_request_sent, signature_request_all_signed, signature_request_invalid, signature_request_remind, signature_request_destroyed, signature_request_canceled, signature_request_declined, account_confirmed, template_created, template_error, file_error, test, callback_test, unknown_error, sign_url_invalid, signature_request_email_bounce
28+
signature_request_viewed,
29+
signature_request_signed,
30+
signature_request_sent,
31+
signature_request_all_signed,
32+
signature_request_invalid,
33+
signature_request_remind,
34+
signature_request_destroyed,
35+
signature_request_canceled,
36+
signature_request_declined,
37+
account_confirmed,
38+
template_created,
39+
template_error,
40+
file_error,
41+
test,
42+
callback_test,
43+
unknown_error,
44+
sign_url_invalid,
45+
signature_request_email_bounce,
46+
signature_request_downloadable,
47+
signature_request_delegated
2948
}

0 commit comments

Comments
 (0)