Skip to content

Commit

Permalink
Add resend webhook (#100)
Browse files Browse the repository at this point in the history
* Add resend webhook

* Bump to 2.15.0
  • Loading branch information
DavidMealha-Onfido authored Feb 12, 2024
1 parent 6026157 commit e92cb10
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion onfido-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.onfido</groupId>
<artifactId>onfido-api-java</artifactId>
<version>2.14.1</version>
<version>2.15.0</version>

<name>Onfido API Java Client</name>
<description>Official Java API client library for the Onfido API</description>
Expand Down
12 changes: 12 additions & 0 deletions onfido-java/src/main/java/com/onfido/WebhookManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.onfido.api.ResourceManager;
import com.onfido.exceptions.OnfidoException;
import com.onfido.models.Webhook;
import com.onfido.models.WebhookResend;
import java.util.List;
import okhttp3.OkHttpClient;

Expand All @@ -15,6 +16,7 @@
public class WebhookManager extends ResourceManager {
private ApiJson<Webhook> webhookParser = new ApiJson<>(Webhook.class);
private ApiJson<Webhook.Request> requestFormatter = new ApiJson<>(Webhook.Request.class);
private ApiJson<WebhookResend.Request> resendRequestFormatter = new ApiJson<>(WebhookResend.Request.class);

protected WebhookManager(Config config, OkHttpClient client) {
super("webhooks/", config, client);
Expand Down Expand Up @@ -73,4 +75,14 @@ public void delete(String webhookId) throws OnfidoException {
public List<Webhook> list() throws OnfidoException {
return webhookParser.parseWrappedList(get(""), "webhooks");
}

/**
* Resends a list of webhooks. If successful, returns a 204 No Content response.
*
* @param request the request body
* @throws OnfidoException the onfido exception
*/
public void resend(WebhookResend.Request request) throws OnfidoException {
post("resend", resendRequestFormatter.toJson(request));
}
}
13 changes: 13 additions & 0 deletions onfido-java/src/main/models/webhook_resend.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"title": "WebhookResend",
"properties": {
"data": {
"type": "array",
"description": "Data object",
"items": {
"$ref": "webhook_resend_object.yaml"
},
"writeOnly": true
}
}
}
20 changes: 20 additions & 0 deletions onfido-java/src/main/models/webhook_resend_object.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"title": "WebhookResendObject",
"properties": {
"resource_type": {
"type": "string",
"description": "The resource type to resend.",
"writeOnly": true
},
"resource_id": {
"type": "string",
"description": "The resource id to resend.",
"writeOnly": true
},
"event": {
"type": "string",
"description": "The event that should be resent.",
"writeOnly": true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.onfido.JsonObject;
import com.onfido.Onfido;
import com.onfido.models.Webhook;
import com.onfido.models.WebhookResend;
import com.onfido.models.WebhookResendObject;
import com.onfido.exceptions.OnfidoException;

import java.util.Arrays;
Expand Down Expand Up @@ -107,4 +109,18 @@ public void listWebhooksTest() throws Exception {
assertEquals("https://example.com/firstWebhook", webhooks.get(0).getUrl());
assertEquals("https://example.com/secondWebhook", webhooks.get(1).getUrl());
}

@Test
public void resendWebhooksTest() throws Exception {
prepareMock("", null, 204);

onfido.webhook.resend(
WebhookResend.request().data(
WebhookResendObject.request().resourceType("check").resourceId("check_id_1").event("check.completed"),
WebhookResendObject.request().resourceType("check").resourceId("check_id_2").event("check.completed")
)
);

takeRequest("/webhooks/resend");
}
}

0 comments on commit e92cb10

Please sign in to comment.