-
Notifications
You must be signed in to change notification settings - Fork 3
feat: support logs endpoints #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package com.resend.services.logs; | ||
|
|
||
| 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); | ||
| } | ||
| } | ||
47 changes: 47 additions & 0 deletions
47
src/main/java/com/resend/services/logs/model/GetLogResponseSuccess.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/resend/services/logs/model/ListLogsResponseSuccess.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
60
src/main/java/com/resend/services/logs/model/LogEntry.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.