-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Add domain claims endpoints #110
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
93 changes: 93 additions & 0 deletions
93
src/main/java/com/resend/services/domains/DomainClaims.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,93 @@ | ||
| package com.resend.services.domains; | ||
|
|
||
| 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.domains.model.ClaimDomainOptions; | ||
| import com.resend.services.domains.model.DomainClaimResponseSuccess; | ||
| import okhttp3.MediaType; | ||
|
|
||
| /** | ||
| * Represents the Resend Domain Claims module. | ||
| */ | ||
| public final class DomainClaims extends BaseService { | ||
|
|
||
| /** | ||
| * Constructs an instance of the {@code DomainClaims} class. | ||
| * | ||
| * @param apiKey The apiKey used for authentication. | ||
| */ | ||
| public DomainClaims(final String apiKey) { | ||
| super(apiKey); | ||
| } | ||
|
|
||
| /** | ||
| * Package-private constructor for testing, allowing injection of a mock HTTP client. | ||
| * | ||
| * @param apiKey The apiKey used for authentication. | ||
| * @param httpClient The HTTP client to use. | ||
| */ | ||
| DomainClaims(final String apiKey, final IHttpClient httpClient) { | ||
| super(apiKey, httpClient); | ||
| } | ||
|
|
||
| /** | ||
| * Claims a domain already verified by another team. | ||
| * | ||
| * @param claimDomainOptions The request object containing the domain claim details. | ||
| * @return A DomainClaimResponseSuccess representing the created claim. | ||
| * @throws ResendException If an error occurs during the domain claim process. | ||
| */ | ||
| public DomainClaimResponseSuccess create(ClaimDomainOptions claimDomainOptions) throws ResendException { | ||
| if (claimDomainOptions == null) { | ||
| throw new ResendException("claimDomainOptions must not be null"); | ||
| } | ||
| String payload = super.resendMapper.writeValue(claimDomainOptions); | ||
| AbstractHttpResponse<String> response = httpClient.perform("/domains/claim", 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, DomainClaimResponseSuccess.class); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves the latest claim for a domain. | ||
| * | ||
| * @param domainId The placeholder domain ID returned when the claim was created. | ||
| * @return A DomainClaimResponseSuccess representing the current claim state. | ||
| * @throws ResendException If an error occurs during the retrieval process. | ||
| */ | ||
| public DomainClaimResponseSuccess get(String domainId) throws ResendException { | ||
| AbstractHttpResponse<String> response = httpClient.perform("/domains/" + domainId + "/claim", 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, DomainClaimResponseSuccess.class); | ||
| } | ||
|
|
||
| /** | ||
| * Triggers DNS verification for a domain claim. | ||
| * | ||
| * @param domainId The placeholder domain ID returned when the claim was created. | ||
| * @return A DomainClaimResponseSuccess representing the claim after verification is triggered. | ||
| * @throws ResendException If an error occurs during the verification process. | ||
| */ | ||
| public DomainClaimResponseSuccess verify(String domainId) throws ResendException { | ||
| AbstractHttpResponse<String> response = httpClient.perform("/domains/" + domainId + "/claim/verify", super.apiKey, HttpMethod.POST, "", null); | ||
|
|
||
| if (!response.isSuccessful()) { | ||
| throw new ResendException(response.getCode(), response.getBody()); | ||
| } | ||
|
|
||
| String responseBody = response.getBody(); | ||
| return resendMapper.readValue(responseBody, DomainClaimResponseSuccess.class); | ||
| } | ||
| } | ||
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
200 changes: 200 additions & 0 deletions
200
src/main/java/com/resend/services/domains/model/ClaimDomainOptions.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,200 @@ | ||
| package com.resend.services.domains.model; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| /** | ||
| * Represents a request to claim a domain already verified by another team. | ||
| */ | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| public class ClaimDomainOptions { | ||
|
|
||
| @JsonProperty("name") | ||
| private final String name; | ||
|
|
||
| @JsonProperty("region") | ||
| private final String region; | ||
|
|
||
| @JsonProperty("custom_return_path") | ||
| private final String customReturnPath; | ||
|
|
||
| @JsonProperty("open_tracking") | ||
| private final Boolean openTracking; | ||
|
|
||
| @JsonProperty("click_tracking") | ||
| private final Boolean clickTracking; | ||
|
|
||
| @JsonProperty("tracking_subdomain") | ||
| private final String trackingSubdomain; | ||
|
|
||
| /** | ||
| * Constructs a ClaimDomainOptions object using the provided builder. | ||
| * | ||
| * @param builder The builder to construct the ClaimDomainOptions from. | ||
| */ | ||
| public ClaimDomainOptions(Builder builder) { | ||
| this.name = builder.name; | ||
| this.region = builder.region; | ||
| this.customReturnPath = builder.customReturnPath; | ||
| this.openTracking = builder.openTracking; | ||
| this.clickTracking = builder.clickTracking; | ||
| this.trackingSubdomain = builder.trackingSubdomain; | ||
| } | ||
|
|
||
| /** | ||
| * Get the domain name to claim. | ||
| * | ||
| * @return The domain name. | ||
| */ | ||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| /** | ||
| * Get the region where emails will be sent from. | ||
| * | ||
| * @return The region. | ||
| */ | ||
| public String getRegion() { | ||
| return region; | ||
| } | ||
|
|
||
| /** | ||
| * Get the custom return path subdomain. | ||
| * | ||
| * @return The custom return path. | ||
| */ | ||
| public String getCustomReturnPath() { | ||
| return customReturnPath; | ||
| } | ||
|
|
||
| /** | ||
| * Get whether open tracking is enabled. | ||
| * | ||
| * @return The open tracking setting. | ||
| */ | ||
| public Boolean getOpenTracking() { | ||
| return openTracking; | ||
| } | ||
|
|
||
| /** | ||
| * Get whether click tracking is enabled. | ||
| * | ||
| * @return The click tracking setting. | ||
| */ | ||
| public Boolean getClickTracking() { | ||
| return clickTracking; | ||
| } | ||
|
|
||
| /** | ||
| * Get the subdomain used for click and open tracking. | ||
| * | ||
| * @return The tracking subdomain. | ||
| */ | ||
| public String getTrackingSubdomain() { | ||
| return trackingSubdomain; | ||
| } | ||
|
|
||
| /** | ||
| * Create a new builder instance for constructing ClaimDomainOptions objects. | ||
| * | ||
| * @return A new builder instance. | ||
| */ | ||
| public static Builder builder() { | ||
| return new Builder(); | ||
| } | ||
|
|
||
| /** | ||
| * Builder class for constructing ClaimDomainOptions objects. | ||
| */ | ||
| public static class Builder { | ||
|
|
||
| /** | ||
| * Creates a new Builder instance. | ||
| */ | ||
| public Builder() { | ||
| } | ||
|
|
||
| private String name; | ||
| private String region; | ||
| private String customReturnPath; | ||
| private Boolean openTracking; | ||
| private Boolean clickTracking; | ||
| private String trackingSubdomain; | ||
|
|
||
| /** | ||
| * Set the domain name to claim. | ||
| * | ||
| * @param name The domain name. | ||
| * @return The builder instance. | ||
| */ | ||
| public Builder name(String name) { | ||
| this.name = name; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Set the region where emails will be sent from. | ||
| * | ||
| * @param region The region. | ||
| * @return The builder instance. | ||
| */ | ||
| public Builder region(String region) { | ||
| this.region = region; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Set the custom return path subdomain. | ||
| * | ||
| * @param customReturnPath The custom return path. | ||
| * @return The builder instance. | ||
| */ | ||
| public Builder customReturnPath(String customReturnPath) { | ||
| this.customReturnPath = customReturnPath; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Set whether open tracking is enabled. | ||
| * | ||
| * @param openTracking The open tracking setting. | ||
| * @return The builder instance. | ||
| */ | ||
| public Builder openTracking(Boolean openTracking) { | ||
| this.openTracking = openTracking; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Set whether click tracking is enabled. | ||
| * | ||
| * @param clickTracking The click tracking setting. | ||
| * @return The builder instance. | ||
| */ | ||
| public Builder clickTracking(Boolean clickTracking) { | ||
| this.clickTracking = clickTracking; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Set the subdomain used for click and open tracking. | ||
| * | ||
| * @param trackingSubdomain The tracking subdomain. | ||
| * @return The builder instance. | ||
| */ | ||
| public Builder trackingSubdomain(String trackingSubdomain) { | ||
| this.trackingSubdomain = trackingSubdomain; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Build a new ClaimDomainOptions object. | ||
| * | ||
| * @return A new ClaimDomainOptions object. | ||
| */ | ||
| public ClaimDomainOptions build() { | ||
| return new ClaimDomainOptions(this); | ||
| } | ||
| } | ||
| } |
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.