From 843cee1b8cec514cc5323805b0a7ea276bdd391d Mon Sep 17 00:00:00 2001 From: Kewyn Akshlley Date: Fri, 12 Sep 2025 14:44:36 -0300 Subject: [PATCH 1/3] feat: Pagination and list emails --- .../com/resend/core/helper/URLHelper.java | 49 +++++++ .../java/com/resend/core/net/ListParams.java | 123 ++++++++++++++++++ .../com/resend/core/net/RequestOptions.java | 2 - .../com/resend/services/apikeys/ApiKeys.java | 22 ++++ .../apikeys/model/ListApiKeysResponse.java | 15 ++- .../resend/services/audiences/Audiences.java | 21 +++ .../model/ListAudiencesResponseSuccess.java | 15 ++- .../services/broadcasts/Broadcasts.java | 21 +++ .../model/ListBroadcastsResponseSuccess.java | 15 ++- .../resend/services/contacts/Contacts.java | 22 ++++ .../model/ListContactsResponseSuccess.java | 13 ++ .../com/resend/services/domains/Domains.java | 21 +++ .../domains/model/ListDomainsResponse.java | 15 ++- .../com/resend/services/emails/Emails.java | 42 +++++- .../model/ListEmailsResponseSuccess.java | 66 ++++++++++ .../resend/services/apikey/ApiKeysTest.java | 16 +++ .../services/audiences/AudiencesTest.java | 17 +++ .../services/broadcasts/BroadcastsTest.java | 17 +++ .../services/contacts/ContactsTest.java | 19 +++ .../resend/services/domains/DomainsTest.java | 34 +++++ .../resend/services/emails/EmailsTest.java | 28 ++++ .../com/resend/services/util/ApiKeysUtil.java | 2 +- .../resend/services/util/AudiencesUtil.java | 2 +- .../resend/services/util/BroadcastsUtil.java | 2 +- .../com/resend/services/util/DomainsUtil.java | 46 ++++++- .../com/resend/services/util/EmailsUtil.java | 56 +++++++- 26 files changed, 682 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/resend/core/helper/URLHelper.java create mode 100644 src/main/java/com/resend/core/net/ListParams.java create mode 100644 src/main/java/com/resend/services/emails/model/ListEmailsResponseSuccess.java diff --git a/src/main/java/com/resend/core/helper/URLHelper.java b/src/main/java/com/resend/core/helper/URLHelper.java new file mode 100644 index 0000000..c918788 --- /dev/null +++ b/src/main/java/com/resend/core/helper/URLHelper.java @@ -0,0 +1,49 @@ +package com.resend.core.helper; + +import com.resend.core.net.ListParams; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * URL Helper for handling query params. + */ +public class URLHelper { + + /** + * Parses the given {@link ListParams} object into a query string. + * + * @param params The {@link ListParams} instance (can be null). + * @return A query string starting with "?" if parameters exist, or an empty string otherwise. + */ + public static String parse(ListParams params) { + if (params == null) { + return ""; + } + + Map queryParams = new LinkedHashMap<>(); + + if (params.getLimit() != null) { + queryParams.put("limit", params.getLimit().toString()); + } + if (params.getAfter() != null && !params.getAfter().isEmpty()) { + queryParams.put("after", params.getAfter()); + } + if (params.getBefore() != null && !params.getBefore().isEmpty()) { + queryParams.put("before", params.getBefore()); + } + + if (queryParams.isEmpty()) { + return ""; + } + + String query = queryParams.entrySet().stream() + .map(entry -> entry.getKey() + "=" + entry.getValue()) + .collect(Collectors.joining("&")); + + return "?" + query; + } + + +} diff --git a/src/main/java/com/resend/core/net/ListParams.java b/src/main/java/com/resend/core/net/ListParams.java new file mode 100644 index 0000000..a43be97 --- /dev/null +++ b/src/main/java/com/resend/core/net/ListParams.java @@ -0,0 +1,123 @@ +package com.resend.core.net; + +import com.resend.services.broadcasts.model.SendBroadcastOptions; + +/** + * Represents a class that wraps the parameters for the list method. + */ +public class ListParams { + + /** + * The maximum number of emails to return. Defaults to 10, maximum 100. + */ + private final Integer limit; + + /** + * Return emails after this cursor for pagination. + */ + private final String after; + + /** + * Return emails before this cursor for pagination. + */ + private final String before; + + /** + * Constructs a ListParams object using the provided builder. + * + * @param builder The builder to construct the ListParams. + */ + public ListParams(Builder builder) { + this.limit = builder.limit; + this.after = builder.after; + this.before = builder.before; + } + + /** + * Get the pagination limit. + * + * @return pagination limit. + */ + public Integer getLimit() { + return limit; + } + + /** + * Get emails after this cursor for pagination. + * @return email after this cursor. + */ + public String getAfter() { + return after; + } + + /** + * Get emails before this cursor for pagination. + * @return email before this cursor. + */ + public String getBefore() { + return before; + } + + /** + * Builder class for constructing ListParams objects. + */ + public static class Builder { + private Integer limit; + + private String before; + + private String after; + + + /** + * Set the maximum number of emails to return. + * + * @param limit The maximum number of emails. + * @return The builder instance. + */ + public Builder limit(Integer limit) { + this.limit = limit; + return this; + } + + /** + * Set the emails before this cursor for pagination. + * + * @param before The emails after this cursor for pagination. + * @return The builder instance. + */ + public Builder before(String before) { + this.before = before; + return this; + } + + /** + * Set the emails after this cursor for pagination. + * + * @param after The emails after this cursor for pagination. + * @return The builder instance. + */ + public Builder after(String after) { + this.after = after; + return this; + } + + /** + * Builds an instance of {@link ListParams} with the specified options. + * + * @return A new {@link ListParams} instance. + */ + public ListParams build() { + return new ListParams(this); + } + } + + /** + * Create a new builder instance for constructing ListParams objects. + * + * @return A new builder instance. + */ + public static Builder builder() { + return new Builder(); + } +} diff --git a/src/main/java/com/resend/core/net/RequestOptions.java b/src/main/java/com/resend/core/net/RequestOptions.java index f3b65d3..d22745e 100644 --- a/src/main/java/com/resend/core/net/RequestOptions.java +++ b/src/main/java/com/resend/core/net/RequestOptions.java @@ -1,7 +1,5 @@ package com.resend.core.net; -import com.resend.services.domains.model.CreateDomainOptions; - /** * Represents a request to create a request options. */ diff --git a/src/main/java/com/resend/services/apikeys/ApiKeys.java b/src/main/java/com/resend/services/apikeys/ApiKeys.java index 4afe3ba..a1b40c3 100644 --- a/src/main/java/com/resend/services/apikeys/ApiKeys.java +++ b/src/main/java/com/resend/services/apikeys/ApiKeys.java @@ -1,8 +1,10 @@ package com.resend.services.apikeys; import com.resend.core.exception.ResendException; +import com.resend.core.helper.URLHelper; import com.resend.core.net.AbstractHttpResponse; import com.resend.core.net.HttpMethod; +import com.resend.core.net.ListParams; import com.resend.core.service.BaseService; import com.resend.services.apikeys.model.CreateApiKeyResponse; import com.resend.services.apikeys.model.CreateApiKeyOptions; @@ -63,6 +65,26 @@ public ListApiKeysResponse list() throws ResendException { return listApiKeysResponse; } + /** + * Retrieves a paginated list of api keys and returns a ListApiKeysResponse. + * + * @return A ListApiKeysResponse containing the paginated list of api keys. + * @throws ResendException If an error occurs during the api keys list retrieval process. + */ + public ListApiKeysResponse list(ListParams params) throws ResendException { + String pathWithQuery = "/api-keys" + URLHelper.parse(params); + AbstractHttpResponse response = this.httpClient.perform(pathWithQuery, super.apiKey, HttpMethod.GET, null, MediaType.get("application/json")); + + if (!response.isSuccessful()) { + throw new ResendException("Failed to retrieve api keys: " + response.getCode() + " " + response.getBody()); + } + + String responseBody = response.getBody(); + + ListApiKeysResponse listApiKeysResponse = resendMapper.readValue(responseBody, ListApiKeysResponse.class); + return listApiKeysResponse; + } + /** * Deletes an api key based on the provided api key ID and returns a boolean response. * diff --git a/src/main/java/com/resend/services/apikeys/model/ListApiKeysResponse.java b/src/main/java/com/resend/services/apikeys/model/ListApiKeysResponse.java index 73e2432..6bd5cb1 100644 --- a/src/main/java/com/resend/services/apikeys/model/ListApiKeysResponse.java +++ b/src/main/java/com/resend/services/apikeys/model/ListApiKeysResponse.java @@ -12,6 +12,9 @@ public class ListApiKeysResponse { @JsonProperty("data") private List data; + @JsonProperty("has_more") + private Boolean hasMore; + /** * Default constructor. Creates an instance of ListApiKeysResponse with an empty data list. */ @@ -23,8 +26,9 @@ public ListApiKeysResponse() { * * @param data The list of API key items. */ - public ListApiKeysResponse(List data) { + public ListApiKeysResponse(List data, Boolean hasMore) { this.data = data; + this.hasMore = hasMore; } /** @@ -35,5 +39,14 @@ public ListApiKeysResponse(List data) { public List getData() { return data; } + + /** + * Gets the indicator whether there are more items available for pagination. + * + * @return Whether there are more items available for pagination. + */ + public Boolean hasMore() { + return hasMore; + } } diff --git a/src/main/java/com/resend/services/audiences/Audiences.java b/src/main/java/com/resend/services/audiences/Audiences.java index 0153007..7e25889 100644 --- a/src/main/java/com/resend/services/audiences/Audiences.java +++ b/src/main/java/com/resend/services/audiences/Audiences.java @@ -1,8 +1,10 @@ package com.resend.services.audiences; import com.resend.core.exception.ResendException; +import com.resend.core.helper.URLHelper; import com.resend.core.net.AbstractHttpResponse; import com.resend.core.net.HttpMethod; +import com.resend.core.net.ListParams; import com.resend.core.service.BaseService; import com.resend.services.audiences.model.*; import okhttp3.MediaType; @@ -58,6 +60,25 @@ public ListAudiencesResponseSuccess list() throws ResendException { return resendMapper.readValue(responseBody, ListAudiencesResponseSuccess.class); } + /** + * Retrieves a paginated list of audiences and returns a ListAudiencesResponseSuccess. + * + * @return A ListAudiencesResponseSuccess containing the paginated list of audiences. + * @throws ResendException If an error occurs during the audiences list retrieval process. + */ + public ListAudiencesResponseSuccess list(ListParams params) throws ResendException { + String pathWithQuery = "/audiences" + URLHelper.parse(params); + AbstractHttpResponse response = this.httpClient.perform(pathWithQuery, super.apiKey, HttpMethod.GET, null, MediaType.get("application/json")); + + if (!response.isSuccessful()) { + throw new ResendException("Failed to retrieve audiences: " + response.getCode() + " " + response.getBody()); + } + + String responseBody = response.getBody(); + + return resendMapper.readValue(responseBody, ListAudiencesResponseSuccess.class); + } + /** * Retrieves a audience by its unique identifier. * diff --git a/src/main/java/com/resend/services/audiences/model/ListAudiencesResponseSuccess.java b/src/main/java/com/resend/services/audiences/model/ListAudiencesResponseSuccess.java index 10074d3..9e6df5e 100644 --- a/src/main/java/com/resend/services/audiences/model/ListAudiencesResponseSuccess.java +++ b/src/main/java/com/resend/services/audiences/model/ListAudiencesResponseSuccess.java @@ -15,6 +15,9 @@ public class ListAudiencesResponseSuccess { @JsonProperty("object") private String object; + @JsonProperty("has_more") + private Boolean hasMore; + /** * Default constructor */ @@ -27,9 +30,10 @@ public ListAudiencesResponseSuccess() { * @param data The list of audiences. * @param object The object of the audiences. */ - public ListAudiencesResponseSuccess(List data, String object) { + public ListAudiencesResponseSuccess(List data, String object, Boolean hasMore) { this.data = data; this.object = object; + this.hasMore = hasMore; } /** @@ -49,4 +53,13 @@ public List getData() { public String getObject() { return object; } + + /** + * Gets the indicator whether there are more items available for pagination. + * + * @return Whether there are more items available for pagination. + */ + public Boolean hasMore() { + return hasMore; + } } \ No newline at end of file diff --git a/src/main/java/com/resend/services/broadcasts/Broadcasts.java b/src/main/java/com/resend/services/broadcasts/Broadcasts.java index 67e5b2c..a347147 100644 --- a/src/main/java/com/resend/services/broadcasts/Broadcasts.java +++ b/src/main/java/com/resend/services/broadcasts/Broadcasts.java @@ -1,8 +1,10 @@ package com.resend.services.broadcasts; import com.resend.core.exception.ResendException; +import com.resend.core.helper.URLHelper; import com.resend.core.net.AbstractHttpResponse; import com.resend.core.net.HttpMethod; +import com.resend.core.net.ListParams; import com.resend.core.service.BaseService; import com.resend.services.broadcasts.model.*; import okhttp3.MediaType; @@ -117,6 +119,25 @@ public ListBroadcastsResponseSuccess list() throws ResendException { return resendMapper.readValue(responseBody, ListBroadcastsResponseSuccess.class); } + /** + * Retrieves a paginated list of broadcasts and returns a List. + * + * @return A ListBroadcastsResponseSuccess containing the paginated list of broadcasts. + * @throws ResendException If an error occurs during the broadcasts list retrieval process. + */ + public ListBroadcastsResponseSuccess list(ListParams params) throws ResendException { + String pathWithQuery = "/broadcasts" + URLHelper.parse(params); + AbstractHttpResponse response = this.httpClient.perform(pathWithQuery, super.apiKey, HttpMethod.GET, null, MediaType.get("application/json")); + + if (!response.isSuccessful()) { + throw new ResendException("Failed to retrieve broadcasts: " + response.getCode() + " " + response.getBody()); + } + + String responseBody = response.getBody(); + + return resendMapper.readValue(responseBody, ListBroadcastsResponseSuccess.class); + } + /** * Updates a Broadcast. * diff --git a/src/main/java/com/resend/services/broadcasts/model/ListBroadcastsResponseSuccess.java b/src/main/java/com/resend/services/broadcasts/model/ListBroadcastsResponseSuccess.java index 1421f04..51c8c46 100644 --- a/src/main/java/com/resend/services/broadcasts/model/ListBroadcastsResponseSuccess.java +++ b/src/main/java/com/resend/services/broadcasts/model/ListBroadcastsResponseSuccess.java @@ -15,6 +15,9 @@ public class ListBroadcastsResponseSuccess { @JsonProperty("data") private List data; + @JsonProperty("has_more") + private Boolean hasMore; + /** * Default constructor */ @@ -28,9 +31,10 @@ public ListBroadcastsResponseSuccess() { * @param object Type of the object (e.g., "list"). * @param data List of Broadcast objects. */ - public ListBroadcastsResponseSuccess(String object, List data) { + public ListBroadcastsResponseSuccess(String object, List data, Boolean hasMore) { this.object = object; this.data = data; + this.hasMore = hasMore; } /** @@ -46,5 +50,14 @@ public String getObject() { public List getData() { return data; } + + /** + * Gets the indicator whether there are more items available for pagination. + * + * @return Whether there are more items available for pagination. + */ + public Boolean hasMore() { + return hasMore; + } } diff --git a/src/main/java/com/resend/services/contacts/Contacts.java b/src/main/java/com/resend/services/contacts/Contacts.java index f0c3aa5..56cc03b 100644 --- a/src/main/java/com/resend/services/contacts/Contacts.java +++ b/src/main/java/com/resend/services/contacts/Contacts.java @@ -1,8 +1,10 @@ package com.resend.services.contacts; import com.resend.core.exception.ResendException; +import com.resend.core.helper.URLHelper; import com.resend.core.net.AbstractHttpResponse; import com.resend.core.net.HttpMethod; +import com.resend.core.net.ListParams; import com.resend.core.service.BaseService; import com.resend.services.contacts.model.*; import okhttp3.MediaType; @@ -59,6 +61,26 @@ public ListContactsResponseSuccess list(String audienceId) throws ResendExceptio return resendMapper.readValue(responseBody, ListContactsResponseSuccess.class); } + /** + * Retrieves a paginated list of contacts and returns a ListContactsResponseSuccess. + * + * @param audienceId The id of the audience. + * @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); + AbstractHttpResponse response = this.httpClient.perform(pathWithQuery, super.apiKey, HttpMethod.GET, null, MediaType.get("application/json")); + + if (!response.isSuccessful()) { + throw new ResendException("Failed to retrieve contacts: " + response.getCode() + " " + response.getBody()); + } + + String responseBody = response.getBody(); + + return resendMapper.readValue(responseBody, ListContactsResponseSuccess.class); + } + /** * Retrieves a contact by its unique identifier. * diff --git a/src/main/java/com/resend/services/contacts/model/ListContactsResponseSuccess.java b/src/main/java/com/resend/services/contacts/model/ListContactsResponseSuccess.java index 2eab35a..9923547 100644 --- a/src/main/java/com/resend/services/contacts/model/ListContactsResponseSuccess.java +++ b/src/main/java/com/resend/services/contacts/model/ListContactsResponseSuccess.java @@ -15,6 +15,9 @@ public class ListContactsResponseSuccess { @JsonProperty("data") private List data; + @JsonProperty("has_more") + private Boolean hasMore; + /** * Default constructor */ @@ -30,6 +33,7 @@ public ListContactsResponseSuccess() { public ListContactsResponseSuccess(final List data, final String object) { this.data = data; this.object = object; + this.hasMore = hasMore; } /** @@ -49,5 +53,14 @@ public List getData() { public String getObject() { return object; } + + /** + * Gets the indicator whether there are more items available for pagination. + * + * @return Whether there are more items available for pagination. + */ + public Boolean hasMore() { + return hasMore; + } } diff --git a/src/main/java/com/resend/services/domains/Domains.java b/src/main/java/com/resend/services/domains/Domains.java index d741b7e..bd21de3 100644 --- a/src/main/java/com/resend/services/domains/Domains.java +++ b/src/main/java/com/resend/services/domains/Domains.java @@ -1,8 +1,10 @@ package com.resend.services.domains; import com.resend.core.exception.ResendException; +import com.resend.core.helper.URLHelper; import com.resend.core.net.AbstractHttpResponse; import com.resend.core.net.HttpMethod; +import com.resend.core.net.ListParams; import com.resend.core.service.BaseService; import com.resend.services.domains.model.*; import okhttp3.MediaType; @@ -100,6 +102,25 @@ public ListDomainsResponse list() throws ResendException { return resendMapper.readValue(responseBody, ListDomainsResponse.class); } + /** + * Retrieves a paginated list of domains and returns a ListDomainsResponse. + * + * @return A ListDomainsResponse containing the paginated list of domains. + * @throws ResendException If an error occurs during the domain list retrieval process. + */ + public ListDomainsResponse list(ListParams params) throws ResendException { + String pathWithQuery = "/domains" + URLHelper.parse(params); + AbstractHttpResponse response = this.httpClient.perform(pathWithQuery, super.apiKey, HttpMethod.GET, null, MediaType.get("application/json")); + + if (!response.isSuccessful()) { + throw new ResendException("Failed to retrieve domains list: " + response.getCode() + " " + response.getBody()); + } + + String responseBody = response.getBody(); + + return resendMapper.readValue(responseBody, ListDomainsResponse.class); + } + /** * Updates a domain based on the provided domain ID and returns a UpdateDomainResponseSuccess. * diff --git a/src/main/java/com/resend/services/domains/model/ListDomainsResponse.java b/src/main/java/com/resend/services/domains/model/ListDomainsResponse.java index 1c8f764..5509ce3 100644 --- a/src/main/java/com/resend/services/domains/model/ListDomainsResponse.java +++ b/src/main/java/com/resend/services/domains/model/ListDomainsResponse.java @@ -16,6 +16,9 @@ public class ListDomainsResponse { @JsonProperty("data") public List data; + @JsonProperty("has_more") + private Boolean hasMore; + /** * Default constructor for creating an empty ListDomainsResponse object. */ @@ -27,8 +30,9 @@ public ListDomainsResponse() { * * @param data The list of DomainDTO objects. */ - public ListDomainsResponse(List data) { + public ListDomainsResponse(List data, Boolean hasMore) { this.data = data; + this.hasMore = hasMore; } /** @@ -39,5 +43,14 @@ public ListDomainsResponse(List data) { public List getData() { return data; } + + /** + * Gets the indicator whether there are more items available for pagination. + * + * @return Whether there are more items available for pagination. + */ + public Boolean hasMore() { + return hasMore; + } } diff --git a/src/main/java/com/resend/services/emails/Emails.java b/src/main/java/com/resend/services/emails/Emails.java index 001ea16..c36973f 100644 --- a/src/main/java/com/resend/services/emails/Emails.java +++ b/src/main/java/com/resend/services/emails/Emails.java @@ -1,10 +1,13 @@ package com.resend.services.emails; import com.resend.core.exception.ResendException; +import com.resend.core.helper.URLHelper; import com.resend.core.net.AbstractHttpResponse; import com.resend.core.net.HttpMethod; +import com.resend.core.net.ListParams; import com.resend.core.net.RequestOptions; import com.resend.core.service.BaseService; +import com.resend.services.broadcasts.model.ListBroadcastsResponseSuccess; import com.resend.services.emails.model.*; import okhttp3.MediaType; @@ -47,7 +50,7 @@ public CreateEmailResponse send(CreateEmailOptions createEmailOptions) throws Re /** * Sends an email based on the provided email request. - * + *hjk * @param createEmailOptions The request containing email details. * @param requestOptions The options with additional headers. * @return The response indicating the status of the email sending. @@ -151,4 +154,41 @@ public CancelEmailResponse cancel(String emailId) throws ResendException { return resendMapper.readValue(responseBody, CancelEmailResponse.class); } + + /** + * Retrieves a list of emails and returns a List. + * + * @return A ListEmailsResponseSuccess containing the list of emails. + * @throws ResendException If an error occurs during the emails list retrieval process. + */ + public ListEmailsResponseSuccess list() throws ResendException { + AbstractHttpResponse response = this.httpClient.perform("/emails", super.apiKey, HttpMethod.GET, null, MediaType.get("application/json")); + + if (!response.isSuccessful()) { + throw new ResendException("Failed to retrieve emails: " + response.getCode() + " " + response.getBody()); + } + + String responseBody = response.getBody(); + + return resendMapper.readValue(responseBody, ListEmailsResponseSuccess.class); + } + + /** + * Retrieves a paginated list of emails and returns a List. + * + * @return A ListEmailsResponseSuccess containing the paginated list of emails. + * @throws ResendException If an error occurs during the emails list retrieval process. + */ + public ListEmailsResponseSuccess list(ListParams params) throws ResendException { + String pathWithQuery = "/emails" + URLHelper.parse(params); + AbstractHttpResponse response = this.httpClient.perform(pathWithQuery, super.apiKey, HttpMethod.GET, null, MediaType.get("application/json")); + + if (!response.isSuccessful()) { + throw new ResendException("Failed to retrieve emails: " + response.getCode() + " " + response.getBody()); + } + + String responseBody = response.getBody(); + + return resendMapper.readValue(responseBody, ListEmailsResponseSuccess.class); + } } \ No newline at end of file diff --git a/src/main/java/com/resend/services/emails/model/ListEmailsResponseSuccess.java b/src/main/java/com/resend/services/emails/model/ListEmailsResponseSuccess.java new file mode 100644 index 0000000..cc11312 --- /dev/null +++ b/src/main/java/com/resend/services/emails/model/ListEmailsResponseSuccess.java @@ -0,0 +1,66 @@ +package com.resend.services.emails.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; + +/** + * Represents a successful response for listing e-mails. + */ +public class ListEmailsResponseSuccess { + + @JsonProperty("object") + private String object; + + @JsonProperty("data") + private List data; + + @JsonProperty("has_more") + private Boolean hasMore; + + /** + * Default constructor + */ + public ListEmailsResponseSuccess () { + } + + /** + * Constructs a successful response for listing e-mails. + * + * @param data The list of emails. + * @param object The object of the list emails. + * @param hasMore Whether there are more emails available for pagination. + */ + public ListEmailsResponseSuccess (final List data, final String object, final Boolean hasMore) { + this.data = data; + this.object = object; + this.hasMore = hasMore; + } + + /** + * Gets the list of emails. + * + * @return The list of emails. + */ + public List getData() { + return data; + } + + /** + * Gets the list of emails object. + * + * @return The list of emails object. + */ + public String getObject() { + return object; + } + + /** + * Gets the indicator whether there are more items available for pagination. + * + * @return Whether there are more items available for pagination. + */ + public Boolean hasMore() { + return hasMore; + } +} + diff --git a/src/test/java/com/resend/services/apikey/ApiKeysTest.java b/src/test/java/com/resend/services/apikey/ApiKeysTest.java index 978b581..b9636e2 100644 --- a/src/test/java/com/resend/services/apikey/ApiKeysTest.java +++ b/src/test/java/com/resend/services/apikey/ApiKeysTest.java @@ -1,6 +1,7 @@ package com.resend.services.apikey; import com.resend.core.exception.ResendException; +import com.resend.core.net.ListParams; import com.resend.services.apikeys.ApiKeys; import com.resend.services.apikeys.model.CreateApiKeyOptions; import com.resend.services.apikeys.model.CreateApiKeyResponse; @@ -65,4 +66,19 @@ public void testListApiKeys_Success() throws ResendException { assertNotNull(response); assertEquals(expectedResponse.getData().size(), response.getData().size()); } + + @Test + public void testListApiKeysWithPagination_Success() throws ResendException { + ListParams params = ListParams.builder() + .limit(2).build(); + ListApiKeysResponse expectedResponse = ApiKeysUtil.createListApiKeyResponse(); + + when(apiKeys.list(params)) + .thenReturn(expectedResponse); + + ListApiKeysResponse response = apiKeys.list(params); + + assertNotNull(response); + assertEquals(params.getLimit(), response.getData().size()); + } } diff --git a/src/test/java/com/resend/services/audiences/AudiencesTest.java b/src/test/java/com/resend/services/audiences/AudiencesTest.java index 0fbe813..f9ed0db 100644 --- a/src/test/java/com/resend/services/audiences/AudiencesTest.java +++ b/src/test/java/com/resend/services/audiences/AudiencesTest.java @@ -1,6 +1,7 @@ package com.resend.services.audiences; import com.resend.core.exception.ResendException; +import com.resend.core.net.ListParams; import com.resend.services.audiences.model.CreateAudienceOptions; import com.resend.services.audiences.model.CreateAudienceResponseSuccess; import com.resend.services.audiences.model.ListAudiencesResponseSuccess; @@ -68,4 +69,20 @@ public void testListAudiences_Success() throws ResendException { assertEquals(expectedResponse.getData().size(), res.getData().size()); assertEquals(expectedResponse.getObject(), res.getObject()); } + + @Test + public void testListAudienceWithPagination_Success() throws ResendException { + ListParams params = ListParams.builder() + .limit(3).build(); + ListAudiencesResponseSuccess expectedResponse = AudiencesUtil.createAudiencesListResponse(); + + when(audiences.list(params)) + .thenReturn(expectedResponse); + + ListAudiencesResponseSuccess res = audiences.list(params); + + assertNotNull(res); + assertEquals(params.getLimit(), res.getData().size()); + assertEquals(expectedResponse.getObject(), res.getObject()); + } } diff --git a/src/test/java/com/resend/services/broadcasts/BroadcastsTest.java b/src/test/java/com/resend/services/broadcasts/BroadcastsTest.java index 58f3613..c34e215 100644 --- a/src/test/java/com/resend/services/broadcasts/BroadcastsTest.java +++ b/src/test/java/com/resend/services/broadcasts/BroadcastsTest.java @@ -1,6 +1,7 @@ package com.resend.services.broadcasts; import com.resend.core.exception.ResendException; +import com.resend.core.net.ListParams; import com.resend.services.broadcasts.model.*; import com.resend.services.util.BroadcastsUtil; import org.junit.jupiter.api.BeforeEach; @@ -103,5 +104,21 @@ public void testListBroadcasts_Success() throws ResendException { assertEquals(expectedResponse.getObject(), response.getObject()); verify(broadcasts, times(1)).list(); } + + @Test + public void testListBroadcastsWithPagination_Success() throws ResendException { + ListParams params = ListParams.builder() + .limit(3).build(); + ListBroadcastsResponseSuccess expectedResponse = BroadcastsUtil.createBroadcastsListResponse(); + + when(broadcasts.list()).thenReturn(expectedResponse); + + ListBroadcastsResponseSuccess response = broadcasts.list(params); + + assertNotNull(response); + assertEquals(params.getLimit(), response.getData().size()); + assertEquals(expectedResponse.getObject(), response.getObject()); + verify(broadcasts, times(1)).list(); + } } diff --git a/src/test/java/com/resend/services/contacts/ContactsTest.java b/src/test/java/com/resend/services/contacts/ContactsTest.java index 8daf590..33a8070 100644 --- a/src/test/java/com/resend/services/contacts/ContactsTest.java +++ b/src/test/java/com/resend/services/contacts/ContactsTest.java @@ -1,6 +1,7 @@ package com.resend.services.contacts; import com.resend.core.exception.ResendException; +import com.resend.core.net.ListParams; import com.resend.services.contacts.model.*; import com.resend.services.util.ContactsUtil; import org.junit.jupiter.api.BeforeEach; @@ -70,6 +71,24 @@ public void testListContacts_Success() throws ResendException { assertEquals(expectedResponse.getObject(), res.getObject()); } + @Test + public void testListContactsWithPagination_Success() throws ResendException { + ListParams params = ListParams.builder() + .limit(3).build(); + + String audienceId = "123"; + ListContactsResponseSuccess expectedResponse = ContactsUtil.createContactsListResponse(); + + when(contacts.list(audienceId, params)) + .thenReturn(expectedResponse); + + ListContactsResponseSuccess res = contacts.list(audienceId, params); + + assertNotNull(res); + assertEquals(params.getLimit(), res.getData().size()); + assertEquals(expectedResponse.getObject(), res.getObject()); + } + @Test public void testUpdateContact_Success() throws ResendException { UpdateContactOptions params = ContactsUtil.createUpdateOptions(); diff --git a/src/test/java/com/resend/services/domains/DomainsTest.java b/src/test/java/com/resend/services/domains/DomainsTest.java index 2f6a856..149031e 100644 --- a/src/test/java/com/resend/services/domains/DomainsTest.java +++ b/src/test/java/com/resend/services/domains/DomainsTest.java @@ -1,6 +1,8 @@ package com.resend.services.domains; import com.resend.core.exception.ResendException; +import com.resend.core.net.ListParams; +import com.resend.services.domains.dto.DomainDTO; import com.resend.services.domains.model.*; import com.resend.services.util.DomainsUtil; import org.junit.jupiter.api.BeforeEach; @@ -8,6 +10,8 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import java.util.List; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.mock; @@ -94,4 +98,34 @@ public void testUpdateDomain_Success() throws ResendException { assertEquals(expectedResponse, response); assertEquals(expectedResponse.getId(), response.getId()); } + + @Test + public void testListDomains_Success() throws ResendException { + ListDomainsResponse expectedResponse = DomainsUtil.createDomainListResponse(); + + when(domains.list()).thenReturn(expectedResponse); + + + ListDomainsResponse response = domains.list(); + + assertNotNull(response); + assertEquals(expectedResponse.getData().size(), response.getData().size()); + } + + @Test + public void testListDomainsWithPagination_Success() throws ResendException { + // Arrange + ListParams params = ListParams.builder().limit(2).build(); + ListDomainsResponse expectedResponse = DomainsUtil.createDomainListResponse(); + List paginatedData = expectedResponse.getData().subList(0, params.getLimit()); + ListDomainsResponse paginatedResponse = new ListDomainsResponse(paginatedData, true); + + when(domains.list(params)).thenReturn(paginatedResponse); + + ListDomainsResponse response = domains.list(params); + + assertNotNull(response); + assertEquals(params.getLimit(), response.getData().size()); + + } } diff --git a/src/test/java/com/resend/services/emails/EmailsTest.java b/src/test/java/com/resend/services/emails/EmailsTest.java index 28a8afc..a3136a9 100644 --- a/src/test/java/com/resend/services/emails/EmailsTest.java +++ b/src/test/java/com/resend/services/emails/EmailsTest.java @@ -1,5 +1,6 @@ package com.resend.services.emails; import com.resend.core.exception.ResendException; +import com.resend.core.net.ListParams; import com.resend.core.net.RequestOptions; import com.resend.services.batch.Batch; import com.resend.services.batch.model.CreateBatchEmailsResponse; @@ -121,4 +122,31 @@ public void testCancelEmail_Success() throws ResendException { assertNotNull(cancelEmailResponse); } + + @Test + public void testListEmails_Success() throws ResendException { + + ListEmailsResponseSuccess expectedResponse = new ListEmailsResponseSuccess(EmailsUtil.createEmailList(), "emails", true); + + when(emails.list()).thenReturn(expectedResponse); + + ListEmailsResponseSuccess response = emails.list(); + + assertNotNull(response); + assertEquals(expectedResponse.getData().size(), response.getData().size()); + } + + @Test + public void testListEmailsWithPagination_Success() throws ResendException { + ListParams params = ListParams.builder() + .limit(3).build(); + ListEmailsResponseSuccess expectedResponse = new ListEmailsResponseSuccess(EmailsUtil.createEmailList(), "emails", true); + + when(emails.list(params)).thenReturn(expectedResponse); + + ListEmailsResponseSuccess response = emails.list(params); + + assertNotNull(response); + assertEquals(params.getLimit(), response.getData().size()); + } } diff --git a/src/test/java/com/resend/services/util/ApiKeysUtil.java b/src/test/java/com/resend/services/util/ApiKeysUtil.java index 1e292ae..ce3e3e8 100644 --- a/src/test/java/com/resend/services/util/ApiKeysUtil.java +++ b/src/test/java/com/resend/services/util/ApiKeysUtil.java @@ -38,7 +38,7 @@ public static final ListApiKeysResponse createListApiKeyResponse() { apiKeys.add(apiKey1); apiKeys.add(apiKey2); - ListApiKeysResponse response = new ListApiKeysResponse(apiKeys); + ListApiKeysResponse response = new ListApiKeysResponse(apiKeys, true); return response; } diff --git a/src/test/java/com/resend/services/util/AudiencesUtil.java b/src/test/java/com/resend/services/util/AudiencesUtil.java index e3b2880..e3d5128 100644 --- a/src/test/java/com/resend/services/util/AudiencesUtil.java +++ b/src/test/java/com/resend/services/util/AudiencesUtil.java @@ -30,6 +30,6 @@ public static ListAudiencesResponseSuccess createAudiencesListResponse() { audList.add(aud2); audList.add(aud3); - return new ListAudiencesResponseSuccess(audList, "list"); + return new ListAudiencesResponseSuccess(audList, "list", true); } } \ No newline at end of file diff --git a/src/test/java/com/resend/services/util/BroadcastsUtil.java b/src/test/java/com/resend/services/util/BroadcastsUtil.java index dc3ad9b..03e97d1 100644 --- a/src/test/java/com/resend/services/util/BroadcastsUtil.java +++ b/src/test/java/com/resend/services/util/BroadcastsUtil.java @@ -75,7 +75,7 @@ public static ListBroadcastsResponseSuccess createBroadcastsListResponse() { broadcastList.add(new Broadcast("2", "78261eea-8f8b-4381-83c6-79fa7120f1cf", "sent", "2024-12-02T10:15:30.000Z", "2024-12-02T11:00:00.000Z", "2024-12-02T12:00:00.000Z")); broadcastList.add(new Broadcast("3", "78261eea-8f8b-4381-83c6-79fa7120f1cf", "queued", "2024-12-03T08:45:00.000Z", null, null)); - return new ListBroadcastsResponseSuccess("list", broadcastList); + return new ListBroadcastsResponseSuccess("list", broadcastList, true); } public static SendBroadcastOptions sendBroadcastRequest() { diff --git a/src/test/java/com/resend/services/util/DomainsUtil.java b/src/test/java/com/resend/services/util/DomainsUtil.java index e7f3eee..8c7039b 100644 --- a/src/test/java/com/resend/services/util/DomainsUtil.java +++ b/src/test/java/com/resend/services/util/DomainsUtil.java @@ -1,7 +1,9 @@ package com.resend.services.util; +import com.resend.services.domains.dto.DomainDTO; import com.resend.services.domains.model.*; import java.util.ArrayList; +import java.util.List; public class DomainsUtil { @@ -12,15 +14,49 @@ public static final CreateDomainOptions createDomainRequest() { .build(); } + public static ListDomainsResponse createDomainListResponse() { + List data = new ArrayList<>(); + + DomainDTO domain1 = new DomainDTO( + "id-1", + "resend.dev", + "2023-04-08T00:11:13.110Z", + "Active", + "us-east-1" + ); + + DomainDTO domain2 = new DomainDTO( + "id-2", + "example.com", + "2023-01-01T12:00:00.000Z", + "Active", + "us-east-2" + ); + + DomainDTO domain3 = new DomainDTO( + "id-3", + "another.com", + "2023-02-15T08:30:00.000Z", + "Inactive", + "us-west-1" + ); + + data.add(domain1); + data.add(domain2); + data.add(domain3); + + return new ListDomainsResponse(data, true); + } + public static final CreateDomainResponse createDomainResponse() { return new CreateDomainResponse( "2c64b27c-6237-4626-85d2-a0a8b5832070", "resend.dev", - "2023-04-08T00:11:13.110779+00:00", // Replace with the actual creation date/time - "Active", // Replace with the desired status - "us-east-1", // Replace with the desired region - "DNSProviderXYZ", // Replace with the desired DNS provider - new ArrayList<>() // An empty list of records or add your records here + "2023-04-08T00:11:13.110779+00:00", + "Active", + "us-east-1", + "DNSProviderXYZ", + new ArrayList<>() ); } diff --git a/src/test/java/com/resend/services/util/EmailsUtil.java b/src/test/java/com/resend/services/util/EmailsUtil.java index ccda985..d31ce92 100644 --- a/src/test/java/com/resend/services/util/EmailsUtil.java +++ b/src/test/java/com/resend/services/util/EmailsUtil.java @@ -6,10 +6,7 @@ import com.resend.services.emails.model.*; import com.resend.core.net.AbstractHttpResponse; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; public class EmailsUtil { @@ -88,6 +85,57 @@ public static Email createTestEmail() { ); } + public static List createEmailList() { + List emails = new ArrayList<>(); + + emails.add(new Email( + "email_1", + "qwert1", + "sender1@example.com", + Arrays.asList("recipient1@example.com"), + "2023-04-08T00:11:13.110779+00:00", + "Test Email Subject 1", + "This is the HTML content 1", + "This is the plain text content 1", + Arrays.asList("bcc1@example.com"), + Arrays.asList("cc1@example.com"), + Arrays.asList("replyto1@example.com"), + "last_event_status_1" + )); + + emails.add(new Email( + "email_2", + "qwert2", + "sender2@example.com", + Arrays.asList("recipient2@example.com"), + "2023-04-09T00:11:13.110779+00:00", + "Test Email Subject 2", + "This is the HTML content 2", + "This is the plain text content 2", + Arrays.asList("bcc2@example.com"), + Arrays.asList("cc2@example.com"), + Arrays.asList("replyto2@example.com"), + "last_event_status_2" + )); + + emails.add(new Email( + "email_3", + "qwert3", + "sender3@example.com", + Arrays.asList("recipient3@example.com"), + "2023-04-10T00:11:13.110779+00:00", + "Test Email Subject 3", + "This is the HTML content 3", + "This is the plain text content 3", + Arrays.asList("bcc3@example.com"), + Arrays.asList("cc3@example.com"), + Arrays.asList("replyto3@example.com"), + "last_event_status_3" + )); + + return emails; + } + public static CreateEmailResponse createSendEmailResponse() { return new CreateEmailResponse("mock_id"); } From b6e70a071798b473c16f66a5d0739099a4c593a1 Mon Sep 17 00:00:00 2001 From: Kewyn Akshlley Date: Fri, 12 Sep 2025 14:51:31 -0300 Subject: [PATCH 2/3] fix: Broadcast test --- .../com/resend/services/broadcasts/BroadcastsTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/resend/services/broadcasts/BroadcastsTest.java b/src/test/java/com/resend/services/broadcasts/BroadcastsTest.java index c34e215..19260d3 100644 --- a/src/test/java/com/resend/services/broadcasts/BroadcastsTest.java +++ b/src/test/java/com/resend/services/broadcasts/BroadcastsTest.java @@ -109,16 +109,19 @@ public void testListBroadcasts_Success() throws ResendException { public void testListBroadcastsWithPagination_Success() throws ResendException { ListParams params = ListParams.builder() .limit(3).build(); + ListBroadcastsResponseSuccess expectedResponse = BroadcastsUtil.createBroadcastsListResponse(); - when(broadcasts.list()).thenReturn(expectedResponse); + when(broadcasts.list(params)).thenReturn(expectedResponse); ListBroadcastsResponseSuccess response = broadcasts.list(params); assertNotNull(response); assertEquals(params.getLimit(), response.getData().size()); assertEquals(expectedResponse.getObject(), response.getObject()); - verify(broadcasts, times(1)).list(); + + verify(broadcasts, times(1)).list(params); } + } From 4eb4a409fbbb21ef4c7056badf478b723ed4be59 Mon Sep 17 00:00:00 2001 From: Kewyn Akshlley Date: Mon, 22 Sep 2025 13:09:37 -0300 Subject: [PATCH 3/3] fix: Typo, expose object attribute and fix docs --- .../com/resend/services/apikeys/ApiKeys.java | 1 + .../apikeys/model/ListApiKeysResponse.java | 17 ++++++++++++++++- .../resend/services/audiences/Audiences.java | 1 + .../model/ListAudiencesResponseSuccess.java | 1 + .../resend/services/broadcasts/Broadcasts.java | 1 + .../model/ListBroadcastsResponseSuccess.java | 1 + .../com/resend/services/contacts/Contacts.java | 1 + .../com/resend/services/domains/Domains.java | 1 + .../domains/model/ListDomainsResponse.java | 17 ++++++++++++++++- .../java/com/resend/services/emails/Emails.java | 1 + .../resend/services/domains/DomainsTest.java | 2 +- .../com/resend/services/util/ApiKeysUtil.java | 2 +- .../com/resend/services/util/DomainsUtil.java | 2 +- 13 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/resend/services/apikeys/ApiKeys.java b/src/main/java/com/resend/services/apikeys/ApiKeys.java index a1b40c3..3cad81c 100644 --- a/src/main/java/com/resend/services/apikeys/ApiKeys.java +++ b/src/main/java/com/resend/services/apikeys/ApiKeys.java @@ -67,6 +67,7 @@ public ListApiKeysResponse list() throws ResendException { /** * Retrieves a paginated list of api keys and returns a ListApiKeysResponse. + * @param params The params used to customize the list. * * @return A ListApiKeysResponse containing the paginated list of api keys. * @throws ResendException If an error occurs during the api keys list retrieval process. diff --git a/src/main/java/com/resend/services/apikeys/model/ListApiKeysResponse.java b/src/main/java/com/resend/services/apikeys/model/ListApiKeysResponse.java index 6bd5cb1..7b6430f 100644 --- a/src/main/java/com/resend/services/apikeys/model/ListApiKeysResponse.java +++ b/src/main/java/com/resend/services/apikeys/model/ListApiKeysResponse.java @@ -15,6 +15,9 @@ public class ListApiKeysResponse { @JsonProperty("has_more") private Boolean hasMore; + @JsonProperty("object") + private String object; + /** * Default constructor. Creates an instance of ListApiKeysResponse with an empty data list. */ @@ -25,10 +28,13 @@ public ListApiKeysResponse() { * Creates an instance of ListApiKeyResponse with the specified data. * * @param data The list of API key items. + * @param hasMore Indicate if there are more items to be returned. + * @param object the object type of the module. */ - public ListApiKeysResponse(List data, Boolean hasMore) { + public ListApiKeysResponse(List data, Boolean hasMore, String object) { this.data = data; this.hasMore = hasMore; + this.object = object; } /** @@ -48,5 +54,14 @@ public List getData() { public Boolean hasMore() { return hasMore; } + + /** + * Get the type of the object. + * + * @return The type of the object. + */ + public String getObject() { + return object; + } } diff --git a/src/main/java/com/resend/services/audiences/Audiences.java b/src/main/java/com/resend/services/audiences/Audiences.java index 7e25889..85aee90 100644 --- a/src/main/java/com/resend/services/audiences/Audiences.java +++ b/src/main/java/com/resend/services/audiences/Audiences.java @@ -62,6 +62,7 @@ public ListAudiencesResponseSuccess list() throws ResendException { /** * Retrieves a paginated list of audiences and returns a ListAudiencesResponseSuccess. + * @param params The params used to customize the list. * * @return A ListAudiencesResponseSuccess containing the paginated list of audiences. * @throws ResendException If an error occurs during the audiences list retrieval process. diff --git a/src/main/java/com/resend/services/audiences/model/ListAudiencesResponseSuccess.java b/src/main/java/com/resend/services/audiences/model/ListAudiencesResponseSuccess.java index 9e6df5e..dd02114 100644 --- a/src/main/java/com/resend/services/audiences/model/ListAudiencesResponseSuccess.java +++ b/src/main/java/com/resend/services/audiences/model/ListAudiencesResponseSuccess.java @@ -29,6 +29,7 @@ public ListAudiencesResponseSuccess() { * * @param data The list of audiences. * @param object The object of the audiences. + * @param hasMore Indicate if there are more items to be returned. */ public ListAudiencesResponseSuccess(List data, String object, Boolean hasMore) { this.data = data; diff --git a/src/main/java/com/resend/services/broadcasts/Broadcasts.java b/src/main/java/com/resend/services/broadcasts/Broadcasts.java index a347147..1f21dd9 100644 --- a/src/main/java/com/resend/services/broadcasts/Broadcasts.java +++ b/src/main/java/com/resend/services/broadcasts/Broadcasts.java @@ -121,6 +121,7 @@ public ListBroadcastsResponseSuccess list() throws ResendException { /** * Retrieves a paginated list of broadcasts and returns a List. + * @param params The params used to customize the list. * * @return A ListBroadcastsResponseSuccess containing the paginated list of broadcasts. * @throws ResendException If an error occurs during the broadcasts list retrieval process. diff --git a/src/main/java/com/resend/services/broadcasts/model/ListBroadcastsResponseSuccess.java b/src/main/java/com/resend/services/broadcasts/model/ListBroadcastsResponseSuccess.java index 51c8c46..2a16de8 100644 --- a/src/main/java/com/resend/services/broadcasts/model/ListBroadcastsResponseSuccess.java +++ b/src/main/java/com/resend/services/broadcasts/model/ListBroadcastsResponseSuccess.java @@ -30,6 +30,7 @@ public ListBroadcastsResponseSuccess() { * * @param object Type of the object (e.g., "list"). * @param data List of Broadcast objects. + * @param hasMore Indicate if there are more items to be returned. */ public ListBroadcastsResponseSuccess(String object, List data, Boolean hasMore) { this.object = object; diff --git a/src/main/java/com/resend/services/contacts/Contacts.java b/src/main/java/com/resend/services/contacts/Contacts.java index 56cc03b..3368561 100644 --- a/src/main/java/com/resend/services/contacts/Contacts.java +++ b/src/main/java/com/resend/services/contacts/Contacts.java @@ -65,6 +65,7 @@ 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 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. */ diff --git a/src/main/java/com/resend/services/domains/Domains.java b/src/main/java/com/resend/services/domains/Domains.java index bd21de3..7ffb5db 100644 --- a/src/main/java/com/resend/services/domains/Domains.java +++ b/src/main/java/com/resend/services/domains/Domains.java @@ -105,6 +105,7 @@ public ListDomainsResponse list() throws ResendException { /** * Retrieves a paginated list of domains and returns a ListDomainsResponse. * + * @param params The params used to customize the list. * @return A ListDomainsResponse containing the paginated list of domains. * @throws ResendException If an error occurs during the domain list retrieval process. */ diff --git a/src/main/java/com/resend/services/domains/model/ListDomainsResponse.java b/src/main/java/com/resend/services/domains/model/ListDomainsResponse.java index 5509ce3..0239a77 100644 --- a/src/main/java/com/resend/services/domains/model/ListDomainsResponse.java +++ b/src/main/java/com/resend/services/domains/model/ListDomainsResponse.java @@ -19,6 +19,9 @@ public class ListDomainsResponse { @JsonProperty("has_more") private Boolean hasMore; + @JsonProperty("object") + private String object; + /** * Default constructor for creating an empty ListDomainsResponse object. */ @@ -29,10 +32,13 @@ public ListDomainsResponse() { * Constructor to create a ListDomainsResponse object with the provided list of DomainDTO objects. * * @param data The list of DomainDTO objects. + * @param hasMore Indicate if there are more items to be returned. + * @param object the object type of the module. */ - public ListDomainsResponse(List data, Boolean hasMore) { + public ListDomainsResponse(List data, Boolean hasMore, String object) { this.data = data; this.hasMore = hasMore; + this.object = object; } /** @@ -52,5 +58,14 @@ public List getData() { public Boolean hasMore() { return hasMore; } + + /** + * Get the type of the object. + * + * @return The type of the object. + */ + public String getObject() { + return object; + } } diff --git a/src/main/java/com/resend/services/emails/Emails.java b/src/main/java/com/resend/services/emails/Emails.java index c36973f..9490081 100644 --- a/src/main/java/com/resend/services/emails/Emails.java +++ b/src/main/java/com/resend/services/emails/Emails.java @@ -176,6 +176,7 @@ public ListEmailsResponseSuccess list() throws ResendException { /** * Retrieves a paginated list of emails and returns a List. * + * @param params The params used to customize the list. * @return A ListEmailsResponseSuccess containing the paginated list of emails. * @throws ResendException If an error occurs during the emails list retrieval process. */ diff --git a/src/test/java/com/resend/services/domains/DomainsTest.java b/src/test/java/com/resend/services/domains/DomainsTest.java index 149031e..492ad1f 100644 --- a/src/test/java/com/resend/services/domains/DomainsTest.java +++ b/src/test/java/com/resend/services/domains/DomainsTest.java @@ -118,7 +118,7 @@ public void testListDomainsWithPagination_Success() throws ResendException { ListParams params = ListParams.builder().limit(2).build(); ListDomainsResponse expectedResponse = DomainsUtil.createDomainListResponse(); List paginatedData = expectedResponse.getData().subList(0, params.getLimit()); - ListDomainsResponse paginatedResponse = new ListDomainsResponse(paginatedData, true); + ListDomainsResponse paginatedResponse = new ListDomainsResponse(paginatedData, true, "list"); when(domains.list(params)).thenReturn(paginatedResponse); diff --git a/src/test/java/com/resend/services/util/ApiKeysUtil.java b/src/test/java/com/resend/services/util/ApiKeysUtil.java index ce3e3e8..cc398b2 100644 --- a/src/test/java/com/resend/services/util/ApiKeysUtil.java +++ b/src/test/java/com/resend/services/util/ApiKeysUtil.java @@ -38,7 +38,7 @@ public static final ListApiKeysResponse createListApiKeyResponse() { apiKeys.add(apiKey1); apiKeys.add(apiKey2); - ListApiKeysResponse response = new ListApiKeysResponse(apiKeys, true); + ListApiKeysResponse response = new ListApiKeysResponse(apiKeys, true, "list"); return response; } diff --git a/src/test/java/com/resend/services/util/DomainsUtil.java b/src/test/java/com/resend/services/util/DomainsUtil.java index 8c7039b..83001cf 100644 --- a/src/test/java/com/resend/services/util/DomainsUtil.java +++ b/src/test/java/com/resend/services/util/DomainsUtil.java @@ -45,7 +45,7 @@ public static ListDomainsResponse createDomainListResponse() { data.add(domain2); data.add(domain3); - return new ListDomainsResponse(data, true); + return new ListDomainsResponse(data, true, "list"); } public static final CreateDomainResponse createDomainResponse() {