From 15e05b9851397866f7993ee493fec53a1e8725e0 Mon Sep 17 00:00:00 2001 From: Kewyn Akshlley Date: Thu, 9 Jul 2026 20:48:44 -0300 Subject: [PATCH 1/3] feat: add oauth grants endpoints --- src/main/java/com/resend/Resend.java | 10 ++ .../services/oauthgrants/OAuthGrants.java | 88 +++++++++++ .../model/ListOAuthGrantsResponseSuccess.java | 66 +++++++++ .../oauthgrants/model/OAuthGrant.java | 137 ++++++++++++++++++ .../oauthgrants/model/OAuthGrantClient.java | 50 +++++++ .../RemoveOAuthGrantResponseSuccess.java | 78 ++++++++++ .../services/oauthgrants/OAuthGrantsTest.java | 124 ++++++++++++++++ .../resend/services/util/OAuthGrantsUtil.java | 52 +++++++ 8 files changed, 605 insertions(+) create mode 100644 src/main/java/com/resend/services/oauthgrants/OAuthGrants.java create mode 100644 src/main/java/com/resend/services/oauthgrants/model/ListOAuthGrantsResponseSuccess.java create mode 100644 src/main/java/com/resend/services/oauthgrants/model/OAuthGrant.java create mode 100644 src/main/java/com/resend/services/oauthgrants/model/OAuthGrantClient.java create mode 100644 src/main/java/com/resend/services/oauthgrants/model/RemoveOAuthGrantResponseSuccess.java create mode 100644 src/test/java/com/resend/services/oauthgrants/OAuthGrantsTest.java create mode 100644 src/test/java/com/resend/services/util/OAuthGrantsUtil.java diff --git a/src/main/java/com/resend/Resend.java b/src/main/java/com/resend/Resend.java index 3ba6306..327890a 100644 --- a/src/main/java/com/resend/Resend.java +++ b/src/main/java/com/resend/Resend.java @@ -15,6 +15,7 @@ import com.resend.services.topics.Topics; import com.resend.services.events.Events; import com.resend.services.logs.Logs; +import com.resend.services.oauthgrants.OAuthGrants; import com.resend.services.templates.Templates; /** @@ -181,4 +182,13 @@ public Events events() { public Automations automations() { return new Automations(apiKey); } + + /** + * Returns an OAuthGrants object that can be used to interact with the OAuthGrants service. + * + * @return An OAuthGrants object. + */ + public OAuthGrants oauthGrants() { + return new OAuthGrants(apiKey); + } } diff --git a/src/main/java/com/resend/services/oauthgrants/OAuthGrants.java b/src/main/java/com/resend/services/oauthgrants/OAuthGrants.java new file mode 100644 index 0000000..1390e7c --- /dev/null +++ b/src/main/java/com/resend/services/oauthgrants/OAuthGrants.java @@ -0,0 +1,88 @@ +package com.resend.services.oauthgrants; + +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.IHttpClient; +import com.resend.core.net.ListParams; +import com.resend.core.service.BaseService; +import com.resend.services.oauthgrants.model.ListOAuthGrantsResponseSuccess; +import com.resend.services.oauthgrants.model.RemoveOAuthGrantResponseSuccess; +import okhttp3.MediaType; + +/** + * Represents the Resend OAuth Grants module. + */ +public class OAuthGrants extends BaseService { + + /** + * Constructs an instance of the {@code OAuthGrants} class. + * + * @param apiKey The apiKey used for authentication. + */ + public OAuthGrants(final String apiKey) { + super(apiKey); + } + + OAuthGrants(final String apiKey, final IHttpClient httpClient) { + super(apiKey, httpClient); + } + + /** + * Retrieves a list of OAuth grants for the authenticated team. + * + * @return A ListOAuthGrantsResponseSuccess containing the list of OAuth grants. + * @throws ResendException If an error occurs during the OAuth grants list retrieval process. + */ + public ListOAuthGrantsResponseSuccess list() throws ResendException { + AbstractHttpResponse response = this.httpClient.perform("/oauth/grants", super.apiKey, HttpMethod.GET, null, MediaType.get("application/json")); + + if (!response.isSuccessful()) { + throw new ResendException(response.getCode(), response.getBody()); + } + + String responseBody = response.getBody(); + + return resendMapper.readValue(responseBody, ListOAuthGrantsResponseSuccess.class); + } + + /** + * Retrieves a paginated list of OAuth grants for the authenticated team. + * + * @param params The params used to customize the list. + * @return A ListOAuthGrantsResponseSuccess containing the paginated list of OAuth grants. + * @throws ResendException If an error occurs during the OAuth grants list retrieval process. + */ + public ListOAuthGrantsResponseSuccess list(ListParams params) throws ResendException { + String pathWithQuery = "/oauth/grants" + URLHelper.parse(params); + AbstractHttpResponse response = this.httpClient.perform(pathWithQuery, super.apiKey, HttpMethod.GET, null, MediaType.get("application/json")); + + if (!response.isSuccessful()) { + throw new ResendException(response.getCode(), response.getBody()); + } + + String responseBody = response.getBody(); + + return resendMapper.readValue(responseBody, ListOAuthGrantsResponseSuccess.class); + } + + /** + * Revokes an OAuth grant based on the provided OAuth grant ID. + * + * @param oauthGrantId The unique identifier of the OAuth grant to revoke. + * @return The RemoveOAuthGrantResponseSuccess with the details of the revoked OAuth grant. + * @throws ResendException If an error occurs during the OAuth grant revocation process. + */ + public RemoveOAuthGrantResponseSuccess remove(String oauthGrantId) throws ResendException { + AbstractHttpResponse response = httpClient.perform("/oauth/grants/" + oauthGrantId, super.apiKey, HttpMethod.DELETE, "", null); + + if (!response.isSuccessful()) { + throw new ResendException(response.getCode(), response.getBody()); + } + + String responseBody = response.getBody(); + + return resendMapper.readValue(responseBody, RemoveOAuthGrantResponseSuccess.class); + } +} diff --git a/src/main/java/com/resend/services/oauthgrants/model/ListOAuthGrantsResponseSuccess.java b/src/main/java/com/resend/services/oauthgrants/model/ListOAuthGrantsResponseSuccess.java new file mode 100644 index 0000000..71abfb9 --- /dev/null +++ b/src/main/java/com/resend/services/oauthgrants/model/ListOAuthGrantsResponseSuccess.java @@ -0,0 +1,66 @@ +package com.resend.services.oauthgrants.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +/** + * Represents a successful response for listing OAuth grants. + */ +public class ListOAuthGrantsResponseSuccess { + + @JsonProperty("object") + private String object; + + @JsonProperty("has_more") + private Boolean hasMore; + + @JsonProperty("data") + private List data; + + /** + * Default constructor. + */ + public ListOAuthGrantsResponseSuccess() { + } + + /** + * Constructs a ListOAuthGrantsResponseSuccess. + * + * @param object The object type ("list"). + * @param hasMore Whether there are more items available for pagination. + * @param data The list of OAuth grants. + */ + public ListOAuthGrantsResponseSuccess(String object, Boolean hasMore, List data) { + this.object = object; + this.hasMore = hasMore; + this.data = data; + } + + /** + * Gets the object type. + * + * @return the object type ("list") + */ + public String getObject() { + return object; + } + + /** + * Checks if there are more items available for pagination. + * + * @return true if more items are available, false otherwise + */ + public Boolean hasMore() { + return hasMore; + } + + /** + * Gets the list of OAuth grants. + * + * @return the list of OAuth grants + */ + public List getData() { + return data; + } +} diff --git a/src/main/java/com/resend/services/oauthgrants/model/OAuthGrant.java b/src/main/java/com/resend/services/oauthgrants/model/OAuthGrant.java new file mode 100644 index 0000000..4016bb7 --- /dev/null +++ b/src/main/java/com/resend/services/oauthgrants/model/OAuthGrant.java @@ -0,0 +1,137 @@ +package com.resend.services.oauthgrants.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +/** + * Represents an OAuth grant for the authenticated team. + */ +public class OAuthGrant { + + @JsonProperty("id") + private String id; + + @JsonProperty("client_id") + private String clientId; + + @JsonProperty("scopes") + private List scopes; + + @JsonProperty("resource") + private String resource; + + @JsonProperty("created_at") + private String createdAt; + + @JsonProperty("revoked_at") + private String revokedAt; + + @JsonProperty("revoked_reason") + private String revokedReason; + + @JsonProperty("client") + private OAuthGrantClient client; + + /** + * Default constructor. + */ + public OAuthGrant() { + } + + /** + * Constructs an OAuthGrant. + * + * @param id The unique identifier of the OAuth grant. + * @param clientId The unique identifier of the OAuth client. + * @param scopes The scopes granted to the OAuth client. + * @param resource The resource the grant is limited to, if any. + * @param createdAt The creation timestamp of the OAuth grant. + * @param revokedAt The revocation timestamp of the OAuth grant, if revoked. + * @param revokedReason The reason the OAuth grant was revoked, if revoked. + * @param client The OAuth client associated with the grant. + */ + public OAuthGrant(String id, String clientId, List scopes, String resource, String createdAt, + String revokedAt, String revokedReason, OAuthGrantClient client) { + this.id = id; + this.clientId = clientId; + this.scopes = scopes; + this.resource = resource; + this.createdAt = createdAt; + this.revokedAt = revokedAt; + this.revokedReason = revokedReason; + this.client = client; + } + + /** + * Gets the unique identifier of the OAuth grant. + * + * @return the OAuth grant ID + */ + public String getId() { + return id; + } + + /** + * Gets the unique identifier of the OAuth client. + * + * @return the OAuth client ID + */ + public String getClientId() { + return clientId; + } + + /** + * Gets the scopes granted to the OAuth client. + * + * @return the granted scopes + */ + public List getScopes() { + return scopes; + } + + /** + * Gets the resource the grant is limited to, if any. + * + * @return the resource, or {@code null} if not limited + */ + public String getResource() { + return resource; + } + + /** + * Gets the creation timestamp of the OAuth grant. + * + * @return the creation timestamp + */ + public String getCreatedAt() { + return createdAt; + } + + /** + * Gets the revocation timestamp of the OAuth grant. + * + * @return the revocation timestamp, or {@code null} if still active + */ + public String getRevokedAt() { + return revokedAt; + } + + /** + * Gets the reason the OAuth grant was revoked. + * + * @return the revocation reason, or {@code null} if still active + */ + public String getRevokedReason() { + return revokedReason; + } + + /** + * Gets the OAuth client associated with the grant. + * + * @return the OAuth client + */ + public OAuthGrantClient getClient() { + return client; + } +} diff --git a/src/main/java/com/resend/services/oauthgrants/model/OAuthGrantClient.java b/src/main/java/com/resend/services/oauthgrants/model/OAuthGrantClient.java new file mode 100644 index 0000000..0731f5d --- /dev/null +++ b/src/main/java/com/resend/services/oauthgrants/model/OAuthGrantClient.java @@ -0,0 +1,50 @@ +package com.resend.services.oauthgrants.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Represents the OAuth client associated with an OAuth grant. + */ +public class OAuthGrantClient { + + @JsonProperty("name") + private String name; + + @JsonProperty("logo_uri") + private String logoUri; + + /** + * Default constructor. + */ + public OAuthGrantClient() { + } + + /** + * Constructs an OAuthGrantClient. + * + * @param name The name of the OAuth client. + * @param logoUri The logo URI of the OAuth client. + */ + public OAuthGrantClient(String name, String logoUri) { + this.name = name; + this.logoUri = logoUri; + } + + /** + * Gets the name of the OAuth client. + * + * @return the client name + */ + public String getName() { + return name; + } + + /** + * Gets the logo URI of the OAuth client. + * + * @return the client logo URI + */ + public String getLogoUri() { + return logoUri; + } +} diff --git a/src/main/java/com/resend/services/oauthgrants/model/RemoveOAuthGrantResponseSuccess.java b/src/main/java/com/resend/services/oauthgrants/model/RemoveOAuthGrantResponseSuccess.java new file mode 100644 index 0000000..d68a07c --- /dev/null +++ b/src/main/java/com/resend/services/oauthgrants/model/RemoveOAuthGrantResponseSuccess.java @@ -0,0 +1,78 @@ +package com.resend.services.oauthgrants.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Represents a successful response for revoking an OAuth grant. + */ +public class RemoveOAuthGrantResponseSuccess { + + @JsonProperty("object") + private String object; + + @JsonProperty("id") + private String id; + + @JsonProperty("revoked_at") + private String revokedAt; + + @JsonProperty("revoked_reason") + private String revokedReason; + + /** + * Default constructor. + */ + public RemoveOAuthGrantResponseSuccess() { + } + + /** + * Constructs a RemoveOAuthGrantResponseSuccess. + * + * @param object The object type ("oauth_grant"). + * @param id The ID of the revoked OAuth grant. + * @param revokedAt The revocation timestamp of the OAuth grant. + * @param revokedReason The reason the OAuth grant was revoked. + */ + public RemoveOAuthGrantResponseSuccess(String object, String id, String revokedAt, String revokedReason) { + this.object = object; + this.id = id; + this.revokedAt = revokedAt; + this.revokedReason = revokedReason; + } + + /** + * Gets the object type. + * + * @return the object type ("oauth_grant") + */ + public String getObject() { + return object; + } + + /** + * Gets the ID of the revoked OAuth grant. + * + * @return the OAuth grant ID + */ + public String getId() { + return id; + } + + /** + * Gets the revocation timestamp of the OAuth grant. + * + * @return the revocation timestamp + */ + public String getRevokedAt() { + return revokedAt; + } + + /** + * Gets the reason the OAuth grant was revoked. + * + * @return the revocation reason + */ + public String getRevokedReason() { + return revokedReason; + } +} diff --git a/src/test/java/com/resend/services/oauthgrants/OAuthGrantsTest.java b/src/test/java/com/resend/services/oauthgrants/OAuthGrantsTest.java new file mode 100644 index 0000000..0f0f7aa --- /dev/null +++ b/src/test/java/com/resend/services/oauthgrants/OAuthGrantsTest.java @@ -0,0 +1,124 @@ +package com.resend.services.oauthgrants; + +import com.resend.core.exception.ResendException; +import com.resend.core.net.AbstractHttpResponse; +import com.resend.core.net.HttpMethod; +import com.resend.core.net.IHttpClient; +import com.resend.core.net.ListParams; +import com.resend.services.oauthgrants.model.ListOAuthGrantsResponseSuccess; +import com.resend.services.oauthgrants.model.RemoveOAuthGrantResponseSuccess; +import okhttp3.MediaType; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.when; + +@SuppressWarnings("unchecked") +public class OAuthGrantsTest { + + private static final String LIST_RESPONSE_JSON = + "{\"object\":\"list\",\"has_more\":false,\"data\":[" + + "{\"id\":\"650e8400-e29b-41d4-a716-446655440001\",\"client_id\":\"430eed87-632a-4ea6-90db-0aace67ec228\"," + + "\"scopes\":[\"emails:send\"],\"resource\":null,\"created_at\":\"2026-04-08 00:11:13.110779+00\"," + + "\"revoked_at\":null,\"revoked_reason\":null," + + "\"client\":{\"name\":\"Resend CLI\",\"logo_uri\":\"https://example.com/logo.png\"}}," + + "{\"id\":\"650e8400-e29b-41d4-a716-446655440002\",\"client_id\":\"430eed87-632a-4ea6-90db-0aace67ec228\"," + + "\"scopes\":[\"emails:send\",\"domains:read\"],\"resource\":\"https://api.resend.com\"," + + "\"created_at\":\"2026-04-07 00:11:13.110779+00\",\"revoked_at\":\"2026-04-09 00:11:13.110779+00\"," + + "\"revoked_reason\":\"revoked_from_api\"," + + "\"client\":{\"name\":\"Resend CLI\",\"logo_uri\":\"https://example.com/logo.png\"}}" + + "]}"; + + private static final String REMOVE_RESPONSE_JSON = + "{\"object\":\"oauth_grant\",\"id\":\"650e8400-e29b-41d4-a716-446655440001\"," + + "\"revoked_at\":\"2026-04-08T00:11:13.110Z\",\"revoked_reason\":\"revoked_from_api\"}"; + + @Mock + private IHttpClient httpClient; + + private OAuthGrants oauthGrants; + + @BeforeEach + public void setUp() { + MockitoAnnotations.openMocks(this); + oauthGrants = new OAuthGrants("test-api-key", httpClient); + } + + @Test + public void testListOAuthGrants_Success() throws ResendException { + AbstractHttpResponse httpResponse = new AbstractHttpResponse<>(200, LIST_RESPONSE_JSON, true); + + when(httpClient.perform(eq("/oauth/grants"), anyString(), eq(HttpMethod.GET), isNull(), any(MediaType.class))) + .thenReturn(httpResponse); + + ListOAuthGrantsResponseSuccess res = oauthGrants.list(); + + assertNotNull(res); + assertEquals("list", res.getObject()); + assertFalse(res.hasMore()); + assertEquals(2, res.getData().size()); + assertEquals("650e8400-e29b-41d4-a716-446655440001", res.getData().get(0).getId()); + assertEquals("emails:send", res.getData().get(0).getScopes().get(0)); + assertNull(res.getData().get(0).getRevokedAt()); + assertEquals("revoked_from_api", res.getData().get(1).getRevokedReason()); + assertEquals("Resend CLI", res.getData().get(0).getClient().getName()); + } + + @Test + public void testListOAuthGrantsWithPagination_Success() throws ResendException { + ListParams params = ListParams.builder().limit(10).build(); + AbstractHttpResponse httpResponse = new AbstractHttpResponse<>(200, LIST_RESPONSE_JSON, true); + + when(httpClient.perform(startsWith("/oauth/grants?"), anyString(), eq(HttpMethod.GET), isNull(), any(MediaType.class))) + .thenReturn(httpResponse); + + ListOAuthGrantsResponseSuccess res = oauthGrants.list(params); + + assertNotNull(res); + assertEquals(2, res.getData().size()); + } + + @Test + public void testListOAuthGrants_ApiError_ThrowsResendException() throws ResendException { + AbstractHttpResponse httpResponse = new AbstractHttpResponse<>(401, "{\"name\":\"unauthorized\",\"message\":\"Invalid API key\"}", false); + + when(httpClient.perform(eq("/oauth/grants"), anyString(), eq(HttpMethod.GET), isNull(), any(MediaType.class))) + .thenReturn(httpResponse); + + ResendException ex = assertThrows(ResendException.class, () -> oauthGrants.list()); + assertEquals(401, (int) ex.getStatusCode()); + } + + @Test + public void testRemoveOAuthGrant_Success() throws ResendException { + String oauthGrantId = "650e8400-e29b-41d4-a716-446655440001"; + AbstractHttpResponse httpResponse = new AbstractHttpResponse<>(200, REMOVE_RESPONSE_JSON, true); + + when(httpClient.perform(eq("/oauth/grants/" + oauthGrantId), anyString(), eq(HttpMethod.DELETE), eq(""), isNull())) + .thenReturn(httpResponse); + + RemoveOAuthGrantResponseSuccess res = oauthGrants.remove(oauthGrantId); + + assertNotNull(res); + assertEquals("oauth_grant", res.getObject()); + assertEquals(oauthGrantId, res.getId()); + assertEquals("revoked_from_api", res.getRevokedReason()); + assertNotNull(res.getRevokedAt()); + } + + @Test + public void testRemoveOAuthGrant_ApiError_ThrowsResendException() throws ResendException { + String oauthGrantId = "does-not-exist"; + AbstractHttpResponse httpResponse = new AbstractHttpResponse<>(404, "{\"name\":\"not_found\",\"message\":\"Grant not found\"}", false); + + when(httpClient.perform(eq("/oauth/grants/" + oauthGrantId), anyString(), eq(HttpMethod.DELETE), eq(""), isNull())) + .thenReturn(httpResponse); + + ResendException ex = assertThrows(ResendException.class, () -> oauthGrants.remove(oauthGrantId)); + assertEquals(404, (int) ex.getStatusCode()); + } +} diff --git a/src/test/java/com/resend/services/util/OAuthGrantsUtil.java b/src/test/java/com/resend/services/util/OAuthGrantsUtil.java new file mode 100644 index 0000000..2ff3ab2 --- /dev/null +++ b/src/test/java/com/resend/services/util/OAuthGrantsUtil.java @@ -0,0 +1,52 @@ +package com.resend.services.util; + +import com.resend.services.oauthgrants.model.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class OAuthGrantsUtil { + + public static ListOAuthGrantsResponseSuccess listOAuthGrantsResponse() { + List grants = new ArrayList<>(); + + OAuthGrantClient client = new OAuthGrantClient("Resend CLI", "https://example.com/logo.png"); + + OAuthGrant grant1 = new OAuthGrant( + "650e8400-e29b-41d4-a716-446655440001", + "430eed87-632a-4ea6-90db-0aace67ec228", + Collections.singletonList("emails:send"), + null, + "2026-04-08 00:11:13.110779+00", + null, + null, + client + ); + + OAuthGrant grant2 = new OAuthGrant( + "650e8400-e29b-41d4-a716-446655440002", + "430eed87-632a-4ea6-90db-0aace67ec228", + java.util.Arrays.asList("emails:send", "domains:read"), + "https://api.resend.com", + "2026-04-07 00:11:13.110779+00", + "2026-04-09 00:11:13.110779+00", + "revoked_from_api", + client + ); + + grants.add(grant1); + grants.add(grant2); + + return new ListOAuthGrantsResponseSuccess("list", false, grants); + } + + public static RemoveOAuthGrantResponseSuccess removeOAuthGrantResponse() { + return new RemoveOAuthGrantResponseSuccess( + "oauth_grant", + "650e8400-e29b-41d4-a716-446655440001", + "2026-04-08T00:11:13.110Z", + "revoked_from_api" + ); + } +} From c55a8a29e14c1dbb6113d25d0cbba449d6f1534d Mon Sep 17 00:00:00 2001 From: Kewyn Akshlley Date: Fri, 10 Jul 2026 08:55:50 -0300 Subject: [PATCH 2/3] Update src/test/java/com/resend/services/oauthgrants/OAuthGrantsTest.java Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --- .../java/com/resend/services/oauthgrants/OAuthGrantsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/resend/services/oauthgrants/OAuthGrantsTest.java b/src/test/java/com/resend/services/oauthgrants/OAuthGrantsTest.java index 0f0f7aa..b4277d8 100644 --- a/src/test/java/com/resend/services/oauthgrants/OAuthGrantsTest.java +++ b/src/test/java/com/resend/services/oauthgrants/OAuthGrantsTest.java @@ -73,7 +73,7 @@ public void testListOAuthGrantsWithPagination_Success() throws ResendException { ListParams params = ListParams.builder().limit(10).build(); AbstractHttpResponse httpResponse = new AbstractHttpResponse<>(200, LIST_RESPONSE_JSON, true); - when(httpClient.perform(startsWith("/oauth/grants?"), anyString(), eq(HttpMethod.GET), isNull(), any(MediaType.class))) + when(httpClient.perform(eq("/oauth/grants?limit=10"), anyString(), eq(HttpMethod.GET), isNull(), any(MediaType.class))) .thenReturn(httpResponse); ListOAuthGrantsResponseSuccess res = oauthGrants.list(params); From 64200e4283ef97915dfefb326bf2fb51e63eb5c7 Mon Sep 17 00:00:00 2001 From: Kewyn Akshlley Date: Fri, 10 Jul 2026 09:23:58 -0300 Subject: [PATCH 3/3] fix: rename remove to revoke in OAuthGrants --- .../resend/services/oauthgrants/OAuthGrants.java | 8 ++++---- ...s.java => RevokeOAuthGrantResponseSuccess.java} | 8 ++++---- .../services/oauthgrants/OAuthGrantsTest.java | 14 +++++++------- .../com/resend/services/util/OAuthGrantsUtil.java | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) rename src/main/java/com/resend/services/oauthgrants/model/{RemoveOAuthGrantResponseSuccess.java => RevokeOAuthGrantResponseSuccess.java} (88%) diff --git a/src/main/java/com/resend/services/oauthgrants/OAuthGrants.java b/src/main/java/com/resend/services/oauthgrants/OAuthGrants.java index 1390e7c..15fd017 100644 --- a/src/main/java/com/resend/services/oauthgrants/OAuthGrants.java +++ b/src/main/java/com/resend/services/oauthgrants/OAuthGrants.java @@ -8,7 +8,7 @@ import com.resend.core.net.ListParams; import com.resend.core.service.BaseService; import com.resend.services.oauthgrants.model.ListOAuthGrantsResponseSuccess; -import com.resend.services.oauthgrants.model.RemoveOAuthGrantResponseSuccess; +import com.resend.services.oauthgrants.model.RevokeOAuthGrantResponseSuccess; import okhttp3.MediaType; /** @@ -71,10 +71,10 @@ public ListOAuthGrantsResponseSuccess list(ListParams params) throws ResendExcep * Revokes an OAuth grant based on the provided OAuth grant ID. * * @param oauthGrantId The unique identifier of the OAuth grant to revoke. - * @return The RemoveOAuthGrantResponseSuccess with the details of the revoked OAuth grant. + * @return The RevokeOAuthGrantResponseSuccess with the details of the revoked OAuth grant. * @throws ResendException If an error occurs during the OAuth grant revocation process. */ - public RemoveOAuthGrantResponseSuccess remove(String oauthGrantId) throws ResendException { + public RevokeOAuthGrantResponseSuccess revoke(String oauthGrantId) throws ResendException { AbstractHttpResponse response = httpClient.perform("/oauth/grants/" + oauthGrantId, super.apiKey, HttpMethod.DELETE, "", null); if (!response.isSuccessful()) { @@ -83,6 +83,6 @@ public RemoveOAuthGrantResponseSuccess remove(String oauthGrantId) throws Resend String responseBody = response.getBody(); - return resendMapper.readValue(responseBody, RemoveOAuthGrantResponseSuccess.class); + return resendMapper.readValue(responseBody, RevokeOAuthGrantResponseSuccess.class); } } diff --git a/src/main/java/com/resend/services/oauthgrants/model/RemoveOAuthGrantResponseSuccess.java b/src/main/java/com/resend/services/oauthgrants/model/RevokeOAuthGrantResponseSuccess.java similarity index 88% rename from src/main/java/com/resend/services/oauthgrants/model/RemoveOAuthGrantResponseSuccess.java rename to src/main/java/com/resend/services/oauthgrants/model/RevokeOAuthGrantResponseSuccess.java index d68a07c..12cbdba 100644 --- a/src/main/java/com/resend/services/oauthgrants/model/RemoveOAuthGrantResponseSuccess.java +++ b/src/main/java/com/resend/services/oauthgrants/model/RevokeOAuthGrantResponseSuccess.java @@ -5,7 +5,7 @@ /** * Represents a successful response for revoking an OAuth grant. */ -public class RemoveOAuthGrantResponseSuccess { +public class RevokeOAuthGrantResponseSuccess { @JsonProperty("object") private String object; @@ -22,18 +22,18 @@ public class RemoveOAuthGrantResponseSuccess { /** * Default constructor. */ - public RemoveOAuthGrantResponseSuccess() { + public RevokeOAuthGrantResponseSuccess() { } /** - * Constructs a RemoveOAuthGrantResponseSuccess. + * Constructs a RevokeOAuthGrantResponseSuccess. * * @param object The object type ("oauth_grant"). * @param id The ID of the revoked OAuth grant. * @param revokedAt The revocation timestamp of the OAuth grant. * @param revokedReason The reason the OAuth grant was revoked. */ - public RemoveOAuthGrantResponseSuccess(String object, String id, String revokedAt, String revokedReason) { + public RevokeOAuthGrantResponseSuccess(String object, String id, String revokedAt, String revokedReason) { this.object = object; this.id = id; this.revokedAt = revokedAt; diff --git a/src/test/java/com/resend/services/oauthgrants/OAuthGrantsTest.java b/src/test/java/com/resend/services/oauthgrants/OAuthGrantsTest.java index b4277d8..604e7f4 100644 --- a/src/test/java/com/resend/services/oauthgrants/OAuthGrantsTest.java +++ b/src/test/java/com/resend/services/oauthgrants/OAuthGrantsTest.java @@ -6,7 +6,7 @@ import com.resend.core.net.IHttpClient; import com.resend.core.net.ListParams; import com.resend.services.oauthgrants.model.ListOAuthGrantsResponseSuccess; -import com.resend.services.oauthgrants.model.RemoveOAuthGrantResponseSuccess; +import com.resend.services.oauthgrants.model.RevokeOAuthGrantResponseSuccess; import okhttp3.MediaType; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -33,7 +33,7 @@ public class OAuthGrantsTest { "\"client\":{\"name\":\"Resend CLI\",\"logo_uri\":\"https://example.com/logo.png\"}}" + "]}"; - private static final String REMOVE_RESPONSE_JSON = + private static final String REVOKE_RESPONSE_JSON = "{\"object\":\"oauth_grant\",\"id\":\"650e8400-e29b-41d4-a716-446655440001\"," + "\"revoked_at\":\"2026-04-08T00:11:13.110Z\",\"revoked_reason\":\"revoked_from_api\"}"; @@ -94,14 +94,14 @@ public void testListOAuthGrants_ApiError_ThrowsResendException() throws ResendEx } @Test - public void testRemoveOAuthGrant_Success() throws ResendException { + public void testRevokeOAuthGrant_Success() throws ResendException { String oauthGrantId = "650e8400-e29b-41d4-a716-446655440001"; - AbstractHttpResponse httpResponse = new AbstractHttpResponse<>(200, REMOVE_RESPONSE_JSON, true); + AbstractHttpResponse httpResponse = new AbstractHttpResponse<>(200, REVOKE_RESPONSE_JSON, true); when(httpClient.perform(eq("/oauth/grants/" + oauthGrantId), anyString(), eq(HttpMethod.DELETE), eq(""), isNull())) .thenReturn(httpResponse); - RemoveOAuthGrantResponseSuccess res = oauthGrants.remove(oauthGrantId); + RevokeOAuthGrantResponseSuccess res = oauthGrants.revoke(oauthGrantId); assertNotNull(res); assertEquals("oauth_grant", res.getObject()); @@ -111,14 +111,14 @@ public void testRemoveOAuthGrant_Success() throws ResendException { } @Test - public void testRemoveOAuthGrant_ApiError_ThrowsResendException() throws ResendException { + public void testRevokeOAuthGrant_ApiError_ThrowsResendException() throws ResendException { String oauthGrantId = "does-not-exist"; AbstractHttpResponse httpResponse = new AbstractHttpResponse<>(404, "{\"name\":\"not_found\",\"message\":\"Grant not found\"}", false); when(httpClient.perform(eq("/oauth/grants/" + oauthGrantId), anyString(), eq(HttpMethod.DELETE), eq(""), isNull())) .thenReturn(httpResponse); - ResendException ex = assertThrows(ResendException.class, () -> oauthGrants.remove(oauthGrantId)); + ResendException ex = assertThrows(ResendException.class, () -> oauthGrants.revoke(oauthGrantId)); assertEquals(404, (int) ex.getStatusCode()); } } diff --git a/src/test/java/com/resend/services/util/OAuthGrantsUtil.java b/src/test/java/com/resend/services/util/OAuthGrantsUtil.java index 2ff3ab2..9e398f5 100644 --- a/src/test/java/com/resend/services/util/OAuthGrantsUtil.java +++ b/src/test/java/com/resend/services/util/OAuthGrantsUtil.java @@ -41,8 +41,8 @@ public static ListOAuthGrantsResponseSuccess listOAuthGrantsResponse() { return new ListOAuthGrantsResponseSuccess("list", false, grants); } - public static RemoveOAuthGrantResponseSuccess removeOAuthGrantResponse() { - return new RemoveOAuthGrantResponseSuccess( + public static RevokeOAuthGrantResponseSuccess revokeOAuthGrantResponse() { + return new RevokeOAuthGrantResponseSuccess( "oauth_grant", "650e8400-e29b-41d4-a716-446655440001", "2026-04-08T00:11:13.110Z",