Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: multiple webhooks support #740

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ examples/Example.java
sendgrid-java.jar
dependency-reduced-pom.xml
prism*
sendgrid.env
8 changes: 4 additions & 4 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6126,15 +6126,15 @@ 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
try {
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());
Expand All @@ -6154,15 +6154,15 @@ 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
try {
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());
Expand Down
2 changes: 1 addition & 1 deletion examples/user/GetWebhookEventSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion examples/user/UpdateWebhookEventSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
38 changes: 38 additions & 0 deletions src/test/java/com/sendgrid/SendGridTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand Down