Skip to content

Commit

Permalink
Working on sample code for webhook event parsing. It is a work in pro…
Browse files Browse the repository at this point in the history
…gress.
  • Loading branch information
Chris Wilson committed May 31, 2017
1 parent d99d1f8 commit 0f60a52
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.json.JSONArray;
import org.json.JSONObject;

import com.google.gson.Gson;
import com.sparkpost.model.webhook.event.AbstractWebhookEvent;
import com.sparkpost.model.webhook.event.BounceEvent;
import com.sparkpost.model.webhook.event.ClickEvent;
Expand All @@ -32,11 +31,14 @@
import com.sparkpost.model.webhook.event.SpamComplaintEvent;
import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp;

/**
* NOTE: Webhook events are experimental code and are subject to change.
*/
@SuppressWarnings("rawtypes")
public class WebhookDecoderSample extends SparkPostBaseApp {

private final static Map<String, Class> classMap;
private static final Gson GSON = new Gson();
//private static final Gson GSON = new Gson();

public WebhookDecoderSample() {

Expand All @@ -49,10 +51,10 @@ public static void main(String[] args) {

List<AbstractWebhookEvent> events = decoder.decodeEvents(json);

System.out.println("Found " + events.size() + " events.");
System.out.println("Found " + events.size() + " events:");

for (AbstractWebhookEvent event : events) {
System.out.println("\t " + event.getType());
System.out.println("\t " + event.getType() + " - " + event.getClass().getSimpleName());
}

}
Expand Down Expand Up @@ -86,9 +88,8 @@ public List<AbstractWebhookEvent> decodeEvents(String json) {
continue;
}

@SuppressWarnings("unchecked")
AbstractWebhookEvent eventObj = GSON.fromJson(eventData.toString(), c);
webhookEvents.add(eventObj);
//AbstractWebhookEvent eventObj = GSON.fromJson(eventData.toString(), c);
//webhookEvents.add(eventObj);

}

Expand Down

0 comments on commit 0f60a52

Please sign in to comment.