Skip to content
Merged
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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/resend/services/broadcasts/Broadcasts.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Comment thread
gabrielmfern marked this conversation as resolved.
AbstractHttpResponse<String> 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.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
19 changes: 19 additions & 0 deletions src/test/java/com/resend/services/broadcasts/BroadcastsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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\"}," +
Expand Down Expand Up @@ -181,6 +186,20 @@ public void testCancelBroadcast_Success() throws ResendException {
assertEquals("broadcast", response.getObject());
}

@Test
public void testDuplicateBroadcast_Success() throws ResendException {
AbstractHttpResponse<String> 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<String> httpResponse = new AbstractHttpResponse<>(200, LIST_RESPONSE_JSON, true);
Expand Down
Loading