-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Add suppression module #119
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
2 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
133 changes: 133 additions & 0 deletions
133
src/main/java/com/resend/services/suppressions/Suppressions.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,133 @@ | ||
| package com.resend.services.suppressions; | ||
|
|
||
| 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.service.BaseService; | ||
| import com.resend.services.suppressions.model.*; | ||
| import okhttp3.MediaType; | ||
|
|
||
| /** | ||
| * Represents the Resend Suppressions module. | ||
| */ | ||
| public class Suppressions extends BaseService { | ||
|
|
||
| /** | ||
| * Constructs an instance of the {@code Suppressions} class. | ||
| * | ||
| * @param apiKey The apiKey used for authentication. | ||
| */ | ||
| public Suppressions(final String apiKey) { | ||
| super(apiKey); | ||
| } | ||
|
|
||
| Suppressions(final String apiKey, final IHttpClient httpClient) { | ||
| super(apiKey, httpClient); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a SuppressionsBatch object that can be used to add or remove suppressions in batch. | ||
| * | ||
| * @return A SuppressionsBatch object. | ||
| */ | ||
| public SuppressionsBatch batch() { | ||
| return new SuppressionsBatch(super.apiKey, super.httpClient); | ||
| } | ||
|
|
||
| /** | ||
| * Adds an email address to the suppression list. | ||
| * | ||
| * @param addSuppressionOptions The suppression details. | ||
| * @return The details of the added suppression. | ||
| * @throws ResendException If an error occurs during the suppression creation process. | ||
| */ | ||
| public AddSuppressionResponseSuccess add(AddSuppressionOptions addSuppressionOptions) throws ResendException { | ||
| String payload = super.resendMapper.writeValue(addSuppressionOptions); | ||
| AbstractHttpResponse<String> response = httpClient.perform("/suppressions", 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, AddSuppressionResponseSuccess.class); | ||
| } | ||
|
|
||
| /** | ||
| * Removes a suppression by its unique identifier or by the suppressed email address. | ||
| * | ||
| * @param suppressionIdOrEmail The unique identifier or the suppressed email address. | ||
| * @return The RemoveSuppressionResponseSuccess with the details of the removed suppression. | ||
| * @throws ResendException If an error occurs during the suppression removal process. | ||
| */ | ||
| public RemoveSuppressionResponseSuccess remove(String suppressionIdOrEmail) throws ResendException { | ||
| AbstractHttpResponse<String> response = httpClient.perform("/suppressions/" + suppressionIdOrEmail, super.apiKey, HttpMethod.DELETE, null, MediaType.get("application/json")); | ||
|
kewynakshlley marked this conversation as resolved.
|
||
|
|
||
| if (!response.isSuccessful()) { | ||
| throw new ResendException(response.getCode(), response.getBody()); | ||
| } | ||
|
|
||
| String responseBody = response.getBody(); | ||
|
|
||
| return resendMapper.readValue(responseBody, RemoveSuppressionResponseSuccess.class); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves a suppression by its unique identifier or by the suppressed email address. | ||
| * | ||
| * @param suppressionIdOrEmail The unique identifier or the suppressed email address. | ||
| * @return The retrieved suppression details. | ||
| * @throws ResendException If an error occurs while retrieving the suppression. | ||
| */ | ||
| public GetSuppressionResponseSuccess get(String suppressionIdOrEmail) throws ResendException { | ||
| AbstractHttpResponse<String> response = this.httpClient.perform("/suppressions/" + suppressionIdOrEmail, 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, GetSuppressionResponseSuccess.class); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves a list of suppressions. | ||
| * | ||
| * @return A ListSuppressionsResponseSuccess containing the list of suppressions. | ||
| * @throws ResendException If an error occurs during the suppressions list retrieval process. | ||
| */ | ||
| public ListSuppressionsResponseSuccess list() throws ResendException { | ||
| AbstractHttpResponse<String> response = this.httpClient.perform("/suppressions", 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, ListSuppressionsResponseSuccess.class); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves a paginated list of suppressions with optional filtering by origin. | ||
| * | ||
| * @param params The params used to customize the list. | ||
| * @return A ListSuppressionsResponseSuccess containing the paginated list of suppressions. | ||
| * @throws ResendException If an error occurs during the suppressions list retrieval process. | ||
| */ | ||
| public ListSuppressionsResponseSuccess list(ListSuppressionsParams params) throws ResendException { | ||
| String pathWithQuery = "/suppressions" + (params != null ? params.toQueryString() : ""); | ||
| 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, ListSuppressionsResponseSuccess.class); | ||
| } | ||
| } | ||
69 changes: 69 additions & 0 deletions
69
src/main/java/com/resend/services/suppressions/SuppressionsBatch.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,69 @@ | ||
| package com.resend.services.suppressions; | ||
|
|
||
| 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.service.BaseService; | ||
| import com.resend.services.suppressions.model.*; | ||
| import okhttp3.MediaType; | ||
|
|
||
| /** | ||
| * Represents the Resend Suppressions Batch module. | ||
| */ | ||
| public class SuppressionsBatch extends BaseService { | ||
|
|
||
| /** | ||
| * Constructs an instance of the {@code SuppressionsBatch} class. | ||
| * | ||
| * @param apiKey The apiKey used for authentication. | ||
| */ | ||
| public SuppressionsBatch(final String apiKey) { | ||
| super(apiKey); | ||
| } | ||
|
|
||
| SuppressionsBatch(final String apiKey, final IHttpClient httpClient) { | ||
| super(apiKey, httpClient); | ||
| } | ||
|
|
||
| /** | ||
| * Adds up to 100 email addresses to the suppression list at once. | ||
| * | ||
| * @param addSuppressionsOptions The email addresses to suppress. | ||
| * @return The AddSuppressionsResponseSuccess with the details of the added suppressions. | ||
| * @throws ResendException If an error occurs during the suppressions creation process. | ||
| */ | ||
| public AddSuppressionsResponseSuccess add(AddSuppressionsOptions addSuppressionsOptions) throws ResendException { | ||
| String payload = super.resendMapper.writeValue(addSuppressionsOptions); | ||
| AbstractHttpResponse<String> response = httpClient.perform("/suppressions/batch/add", 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, AddSuppressionsResponseSuccess.class); | ||
| } | ||
|
|
||
| /** | ||
| * Removes up to 100 suppressions from the suppression list at once. | ||
| * Provide either emails or ids, but not both. | ||
| * | ||
| * @param removeSuppressionsOptions The suppressions to remove. | ||
| * @return The RemoveSuppressionsResponseSuccess with the details of the removed suppressions. | ||
| * @throws ResendException If an error occurs during the suppressions removal process. | ||
| */ | ||
| public RemoveSuppressionsResponseSuccess remove(RemoveSuppressionsOptions removeSuppressionsOptions) throws ResendException { | ||
| String payload = super.resendMapper.writeValue(removeSuppressionsOptions); | ||
| AbstractHttpResponse<String> response = httpClient.perform("/suppressions/batch/remove", 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, RemoveSuppressionsResponseSuccess.class); | ||
| } | ||
| } |
72 changes: 72 additions & 0 deletions
72
src/main/java/com/resend/services/suppressions/model/AddSuppressionOptions.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,72 @@ | ||
| package com.resend.services.suppressions.model; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| /** | ||
| * Represents a request to add an email address to the suppression list. | ||
| */ | ||
| public class AddSuppressionOptions { | ||
|
|
||
| @JsonProperty("email") | ||
| private final String email; | ||
|
|
||
| /** | ||
| * Constructs an Add Suppression Options object using the provided builder. | ||
| * | ||
| * @param builder The builder to construct the Add Suppression Options. | ||
| */ | ||
| public AddSuppressionOptions(Builder builder) { | ||
| this.email = builder.email; | ||
| } | ||
|
|
||
| /** | ||
| * Get the email address to suppress. | ||
| * | ||
| * @return The email address to suppress. | ||
| */ | ||
| public String getEmail() { | ||
| return email; | ||
| } | ||
|
|
||
| /** | ||
| * Create a new builder instance for constructing AddSuppressionOptions objects. | ||
| * | ||
| * @return A new builder instance. | ||
| */ | ||
| public static Builder builder() { | ||
| return new Builder(); | ||
| } | ||
|
|
||
| /** | ||
| * Builder class for constructing AddSuppressionOptions objects. | ||
| */ | ||
| public static class Builder { | ||
| /** | ||
| * Creates a new Builder instance. | ||
| */ | ||
| public Builder() { | ||
| } | ||
|
|
||
| private String email; | ||
|
|
||
| /** | ||
| * Set the email address to suppress. | ||
| * | ||
| * @param email The email address to suppress. | ||
| * @return The builder instance. | ||
| */ | ||
| public Builder email(String email) { | ||
| this.email = email; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Build a new AddSuppressionOptions object. | ||
| * | ||
| * @return A new AddSuppressionOptions object. | ||
| */ | ||
| public AddSuppressionOptions build() { | ||
| return new AddSuppressionOptions(this); | ||
| } | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/resend/services/suppressions/model/AddSuppressionResponseSuccess.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,25 @@ | ||
| package com.resend.services.suppressions.model; | ||
|
|
||
| /** | ||
| * Represents a successful response for adding an email address to the suppression list. | ||
| * Extends the AddedSuppression class. | ||
| */ | ||
| public class AddSuppressionResponseSuccess extends AddedSuppression { | ||
|
|
||
| /** | ||
| * Default constructor | ||
| */ | ||
| public AddSuppressionResponseSuccess() { | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Constructs a successful response for adding a suppression. | ||
| * | ||
| * @param object The object type of the suppression. | ||
| * @param id The ID of the suppression. | ||
| */ | ||
| public AddSuppressionResponseSuccess(String object, String id) { | ||
| super(object, id); | ||
| } | ||
| } |
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.