-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Implement topics module (beta) #64
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
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,136 @@ | ||
| package com.resend.services.topics; | ||
|
|
||
| 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.topics.model.*; | ||
| import okhttp3.MediaType; | ||
|
|
||
| /** | ||
| * Represents the Resend Topics module. | ||
| */ | ||
| public final class Topics extends BaseService { | ||
|
|
||
| /** | ||
| * Constructs an instance of the {@code Topics} class. | ||
| * | ||
| * @param apiKey The apiKey used for authentication. | ||
| */ | ||
| public Topics(final String apiKey) { | ||
| super(apiKey); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new topic. | ||
| * | ||
| * @param createTopicOptions The request containing topic details. | ||
| * @return The response indicating the status of the topic creation. | ||
| * @throws ResendException If an error occurs while creating the topic. | ||
| */ | ||
| public CreateTopicResponseSuccess create(CreateTopicOptions createTopicOptions) throws ResendException { | ||
| String payload = super.resendMapper.writeValue(createTopicOptions); | ||
| AbstractHttpResponse<String> response = super.httpClient.perform("/topics", super.apiKey, HttpMethod.POST, payload, MediaType.get("application/json")); | ||
|
|
||
| if (!response.isSuccessful()) { | ||
| throw new ResendException(response.getCode(), response.getBody()); | ||
| } | ||
|
|
||
| String responseBody = response.getBody(); | ||
| return resendMapper.readValue(responseBody, CreateTopicResponseSuccess.class); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves a topic by its unique identifier. | ||
| * | ||
| * @param topicId The unique identifier of the topic. | ||
| * @return The retrieved topic's details. | ||
| * @throws ResendException If an error occurs while retrieving the topic. | ||
| */ | ||
| public GetTopicResponseSuccess get(String topicId) throws ResendException { | ||
| AbstractHttpResponse<String> response = this.httpClient.perform("/topics/" + topicId, 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, GetTopicResponseSuccess.class); | ||
| } | ||
|
|
||
| /** | ||
| * Updates a topic by its unique identifier. | ||
| * | ||
| * @param topicId The unique identifier of the topic. | ||
| * @param updateTopicOptions The new data for the topic. | ||
| * @return The response indicating the status of the topic update. | ||
| * @throws ResendException If an error occurs while updating the topic. | ||
| */ | ||
| public UpdateTopicResponseSuccess update(String topicId, UpdateTopicOptions updateTopicOptions) throws ResendException { | ||
| String payload = super.resendMapper.writeValue(updateTopicOptions); | ||
| AbstractHttpResponse<String> response = this.httpClient.perform("/topics/" + topicId, super.apiKey, HttpMethod.PATCH, payload, MediaType.get("application/json")); | ||
|
|
||
| if (!response.isSuccessful()) { | ||
| throw new ResendException(response.getCode(), response.getBody()); | ||
| } | ||
|
|
||
| String responseBody = response.getBody(); | ||
| return resendMapper.readValue(responseBody, UpdateTopicResponseSuccess.class); | ||
| } | ||
|
|
||
| /** | ||
| * Removes a topic by its unique identifier. | ||
| * | ||
| * @param topicId The unique identifier of the topic. | ||
| * @return The response indicating the status of the topic removal. | ||
| * @throws ResendException If an error occurs while removing the topic. | ||
| */ | ||
| public RemoveTopicResponseSuccess remove(String topicId) throws ResendException { | ||
| AbstractHttpResponse<String> response = this.httpClient.perform("/topics/" + topicId, super.apiKey, HttpMethod.DELETE, null, MediaType.get("application/json")); | ||
|
|
||
| if (!response.isSuccessful()) { | ||
| throw new ResendException(response.getCode(), response.getBody()); | ||
| } | ||
|
|
||
| String responseBody = response.getBody(); | ||
| return resendMapper.readValue(responseBody, RemoveTopicResponseSuccess.class); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves a list of topics and returns a List. | ||
| * | ||
| * @return A ListTopicsResponse containing the list of topics. | ||
| * @throws ResendException If an error occurs during the topics list retrieval process. | ||
| */ | ||
| public ListTopicsResponseSuccess list() throws ResendException { | ||
| AbstractHttpResponse<String> response = this.httpClient.perform("/topics", 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, ListTopicsResponseSuccess.class); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves a paginated list of topics and returns a List. | ||
| * | ||
| * @param params The params used to customize the list. | ||
| * @return A ListTopicsResponse containing the paginated list of topics. | ||
| * @throws ResendException If an error occurs during the topics list retrieval process. | ||
| */ | ||
| public ListTopicsResponseSuccess list(ListParams params) throws ResendException { | ||
| String pathWithQuery = "/topics" + 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, ListTopicsResponseSuccess.class); | ||
| } | ||
| } | ||
153 changes: 153 additions & 0 deletions
153
src/main/java/com/resend/services/topics/model/AbstractTopic.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,153 @@ | ||
| package com.resend.services.topics.model; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| /** | ||
| * Abstract base class representing common topic attributes. | ||
| * This class contains fields shared across different topic response types. | ||
| */ | ||
| public abstract class AbstractTopic { | ||
|
|
||
| /** | ||
| * The unique identifier of the topic. | ||
| */ | ||
| @JsonProperty("id") | ||
| private String id; | ||
|
|
||
| /** | ||
| * The name of the topic. | ||
| */ | ||
| @JsonProperty("name") | ||
| private String name; | ||
|
|
||
| /** | ||
| * The description of the topic. | ||
| */ | ||
| @JsonProperty("description") | ||
| private String description; | ||
|
|
||
| /** | ||
| * The default subscription preference for new contacts. | ||
| */ | ||
| @JsonProperty("default_subscription") | ||
| private String defaultSubscription; | ||
|
|
||
| /** | ||
| * The creation timestamp of the topic. | ||
| */ | ||
| @JsonProperty("created_at") | ||
| private String createdAt; | ||
|
|
||
| /** | ||
| * Default constructor for creating an empty AbstractTopic object. | ||
| */ | ||
| public AbstractTopic() { | ||
| } | ||
|
|
||
| /** | ||
| * Constructs an AbstractTopic with the provided attributes. | ||
| * | ||
| * @param id The unique identifier of the topic. | ||
| * @param name The name of the topic. | ||
| * @param description The description of the topic. | ||
| * @param defaultSubscription The default subscription preference. | ||
| * @param createdAt The creation timestamp. | ||
| */ | ||
| public AbstractTopic(String id, String name, String description, String defaultSubscription, String createdAt) { | ||
| this.id = id; | ||
| this.name = name; | ||
| this.description = description; | ||
| this.defaultSubscription = defaultSubscription; | ||
| this.createdAt = createdAt; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the unique identifier of the topic. | ||
| * | ||
| * @return The topic ID. | ||
| */ | ||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the unique identifier of the topic. | ||
| * | ||
| * @param id The topic ID to set. | ||
| */ | ||
| public void setId(String id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the name of the topic. | ||
| * | ||
| * @return The topic name. | ||
| */ | ||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the name of the topic. | ||
| * | ||
| * @param name The topic name to set. | ||
| */ | ||
| public void setName(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the description of the topic. | ||
| * | ||
| * @return The topic description. | ||
| */ | ||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the description of the topic. | ||
| * | ||
| * @param description The topic description to set. | ||
| */ | ||
| public void setDescription(String description) { | ||
| this.description = description; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the default subscription preference for new contacts. | ||
| * | ||
| * @return The default subscription preference. | ||
| */ | ||
| public String getDefaultSubscription() { | ||
| return defaultSubscription; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the default subscription preference for new contacts. | ||
| * | ||
| * @param defaultSubscription The default subscription preference to set. | ||
| */ | ||
| public void setDefaultSubscription(String defaultSubscription) { | ||
| this.defaultSubscription = defaultSubscription; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the creation timestamp of the topic. | ||
| * | ||
| * @return The creation timestamp. | ||
| */ | ||
| public String getCreatedAt() { | ||
| return createdAt; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the creation timestamp of the topic. | ||
| * | ||
| * @param createdAt The creation timestamp to set. | ||
| */ | ||
| public void setCreatedAt(String createdAt) { | ||
| this.createdAt = createdAt; | ||
| } | ||
| } |
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.