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
10 changes: 10 additions & 0 deletions src/main/java/com/resend/Resend.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
}
}
88 changes: 88 additions & 0 deletions src/main/java/com/resend/services/oauthgrants/OAuthGrants.java
Original file line number Diff line number Diff line change
@@ -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.RevokeOAuthGrantResponseSuccess;
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<String> 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<String> 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 RevokeOAuthGrantResponseSuccess with the details of the revoked OAuth grant.
* @throws ResendException If an error occurs during the OAuth grant revocation process.
*/
public RevokeOAuthGrantResponseSuccess revoke(String oauthGrantId) throws ResendException {
AbstractHttpResponse<String> 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, RevokeOAuthGrantResponseSuccess.class);
}
}
Original file line number Diff line number Diff line change
@@ -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<OAuthGrant> 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<OAuthGrant> 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<OAuthGrant> getData() {
return data;
}
}
137 changes: 137 additions & 0 deletions src/main/java/com/resend/services/oauthgrants/model/OAuthGrant.java
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> 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<String> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading
Loading