From 8f2a0a4e0ac0a6bc9c7db70361e763237912f48e Mon Sep 17 00:00:00 2001 From: Gabriel Miranda Date: Fri, 11 Sep 2026 14:41:40 -0300 Subject: [PATCH 1/2] feat(broadcasts): add duplicate endpoint Ports resend.broadcasts.duplicate(id) from the Node SDK for POST /broadcasts/{id}/duplicate, added in resend/resend-openapi#115. Co-Authored-By: Claude Fable 5.1 --- .../services/broadcasts/Broadcasts.java | 18 +++++++++ .../DuplicateBroadcastResponseSuccess.java | 39 +++++++++++++++++++ .../services/broadcasts/BroadcastsTest.java | 19 +++++++++ 3 files changed, 76 insertions(+) create mode 100644 src/main/java/com/resend/services/broadcasts/model/DuplicateBroadcastResponseSuccess.java diff --git a/src/main/java/com/resend/services/broadcasts/Broadcasts.java b/src/main/java/com/resend/services/broadcasts/Broadcasts.java index 7bc64b0..576eeda 100644 --- a/src/main/java/com/resend/services/broadcasts/Broadcasts.java +++ b/src/main/java/com/resend/services/broadcasts/Broadcasts.java @@ -104,6 +104,24 @@ public CancelBroadcastResponseSuccess cancel(String id) throws ResendException { return resendMapper.readValue(responseBody, CancelBroadcastResponseSuccess.class); } + /** + * Duplicates a broadcast into a new draft. + * + * @param id The unique identifier of the broadcast to duplicate. + * @return The DuplicateBroadcastResponseSuccess with the identifier of the new draft. + * @throws ResendException If an error occurs during the broadcast duplication process. + */ + public DuplicateBroadcastResponseSuccess duplicate(String id) throws ResendException { + AbstractHttpResponse response = httpClient.perform("/broadcasts/" + id + "/duplicate", super.apiKey, HttpMethod.POST, "", MediaType.get("application/json")); + + if (!response.isSuccessful()) { + throw new ResendException(response.getCode(), response.getBody()); + } + + String responseBody = response.getBody(); + return resendMapper.readValue(responseBody, DuplicateBroadcastResponseSuccess.class); + } + /** * Deletes a broadcast based on the provided broadcast ID. * diff --git a/src/main/java/com/resend/services/broadcasts/model/DuplicateBroadcastResponseSuccess.java b/src/main/java/com/resend/services/broadcasts/model/DuplicateBroadcastResponseSuccess.java new file mode 100644 index 0000000..690b722 --- /dev/null +++ b/src/main/java/com/resend/services/broadcasts/model/DuplicateBroadcastResponseSuccess.java @@ -0,0 +1,39 @@ +package com.resend.services.broadcasts.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Represents the response for a successful broadcast duplication. + * Extends the BaseBroadcastResponse class. + */ +public class DuplicateBroadcastResponseSuccess extends BaseBroadcastResponse { + @JsonProperty("object") + private String object; + + /** + * Default constructor + */ + public DuplicateBroadcastResponseSuccess() { + + } + + /** + * Constructs a successful response for duplicating a broadcast. + * + * @param id The ID of the new draft broadcast. + * @param object The object of the broadcast. + */ + public DuplicateBroadcastResponseSuccess(String id, String object) { + super(id); + this.object = object; + } + + /** + * Get the object. + * + * @return The type of the data. + */ + public String getObject() { + return object; + } +} diff --git a/src/test/java/com/resend/services/broadcasts/BroadcastsTest.java b/src/test/java/com/resend/services/broadcasts/BroadcastsTest.java index 95b874e..6f74e9a 100644 --- a/src/test/java/com/resend/services/broadcasts/BroadcastsTest.java +++ b/src/test/java/com/resend/services/broadcasts/BroadcastsTest.java @@ -45,6 +45,11 @@ public class BroadcastsTest { private static final String CANCEL_RESPONSE_JSON = "{\"id\":\"" + GET_BROADCAST_ID + "\",\"object\":\"broadcast\"}"; + private static final String DUPLICATED_BROADCAST_ID = "a1e7c2d4-5b3f-4e8a-9c1d-2f6b7a8e9d01"; + + private static final String DUPLICATE_RESPONSE_JSON = + "{\"id\":\"" + DUPLICATED_BROADCAST_ID + "\",\"object\":\"broadcast\"}"; + private static final String LIST_RESPONSE_JSON = "{\"object\":\"list\",\"has_more\":true,\"data\":[" + "{\"id\":\"1\",\"audience_id\":\"" + AUDIENCE_ID + "\",\"status\":\"draft\",\"created_at\":\"2024-12-01 19:32:22.98+00\"}," + @@ -181,6 +186,20 @@ public void testCancelBroadcast_Success() throws ResendException { assertEquals("broadcast", response.getObject()); } + @Test + public void testDuplicateBroadcast_Success() throws ResendException { + AbstractHttpResponse httpResponse = new AbstractHttpResponse<>(201, DUPLICATE_RESPONSE_JSON, true); + + when(httpClient.perform(eq("/broadcasts/" + GET_BROADCAST_ID + "/duplicate"), anyString(), eq(HttpMethod.POST), eq(""), any(MediaType.class))) + .thenReturn(httpResponse); + + DuplicateBroadcastResponseSuccess response = broadcasts.duplicate(GET_BROADCAST_ID); + + assertNotNull(response); + assertEquals(DUPLICATED_BROADCAST_ID, response.getId()); + assertEquals("broadcast", response.getObject()); + } + @Test public void testListBroadcasts_Success() throws ResendException { AbstractHttpResponse httpResponse = new AbstractHttpResponse<>(200, LIST_RESPONSE_JSON, true); From 291c2f152b996ff61b520c433d0494d30e4beabb Mon Sep 17 00:00:00 2001 From: Gabriel Miranda Date: Fri, 11 Sep 2026 14:42:10 -0300 Subject: [PATCH 2/2] chore: bump to v4.25.0 Co-Authored-By: Claude Fable 5.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 7a57b5c..4e09d88 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ GROUP=com.resend -VERSION_NAME=4.24.0 +VERSION_NAME=4.25.0 POM_URL=https://github.com/resendlabs/resend-java POM_SCM_URL=https://github.com/resendlabs/resend-java.git