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 @@ -12,6 +12,7 @@
import com.resend.services.webhooks.Webhooks;
import com.resend.services.receiving.Receiving;
import com.resend.services.topics.Topics;
import com.resend.services.logs.Logs;
import com.resend.services.templates.Templates;

/**
Expand Down Expand Up @@ -151,4 +152,13 @@ public Topics topics() {
public Templates templates() {
return new Templates(apiKey);
}

/**
* Returns a Logs object that can be used to interact with the Logs service.
*
* @return A Logs object.
*/
public Logs logs() {
return new Logs(apiKey);
}
}
77 changes: 77 additions & 0 deletions src/main/java/com/resend/services/logs/Logs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.resend.services.logs;
Comment thread
felipefreitag marked this conversation as resolved.

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.logs.model.GetLogResponseSuccess;
import com.resend.services.logs.model.ListLogsResponseSuccess;
import okhttp3.MediaType;

/**
* Represents the Resend Logs module.
*/
public class Logs extends BaseService {

/**
* Constructs an instance of the {@code Logs} class.
*
* @param apiKey The apiKey used for authentication.
*/
public Logs(final String apiKey) {
super(apiKey);
}

/**
* Retrieves a single log entry by its unique identifier.
*
* @param logId The unique identifier of the log.
* @return The retrieved log details.
* @throws ResendException If an error occurs while retrieving the log.
*/
public GetLogResponseSuccess get(String logId) throws ResendException {
AbstractHttpResponse<String> response = this.httpClient.perform("/logs/" + logId, super.apiKey, HttpMethod.GET, null, MediaType.get("application/json"));

if (!response.isSuccessful()) {
throw new ResendException(response.getCode(), response.getBody());
}

return resendMapper.readValue(response.getBody(), GetLogResponseSuccess.class);
}

/**
* Retrieves a list of logs.
*
* @return A ListLogsResponseSuccess containing the list of logs.
* @throws ResendException If an error occurs during the logs list retrieval process.
*/
public ListLogsResponseSuccess list() throws ResendException {
AbstractHttpResponse<String> response = this.httpClient.perform("/logs", super.apiKey, HttpMethod.GET, null, MediaType.get("application/json"));

if (!response.isSuccessful()) {
throw new ResendException(response.getCode(), response.getBody());
}

return resendMapper.readValue(response.getBody(), ListLogsResponseSuccess.class);
}

/**
* Retrieves a paginated list of logs.
*
* @param params The params used to customize the list (limit, after, before).
* @return A ListLogsResponseSuccess containing the paginated list of logs.
* @throws ResendException If an error occurs during the logs list retrieval process.
*/
public ListLogsResponseSuccess list(ListParams params) throws ResendException {
String pathWithQuery = "/logs" + 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());
}

