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
12 changes: 12 additions & 0 deletions src/main/java/com/resend/Resend.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.resend.services.contacts.Contacts;
import com.resend.services.domains.Domains;
import com.resend.services.emails.Emails;
import com.resend.services.segments.Segments;
import com.resend.services.webhooks.Webhooks;
import com.resend.services.receiving.Receiving;
import com.resend.services.topics.Topics;
Expand Down Expand Up @@ -71,11 +72,22 @@ public Contacts contacts() {
* Returns an Audience object that can be used to interact with the Audiences service.
*
* @return an Audiences object.
* @deprecated Use {@link #segments()} instead.
*/
@Deprecated
public Audiences audiences() {
return new Audiences(apiKey);
}

/**
* Returns a Segments object that can be used to interact with the Segments service.
*
* @return a Segments object.
*/
public Segments segments() {
return new Segments(apiKey);
}

/**
* Returns a Batch object that can be used to interact with the Batch service.
*
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/resend/services/audiences/Audiences.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public Audiences(final String apiKey) {
* @param createAudienceOptions The Audience details.
* @return The details of the created audience.
* @throws ResendException If an error occurs during the Audience creation process.
* @deprecated Use {@link com.resend.services.segments.Segments#create(com.resend.services.segments.model.CreateSegmentOptions)} instead.
*/
@Deprecated
public CreateAudienceResponseSuccess create(CreateAudienceOptions createAudienceOptions) throws ResendException {
String payload = super.resendMapper.writeValue(createAudienceOptions);
AbstractHttpResponse<String> response = httpClient.perform("/audiences", super.apiKey, HttpMethod.POST, payload, MediaType.get("application/json"));
Expand All @@ -47,7 +49,9 @@ public CreateAudienceResponseSuccess create(CreateAudienceOptions createAudience
*
* @return A ListAudiencesResponseSuccess containing the list of audiences.
* @throws ResendException If an error occurs during the audiences list retrieval process.
* @deprecated Use {@link com.resend.services.segments.Segments#list()} instead.
*/
@Deprecated
public ListAudiencesResponseSuccess list() throws ResendException {
AbstractHttpResponse<String> response = this.httpClient.perform("/audiences", super.apiKey, HttpMethod.GET, null, MediaType.get("application/json"));

Expand All @@ -66,7 +70,9 @@ public ListAudiencesResponseSuccess list() throws ResendException {
*
* @return A ListAudiencesResponseSuccess containing the paginated list of audiences.
* @throws ResendException If an error occurs during the audiences list retrieval process.
* @deprecated Use {@link com.resend.services.segments.Segments#list(ListParams)} instead.
*/
@Deprecated
public ListAudiencesResponseSuccess list(ListParams params) throws ResendException {
String pathWithQuery = "/audiences" + URLHelper.parse(params);
AbstractHttpResponse<String> response = this.httpClient.perform(pathWithQuery, super.apiKey, HttpMethod.GET, null, MediaType.get("application/json"));
Expand All @@ -86,7 +92,9 @@ public ListAudiencesResponseSuccess list(ListParams params) throws ResendExcepti
* @param id The unique identifier of the audience.
* @return The retrieved audience details.
* @throws ResendException If an error occurs while retrieving the audience.
* @deprecated Use {@link com.resend.services.segments.Segments#get(String)} instead.
*/
@Deprecated
public GetAudienceResponseSuccess get(String id) throws ResendException {
AbstractHttpResponse<String> response = this.httpClient.perform("/audiences/" +id, super.apiKey, HttpMethod.GET, null, MediaType.get("application/json"));

Expand All @@ -105,7 +113,9 @@ public GetAudienceResponseSuccess get(String id) throws ResendException {
* @param id The unique identifier of the audience to delete.
* @return The RemoveAudiencesResponseSuccess with the details of the removed audience.
* @throws ResendException If an error occurs during the audience deletion process.
* @deprecated Use {@link com.resend.services.segments.Segments#remove(String)} instead.
*/
@Deprecated
public RemoveAudienceResponseSuccess remove(String id) throws ResendException {
AbstractHttpResponse<String> response = httpClient.perform("/audiences/" +id, super.apiKey, HttpMethod.DELETE, "", null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
*/
public class BroadcastOptions {
@JsonProperty("audience_id")
@Deprecated
private final String audienceId;

@JsonProperty("segment_id")
private final String segmentId;

@JsonProperty("from")
private final String from;

Expand All @@ -36,6 +40,7 @@ public class BroadcastOptions {
*/
protected BroadcastOptions(Builder builder) {
this.audienceId = builder.audienceId;
this.segmentId = builder.segmentId;
this.from = builder.from;
this.subject = builder.subject;
this.replyTo = builder.replyTo;
Expand All @@ -48,11 +53,22 @@ protected BroadcastOptions(Builder builder) {
* Gets the audience ID.
*
* @return the unique identifier of the audience.
* @deprecated Use {@link #getSegmentId()} instead.
*/
@Deprecated
public String getAudienceId() {
return audienceId;
}

/**
* Gets the segment ID.
*
* @return the unique identifier of the segment.
*/
public String getSegmentId() {
return segmentId;
}

/**
* Gets the sender's email address.
*
Expand Down Expand Up @@ -114,9 +130,16 @@ protected static abstract class Builder<T extends BroadcastOptions, B extends Bu

/**
* The ID of the audience targeted by the broadcast.
* @deprecated Use {@link #segmentId} instead.
*/
@Deprecated
protected String audienceId;

/**
* The ID of the segment targeted by the broadcast.
*/
protected String segmentId;

/**
* The email address of the sender.
*/
Expand Down Expand Up @@ -152,12 +175,25 @@ protected static abstract class Builder<T extends BroadcastOptions, B extends Bu
*
* @param audienceId the unique identifier of the audience.
* @return the builder instance.
* @deprecated Use {@link #segmentId(String)} instead.
*/
@Deprecated
public B audienceId(String audienceId) {
this.audienceId = audienceId;
return self();
}

/**
* Sets the segment ID.
*
* @param segmentId the unique identifier of the segment.
* @return the builder instance.
*/
public B segmentId(String segmentId) {
this.segmentId = segmentId;
return self();
}

/**
* Sets the sender's email address.
*
Expand Down
24 changes: 14 additions & 10 deletions src/main/java/com/resend/services/contacts/Contacts.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public Contacts(final String apiKey) {
* @throws ResendException If an error occurs during the Contact creation process.
*/
public CreateContactResponseSuccess create(CreateContactOptions createContactOptions) throws ResendException {
String segmentId = createContactOptions.getSegmentId() != null ? createContactOptions.getSegmentId() : createContactOptions.getAudienceId();
String payload = super.resendMapper.writeValue(createContactOptions);
AbstractHttpResponse<String> response = httpClient.perform("/audiences/" + createContactOptions.getAudienceId()+ "/contacts" , super.apiKey, HttpMethod.POST, payload, MediaType.get("application/json"));
AbstractHttpResponse<String> response = httpClient.perform("/segments/" + segmentId + "/contacts" , super.apiKey, HttpMethod.POST, payload, MediaType.get("application/json"));

if (!response.isSuccessful()) {
throw new ResendException(response.getCode(), response.getBody());
Expand All @@ -45,12 +46,12 @@ public CreateContactResponseSuccess create(CreateContactOptions createContactOpt
/**
* Retrieves a list of contacts and returns a ListContactsResponseSuccess.
*
* @param audienceId The id of the audience.
* @param segmentId The id of the segment (formerly known as audienceId).
* @return A ListContactsResponseSuccess containing the list of contacts.
* @throws ResendException If an error occurs during the contacts list retrieval process.
*/
public ListContactsResponseSuccess list(String audienceId) throws ResendException {
AbstractHttpResponse<String> response = this.httpClient.perform("/audiences/" +audienceId+ "/contacts" , super.apiKey, HttpMethod.GET, null, MediaType.get("application/json"));
public ListContactsResponseSuccess list(String segmentId) throws ResendException {
AbstractHttpResponse<String> response = this.httpClient.perform("/segments/" + segmentId + "/contacts" , super.apiKey, HttpMethod.GET, null, MediaType.get("application/json"));

if (!response.isSuccessful()) {
throw new ResendException(response.getCode(), response.getBody());
Expand All @@ -64,13 +65,13 @@ public ListContactsResponseSuccess list(String audienceId) throws ResendExceptio
/**
* Retrieves a paginated list of contacts and returns a ListContactsResponseSuccess.
*
* @param audienceId The id of the audience.
* @param segmentId The id of the segment (formerly known as audienceId).
* @param params The params used to customize the list.
* @return A ListContactsResponseSuccess containing the paginated list of contacts.
* @throws ResendException If an error occurs during the contacts list retrieval process.
*/
public ListContactsResponseSuccess list(String audienceId, ListParams params) throws ResendException {
String pathWithQuery = "/audiences/" +audienceId+ "/contacts" + URLHelper.parse(params);
public ListContactsResponseSuccess list(String segmentId, ListParams params) throws ResendException {
String pathWithQuery = "/segments/" + segmentId + "/contacts" + URLHelper.parse(params);
AbstractHttpResponse<String> response = this.httpClient.perform(pathWithQuery, super.apiKey, HttpMethod.GET, null, MediaType.get("application/json"));

if (!response.isSuccessful()) {
Expand Down Expand Up @@ -101,8 +102,9 @@ public GetContactResponseSuccess get(GetContactOptions params) throws ResendExce
}

String contactIdentifier = (id != null && !id.isEmpty()) ? id : email;
String segmentId = params.getSegmentId() != null ? params.getSegmentId() : params.getAudienceId();

AbstractHttpResponse<String> response = this.httpClient.perform("/audiences/" +params.getAudienceId()+ "/contacts/" +contactIdentifier, super.apiKey, HttpMethod.GET, null, MediaType.get("application/json"));
AbstractHttpResponse<String> response = this.httpClient.perform("/segments/" + segmentId + "/contacts/" + contactIdentifier, super.apiKey, HttpMethod.GET, null, MediaType.get("application/json"));

if (!response.isSuccessful()) {
throw new ResendException(response.getCode(), response.getBody());
Expand All @@ -127,8 +129,9 @@ public RemoveContactResponseSuccess remove(RemoveContactOptions params) throws R
}

String pathParameter = params.getId() != null ? params.getId() : params.getEmail();
String segmentId = params.getSegmentId() != null ? params.getSegmentId() : params.getAudienceId();

AbstractHttpResponse<String> response = httpClient.perform("/audiences/" +params.getAudienceId()+ "/contacts/" + pathParameter, super.apiKey, HttpMethod.DELETE, "", null);
AbstractHttpResponse<String> response = httpClient.perform("/segments/" + segmentId + "/contacts/" + pathParameter, super.apiKey, HttpMethod.DELETE, "", null);

if (!response.isSuccessful()) {
throw new ResendException(response.getCode(), response.getBody());
Expand All @@ -153,9 +156,10 @@ public UpdateContactResponseSuccess update(UpdateContactOptions params) throws R
}

String pathParameter = params.getId() != null ? params.getId() : params.getEmail();
String segmentId = params.getSegmentId() != null ? params.getSegmentId() : params.getAudienceId();

String payload = super.resendMapper.writeValue(params);
AbstractHttpResponse<String> response = httpClient.perform("/audiences/" +params.getAudienceId()+ "/contacts/" + pathParameter, super.apiKey, HttpMethod.PATCH, payload, MediaType.get("application/json"));
AbstractHttpResponse<String> response = httpClient.perform("/segments/" + segmentId + "/contacts/" + pathParameter, super.apiKey, HttpMethod.PATCH, payload, MediaType.get("application/json"));

if (!response.isSuccessful()) {
throw new ResendException(response.getCode(), response.getBody());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ public abstract class ContactOptions {

/**
* The audience_id of the contact options
* @deprecated Use {@link #segmentId} instead.
*/
@Deprecated
@JsonProperty("audience_id")
protected final String audienceId;

/**
* The segment_id of the contact options
*/
@JsonProperty("segment_id")
protected final String segmentId;

/**
* The email of the contact options
*/
Expand All @@ -33,6 +41,7 @@ public abstract class ContactOptions {
protected ContactOptions(Builder builder) {
this.id = builder.id;
this.audienceId = builder.audienceId;
this.segmentId = builder.segmentId;
this.email = builder.email;
}

Expand All @@ -49,11 +58,22 @@ public String getId() {
* Get the audienceId of the ContactOptions.
*
* @return The audienceId of the ContactOptions.
* @deprecated Use {@link #getSegmentId()} instead.
*/
@Deprecated
public String getAudienceId() {
return audienceId;
}

/**
* Get the segmentId of the ContactOptions.
*
* @return The segmentId of the ContactOptions.
*/
public String getSegmentId() {
return segmentId;
}

/**
* Get the email of the ContactOptions.
*
Expand All @@ -74,9 +94,16 @@ protected static abstract class Builder<T extends ContactOptions, B extends Buil

/**
* The audienceId of the contact options builder
* @deprecated Use {@link #segmentId} instead.
*/
@Deprecated
protected String audienceId;

/**
* The segmentId of the contact options builder
*/
protected String segmentId;

/**
* The email of the contact options builder
*/
Expand All @@ -98,12 +125,25 @@ public B id(String id) {
*
* @param audienceId The audienceId of the ContactOptions.
* @return The builder instance.
* @deprecated Use {@link #segmentId(String)} instead.
*/
@Deprecated
public B audienceId(String audienceId) {
this.audienceId = audienceId;
return self();
}

/**
* Set the segmentId of the ContactOptions.
*
* @param segmentId The segmentId of the ContactOptions.
* @return The builder instance.
*/
public B segmentId(String segmentId) {
this.segmentId = segmentId;
return self();
}

/**
* Set the email of the ContactOptions.
*
Expand Down
Loading