-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add contact properties module #70
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
130 changes: 130 additions & 0 deletions
130
src/main/java/com/resend/services/contactproperties/ContactProperties.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,130 @@ | ||
| package com.resend.services.contactproperties; | ||
|
|
||
| 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.contactproperties.model.*; | ||
| import okhttp3.MediaType; | ||
|
|
||
| /** | ||
| * Represents the Resend ContactProperties module. | ||
| */ | ||
| public class ContactProperties extends BaseService { | ||
|
|
||
| /** | ||
| * Constructs an instance of the {@code ContactProperties} class. | ||
| * | ||
| * @param apiKey The apiKey used for authentication. | ||
| */ | ||
| public ContactProperties(final String apiKey) { | ||
| super(apiKey); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a ContactProperty. | ||
| * | ||
| * @param createContactPropertyOptions The ContactProperty details. | ||
| * @return The details of the created contact property. | ||
| * @throws ResendException If an error occurs during the ContactProperty creation process. | ||
| */ | ||
| public CreateContactPropertyResponseSuccess create(CreateContactPropertyOptions createContactPropertyOptions) throws ResendException { | ||
| String payload = super.resendMapper.writeValue(createContactPropertyOptions); | ||
| AbstractHttpResponse<String> response = httpClient.perform("/contact-properties", 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, CreateContactPropertyResponseSuccess.class); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves a list of contact properties and returns a ListContactPropertiesResponseSuccess. | ||
| * | ||
| * @return A ListContactPropertiesResponseSuccess containing the list of contact properties. | ||
| * @throws ResendException If an error occurs during the contact properties list retrieval process. | ||
| */ | ||
| public ListContactPropertiesResponseSuccess list() throws ResendException { | ||
| AbstractHttpResponse<String> response = this.httpClient.perform("/contact-properties", 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, ListContactPropertiesResponseSuccess.class); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves a contact property by its unique identifier. | ||
| * | ||
| * @param id The contact property's id. | ||
| * @return The retrieved contact property details. | ||
| * @throws ResendException If an error occurs while retrieving the contact property. | ||
| */ | ||
| public ContactProperty get(String id) throws ResendException { | ||
| if (id == null || id.isEmpty()) { | ||
| throw new IllegalArgumentException("Contact property id must be provided"); | ||
| } | ||
|
|
||
| AbstractHttpResponse<String> response = this.httpClient.perform("/contact-properties/" + id, 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, ContactProperty.class); | ||
| } | ||
|
|
||
| /** | ||
| * Updates a contact property based on the provided contact property ID. | ||
| * | ||
| * @param updateContactPropertyOptions The object with the contact property id and fallback value to update. | ||
| * @return The UpdateContactPropertyResponseSuccess with the details of the updated contact property. | ||
| * @throws ResendException If an error occurs during the contact property update process. | ||
| */ | ||
| public UpdateContactPropertyResponseSuccess update(UpdateContactPropertyOptions updateContactPropertyOptions) throws ResendException { | ||
| if (updateContactPropertyOptions.getId() == null || updateContactPropertyOptions.getId().isEmpty()) { | ||
| throw new IllegalArgumentException("Contact property id must be provided"); | ||
| } | ||
|
|
||
| String payload = super.resendMapper.writeValue(updateContactPropertyOptions); | ||
| AbstractHttpResponse<String> response = httpClient.perform("/contact-properties/" + updateContactPropertyOptions.getId(), 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, UpdateContactPropertyResponseSuccess.class); | ||
| } | ||
|
|
||
| /** | ||
| * Deletes a contact property based on the provided contact property ID. | ||
| * | ||
| * @param id The identifier of the contact property to delete. | ||
| * @return The RemoveContactPropertyResponseSuccess with the details of the removed contact property. | ||
| * @throws ResendException If an error occurs during the contact property deletion process. | ||
| */ | ||
| public RemoveContactPropertyResponseSuccess remove(String id) throws ResendException { | ||
| if (id == null || id.isEmpty()) { | ||
| throw new IllegalArgumentException("Contact property id must be provided"); | ||
| } | ||
|
|
||
| AbstractHttpResponse<String> response = httpClient.perform("/contact-properties/" + id, super.apiKey, HttpMethod.DELETE, "", null); | ||
|
|
||
| if (!response.isSuccessful()) { | ||
| throw new ResendException(response.getCode(), response.getBody()); | ||
| } | ||
|
|
||
| String responseBody = response.getBody(); | ||
|
|
||
| return resendMapper.readValue(responseBody, RemoveContactPropertyResponseSuccess.class); | ||
| } | ||
| } | ||
50 changes: 50 additions & 0 deletions
50
src/main/java/com/resend/services/contactproperties/model/BaseContactProperty.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,50 @@ | ||
| package com.resend.services.contactproperties.model; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| /** | ||
| * Base contact property with common properties | ||
| */ | ||
| public abstract class BaseContactProperty { | ||
| @JsonProperty("id") | ||
| private String id; | ||
|
|
||
| @JsonProperty("object") | ||
| private String object; | ||
|
|
||
| /** | ||
| * Default constructor | ||
| */ | ||
| public BaseContactProperty() { | ||
| } | ||
|
|
||
| /** | ||
| * Constructs a base contact property. | ||
| * | ||
| * @param id The ID of the contact property. | ||
| * @param object The object type of the contact property. | ||
| */ | ||
| public BaseContactProperty(final String id, final String object) { | ||
| this.id = id; | ||
| this.object = object; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the ID of the contact property. | ||
| * | ||
| * @return The ID of the contact property. | ||
| */ | ||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the object type of the contact property. | ||
| * | ||
| * @return The object type of the contact property. | ||
| */ | ||
| public String getObject() { | ||
| return object; | ||
| } | ||
|
|
||
| } |
107 changes: 107 additions & 0 deletions
107
src/main/java/com/resend/services/contactproperties/model/ContactProperty.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,107 @@ | ||
| package com.resend.services.contactproperties.model; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| /** | ||
| * Represents a contact property item. | ||
| */ | ||
| public class ContactProperty { | ||
|
|
||
| @JsonProperty("id") | ||
| private String id; | ||
|
|
||
| @JsonProperty("key") | ||
| private String key; | ||
|
|
||
| @JsonProperty("object") | ||
| private String object; | ||
|
|
||
| @JsonProperty("created_at") | ||
| private String createdAt; | ||
|
|
||
| @JsonProperty("type") | ||
| private String type; | ||
|
|
||
| @JsonProperty("fallback_value") | ||
| private Object fallbackValue; | ||
|
|
||
| /** | ||
| * Default constructor | ||
| */ | ||
| public ContactProperty() { | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Creates an instance of ContactProperty with the specified attributes. | ||
| * | ||
| * @param id The ID of the contact property. | ||
| * @param key The key of the contact property. | ||
| * @param object The object type of the contact property. | ||
| * @param createdAt The creation timestamp of the contact property. | ||
| * @param type The type of the contact property. | ||
| * @param fallbackValue The fallback value of the contact property. | ||
| */ | ||
| public ContactProperty(final String id, final String key, final String object, final String createdAt, final String type, final Object fallbackValue) { | ||
| this.id = id; | ||
| this.key = key; | ||
| this.object = object; | ||
| this.createdAt = createdAt; | ||
| this.type = type; | ||
| this.fallbackValue = fallbackValue; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the ID of the contact property. | ||
| * | ||
| * @return The ID of the contact property. | ||
| */ | ||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the key of the contact property. | ||
| * | ||
| * @return The key of the contact property. | ||
| */ | ||
| public String getKey() { | ||
| return key; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the object type of the contact property. | ||
| * | ||
| * @return The object type of the contact property. | ||
| */ | ||
| public String getObject() { | ||
| return object; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the creation timestamp of the contact property. | ||
| * | ||
| * @return The creation timestamp of the contact property. | ||
| */ | ||
| public String getCreatedAt() { | ||
| return createdAt; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the type of the contact property. | ||
| * | ||
| * @return The type of the contact property. | ||
| */ | ||
| public String getType() { | ||
| return type; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the fallback value of the contact property. | ||
| * | ||
| * @return The fallback value of the contact property. | ||
| */ | ||
| public Object getFallbackValue() { | ||
| return fallbackValue; | ||
| } | ||
| } |
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.
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.
Rule violated: API Key Permission Check SDK Methods
Please double-check that the production Resend API keys already include the scopes needed for the new /contact-properties create/list/get/update/remove calls; otherwise these SDK methods will fail immediately once deployed, violating the API Key Permission Check SDK Methods guideline.
Prompt for AI agents