-
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
Open
kewynakshlley
wants to merge
1
commit into
main
Choose a base branch
from
feat/domain-claims
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
79 changes: 79 additions & 0 deletions
79
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,79 @@ | ||
| 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.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); | ||
| } | ||
|
|
||
| /** | ||
| * 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 { | ||
| 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); | ||
| } | ||
| } | ||
| } |
81 changes: 81 additions & 0 deletions
81
src/main/java/com/resend/services/domains/model/DomainClaimRecord.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,81 @@ | ||
| package com.resend.services.domains.model; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| /** | ||
| * Represents the TXT DNS record returned within a domain claim response. | ||
| */ | ||
| public class DomainClaimRecord { | ||
|
|
||
| @JsonProperty("type") | ||
| private String type; | ||
|
|
||
| @JsonProperty("name") | ||
| private String name; | ||
|
|
||
| @JsonProperty("value") | ||
| private String value; | ||
|
|
||
| @JsonProperty("ttl") | ||
| private String ttl; | ||
|
|
||
| /** | ||
| * Default constructor. | ||
| */ | ||
| public DomainClaimRecord() { | ||
| } | ||
|
|
||
| /** | ||
| * Constructs a DomainClaimRecord with all fields. | ||
| * | ||
| * @param type The DNS record type. | ||
| * @param name The DNS record name. | ||
| * @param value The DNS record value. | ||
| * @param ttl The TTL for the DNS record. | ||
| */ | ||
| public DomainClaimRecord(final String type, | ||
| final String name, | ||
| final String value, | ||
| final String ttl) { | ||
| this.type = type; | ||
| this.name = name; | ||
| this.value = value; | ||
| this.ttl = ttl; | ||
| } | ||
|
|
||
| /** | ||
| * Get the DNS record type. | ||
| * | ||
| * @return The DNS record type. | ||
| */ | ||
| public String getType() { | ||
| return type; | ||
| } | ||
|
|
||
| /** | ||
| * Get the DNS record name. | ||
| * | ||
| * @return The DNS record name. | ||
| */ | ||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| /** | ||
| * Get the DNS record value. | ||
| * | ||
| * @return The DNS record value. | ||
| */ | ||
| public String getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| /** | ||
| * Get the TTL for the DNS record. | ||
| * | ||
| * @return The TTL. | ||
| */ | ||
| public String getTtl() { | ||
| return ttl; | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Missing null validation on
claimDomainOptionsparameter increate(). Passing null serializes to the string"null", producing a malformed request body.Prompt for AI agents