From 662b101a36ae19a7ca0208e64e402f4489470698 Mon Sep 17 00:00:00 2001 From: sethgrid Date: Thu, 20 Apr 2023 12:52:08 -0400 Subject: [PATCH] provide examples and test coverage for new multiple webhooks support --- .gitignore | 1 + USAGE.md | 8 ++-- examples/user/GetWebhookEventSettings.java | 2 +- examples/user/UpdateWebhookEventSettings.java | 2 +- src/test/java/com/sendgrid/SendGridTest.java | 38 +++++++++++++++++++ 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 12b0a405..2d699749 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ examples/Example.java sendgrid-java.jar dependency-reduced-pom.xml prism* +sendgrid.env diff --git a/USAGE.md b/USAGE.md index e5b3e1d2..c8cfce13 100644 --- a/USAGE.md +++ b/USAGE.md @@ -6126,7 +6126,7 @@ Twilio SendGrid's Event Webhook will notify a URL of your choice via HTTP POST w Common uses of this data are to remove unsubscribes, react to spam reports, determine unengaged recipients, identify bounced email addresses, or create advanced analytics of your email program. -### PATCH /user/webhooks/event/settings +### PATCH /user/webhooks/event/settings/{id} ```java @@ -6134,7 +6134,7 @@ Common uses of this data are to remove unsubscribes, react to spam reports, dete SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.PATCH); - request.setEndpoint("user/webhooks/event/settings"); + request.setEndpoint("user/webhooks/event/settings/{id}"); request.setBody("{\"group_resubscribe\":true,\"delivered\":true,\"group_unsubscribe\":true,\"spam_report\":true,\"url\":\"url\)",\"enabled\":true,\"bounce\":true,\"deferred\":true,\"unsubscribe\":true,\"dropped\":true,\"open\":true,\"click\":true,\"processed\":true}"); Response response = sg.api(request); System.out.println(response.getStatusCode()); @@ -6154,7 +6154,7 @@ Twilio SendGrid's Event Webhook will notify a URL of your choice via HTTP POST w Common uses of this data are to remove unsubscribes, react to spam reports, determine unengaged recipients, identify bounced email addresses, or create advanced analytics of your email program. -### GET /user/webhooks/event/settings +### GET /user/webhooks/event/settings/{id} ```java @@ -6162,7 +6162,7 @@ Common uses of this data are to remove unsubscribes, react to spam reports, dete SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.GET); - request.setEndpoint("user/webhooks/event/settings"); + request.setEndpoint("user/webhooks/event/settings/{id}"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); diff --git a/examples/user/GetWebhookEventSettings.java b/examples/user/GetWebhookEventSettings.java index fe1561c5..a2b1051a 100644 --- a/examples/user/GetWebhookEventSettings.java +++ b/examples/user/GetWebhookEventSettings.java @@ -9,7 +9,7 @@ public static void main(String[] args) throws IOException { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.GET); - request.setEndpoint("user/webhooks/event/settings"); + request.setEndpoint("user/webhooks/event/settings/{id}"); Response response = sg.api(request); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); diff --git a/examples/user/UpdateWebhookEventSettings.java b/examples/user/UpdateWebhookEventSettings.java index 13b61488..70b69c3e 100644 --- a/examples/user/UpdateWebhookEventSettings.java +++ b/examples/user/UpdateWebhookEventSettings.java @@ -9,7 +9,7 @@ public static void main(String[] args) throws IOException { SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); Request request = new Request(); request.setMethod(Method.PATCH); - request.setEndpoint("user/webhooks/event/settings"); + request.setEndpoint("user/webhooks/event/settings/{id}"); request.setBody("{\"group_resubscribe\":true,\"delivered\":true,\"group_unsubscribe\":true,\"spam_report\":true,\"url\":\"url\",\"enabled\":true,\"bounce\":true,\"deferred\":true,\"unsubscribe\":true,\"dropped\":true,\"open\":true,\"click\":true,\"processed\":true}"); Response response = sg.api(request); System.out.println(response.getStatusCode()); diff --git a/src/test/java/com/sendgrid/SendGridTest.java b/src/test/java/com/sendgrid/SendGridTest.java index 2ac11fdb..6b9c44d5 100644 --- a/src/test/java/com/sendgrid/SendGridTest.java +++ b/src/test/java/com/sendgrid/SendGridTest.java @@ -2703,6 +2703,19 @@ public void test_user_webhooks_event_settings_patch() throws IOException { SendGrid sg = new SendGrid("SENDGRID_API_KEY"); sg.addRequestHeader("X-Mock", "200"); + Request request = new Request(); + request.setMethod(Method.PATCH); + request.setEndpoint("user/webhooks/event/settings/{id}"); + request.setBody("{\"group_resubscribe\":true,\"delivered\":true,\"group_unsubscribe\":true,\"spam_report\":true,\"url\":\"url\",\"enabled\":true,\"bounce\":true,\"deferred\":true,\"unsubscribe\":true,\"dropped\":true,\"open\":true,\"click\":true,\"processed\":true}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_webhooks_event_settings_patch_legacy_no_id() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + Request request = new Request(); request.setMethod(Method.PATCH); request.setEndpoint("user/webhooks/event/settings"); @@ -2716,6 +2729,18 @@ public void test_user_webhooks_event_settings_get() throws IOException { SendGrid sg = new SendGrid("SENDGRID_API_KEY"); sg.addRequestHeader("X-Mock", "200"); + Request request = new Request(); + request.setMethod(Method.GET); + request.setEndpoint("user/webhooks/event/settings/{id}"); + Response response = sg.api(request); + Assert.assertEquals(200, response.getStatusCode()); + } + + @Test + public void test_user_webhooks_event_settings_get_legacy_no_id() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "200"); + Request request = new Request(); request.setMethod(Method.GET); request.setEndpoint("user/webhooks/event/settings"); @@ -2728,6 +2753,19 @@ public void test_user_webhooks_event_test_post() throws IOException { SendGrid sg = new SendGrid("SENDGRID_API_KEY"); sg.addRequestHeader("X-Mock", "204"); + Request request = new Request(); + request.setMethod(Method.POST); + request.setEndpoint("user/webhooks/event/test"); + request.setBody("{\"url\":\"url\", \"id\":\"id\"}"); + Response response = sg.api(request); + Assert.assertEquals(204, response.getStatusCode()); + } + + @Test + public void test_user_webhooks_event_test_post_legacy_no_id() throws IOException { + SendGrid sg = new SendGrid("SENDGRID_API_KEY"); + sg.addRequestHeader("X-Mock", "204"); + Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("user/webhooks/event/test");