return resendMapper.readValue(response.getBody(), ListLogsResponseSuccess.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.resend.services.logs.model;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Map;

/**
* Represents a successful response for retrieving a single log entry.
*/
public class GetLogResponseSuccess extends Log {

@JsonProperty("object")
private String object;

/**
* Default constructor.
*/
public GetLogResponseSuccess() {
}

/**
* Constructs a GetLogResponseSuccess.
*
* @param id The unique identifier of the log.
* @param createdAt The creation timestamp of the log.
* @param endpoint The API endpoint that was called.
* @param method The HTTP method used.
* @param responseStatus The HTTP response status code.
* @param userAgent The user agent string.
* @param requestBody The request body.
* @param responseBody The response body.
* @param object The object type ("log").
*/
public GetLogResponseSuccess(String id, String createdAt, String endpoint, String method, Integer responseStatus, String userAgent, Map<String, Object> requestBody, Map<String, Object> responseBody, String object) {
super(id, createdAt, endpoint, method, responseStatus, userAgent, requestBody, responseBody);
this.object = object;
}

/**
* Gets the object type.
*
* @return The object type ("log").
*/
public String getObject() {
return object;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.resend.services.logs.model;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

/**
* Represents a successful response for listing logs.
*/
public class ListLogsResponseSuccess {

@JsonProperty("object")
private String object;

@JsonProperty("has_more")
private Boolean hasMore;

@JsonProperty("data")
private List<LogEntry> data;

/**
* Default constructor.
*/
public ListLogsResponseSuccess() {
}

/**
* Constructs a ListLogsResponseSuccess.
*
* @param object The object type ("list").
* @param hasMore Whether there are more items available for pagination.
* @param data The list of log entries.
*/
public ListLogsResponseSuccess(String object, Boolean hasMore, List<LogEntry> data) {
this.object = object;
this.hasMore = hasMore;
this.data = data;
}

public String getObject() { return object; }
public Boolean hasMore() { return hasMore; }
public List<LogEntry> getData() { return data; }
}
73 changes: 73 additions & 0 deletions src/main/java/com/resend/services/logs/model/Log.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.resend.services.logs.model;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Map;

/**
* Represents a log entry for a single API request.
*/
public class Log {

@JsonProperty("id")
private String id;

@JsonProperty("created_at")
private String createdAt;

@JsonProperty("endpoint")
private String endpoint;

@JsonProperty("method")
private String method;

@JsonProperty("response_status")
private Integer responseStatus;

@JsonProperty("user_agent")
private String userAgent;

@JsonProperty("request_body")
private Map<String, Object> requestBody;

@JsonProperty("response_body")
private Map<String, Object> responseBody;

/**
* Default constructor.
*/
public Log() {
}

/**
* Constructs a Log entry.
*
* @param id The unique identifier of the log.
* @param createdAt The creation timestamp of the log.
* @param endpoint The API endpoint that was called.
* @param method The HTTP method used.
* @param responseStatus The HTTP response status code.
* @param userAgent The user agent string.
* @param requestBody The request body.
* @param responseBody The response body.
*/
public Log(String id, String createdAt, String endpoint, String method, Integer responseStatus, String userAgent, Map<String, Object> requestBody, Map<String, Object> responseBody) {
this.id = id;
this.createdAt = createdAt;
this.endpoint = endpoint;
this.method = method;
this.responseStatus = responseStatus;
this.userAgent = userAgent;
this.requestBody = requestBody;
this.responseBody = responseBody;
}

public String getId() { return id; }
public String getCreatedAt() { return createdAt; }
public String getEndpoint() { return endpoint; }
public String getMethod() { return method; }
public Integer getResponseStatus() { return responseStatus; }
public String getUserAgent() { return userAgent; }
public Map<String, Object> getRequestBody() { return requestBody; }
public Map<String, Object> getResponseBody() { return responseBody; }
}
60 changes: 60 additions & 0 deletions src/main/java/com/resend/services/logs/model/LogEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.resend.services.logs.model;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Represents a summary log entry returned in the list logs response.
* Contains a subset of fields compared to the full {@link Log} object.
*/
public class LogEntry {

@JsonProperty("id")
private String id;

@JsonProperty("created_at")
private String createdAt;

@JsonProperty("endpoint")
private String endpoint;

@JsonProperty("method")
private String method;

@JsonProperty("response_status")
private Integer responseStatus;

@JsonProperty("user_agent")
private String userAgent;

/**
* Default constructor.
*/
public LogEntry() {
}

/**
* Constructs a LogEntry.
*
* @param id The unique identifier of the log.
* @param createdAt The creation timestamp of the log.
* @param endpoint The API endpoint that was called.
* @param method The HTTP method used.
* @param responseStatus The HTTP response status code.
* @param userAgent The user agent string.
*/
public LogEntry(String id, String createdAt, String endpoint, String method, Integer responseStatus, String userAgent) {
this.id = id;
this.createdAt = createdAt;
this.endpoint = endpoint;
this.method = method;
this.responseStatus = responseStatus;
this.userAgent = userAgent;
}

public String getId() { return id; }
public String getCreatedAt() { return createdAt; }
public String getEndpoint() { return endpoint; }
public String getMethod() { return method; }
public Integer getResponseStatus() { return responseStatus; }
public String getUserAgent() { return userAgent; }
}
Loading
Loading