Skip to content

Commit 4ba086c

Browse files
feat: add contact properties module (#70)
1 parent 42b351b commit 4ba086c

12 files changed

+801
-0
lines changed

src/main/java/com/resend/Resend.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.resend.services.batch.Batch;
66
import com.resend.services.broadcasts.Broadcasts;
77
import com.resend.services.contacts.Contacts;
8+
import com.resend.services.contactproperties.ContactProperties;
89
import com.resend.services.domains.Domains;
910
import com.resend.services.emails.Emails;
1011
import com.resend.services.webhooks.Webhooks;
@@ -67,6 +68,15 @@ public Contacts contacts() {
6768
return new Contacts(apiKey);
6869
}
6970

71+
/**
72+
* Returns a ContactProperties object that can be used to interact with the ContactProperties service.
73+
*
74+
* @return A ContactProperties object.
75+
*/
76+
public ContactProperties contactProperties() {
77+
return new ContactProperties(apiKey);
78+
}
79+
7080
/**
7181
* Returns an Audience object that can be used to interact with the Audiences service.
7282
*
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package com.resend.services.contactproperties;
2+
3+
import com.resend.core.exception.ResendException;
4+
import com.resend.core.net.AbstractHttpResponse;
5+
import com.resend.core.net.HttpMethod;
6+
import com.resend.core.service.BaseService;
7+
import com.resend.services.contactproperties.model.*;
8+
import okhttp3.MediaType;
9+
10+
/**
11+
* Represents the Resend ContactProperties module.
12+
*/
13+
public class ContactProperties extends BaseService {
14+
15+
/**
16+
* Constructs an instance of the {@code ContactProperties} class.
17+
*
18+
* @param apiKey The apiKey used for authentication.
19+
*/
20+
public ContactProperties(final String apiKey) {
21+
super(apiKey);
22+
}
23+
24+
/**
25+
* Creates a ContactProperty.
26+
*
27+
* @param createContactPropertyOptions The ContactProperty details.
28+
* @return The details of the created contact property.
29+
* @throws ResendException If an error occurs during the ContactProperty creation process.
30+
*/
31+
public CreateContactPropertyResponseSuccess create(CreateContactPropertyOptions createContactPropertyOptions) throws ResendException {
32+
String payload = super.resendMapper.writeValue(createContactPropertyOptions);
33+
AbstractHttpResponse<String> response = httpClient.perform("/contact-properties", super.apiKey, HttpMethod.POST, payload, MediaType.get("application/json"));
34+
35+
if (!response.isSuccessful()) {
36+
throw new ResendException(response.getCode(), response.getBody());
37+
}
38+
39+
String responseBody = response.getBody();
40+
return resendMapper.readValue(responseBody, CreateContactPropertyResponseSuccess.class);
41+
}
42+
43+
/**
44+
* Retrieves a list of contact properties and returns a ListContactPropertiesResponseSuccess.
45+
*
46+
* @return A ListContactPropertiesResponseSuccess containing the list of contact properties.
47+
* @throws ResendException If an error occurs during the contact properties list retrieval process.
48+
*/
49+
public ListContactPropertiesResponseSuccess list() throws ResendException {
50+
AbstractHttpResponse<String> response = this.httpClient.perform("/contact-properties", super.apiKey, HttpMethod.GET, null, MediaType.get("application/json"));
51+
52+
if (!response.isSuccessful()) {
53+
throw new ResendException(response.getCode(), response.getBody());
54+
}
55+
56+
String responseBody = response.getBody();
57+
58+
return resendMapper.readValue(responseBody, ListContactPropertiesResponseSuccess.class);
59+
}
60+
61+
/**
62+
* Retrieves a contact property by its unique identifier.
63+
*
64+
* @param id The contact property's id.
65+
* @return The retrieved contact property details.
66+
* @throws ResendException If an error occurs while retrieving the contact property.
67+
*/
68+
public ContactProperty get(String id) throws ResendException {
69+
if (id == null || id.isEmpty()) {
70+
throw new IllegalArgumentException("Contact property id must be provided");
71+
}
72+
73+
AbstractHttpResponse<String> response = this.httpClient.perform("/contact-properties/" + id, super.apiKey, HttpMethod.GET, null, MediaType.get("application/json"));
74+
75+
if (!response.isSuccessful()) {
76+
throw new ResendException(response.getCode(), response.getBody());
77+
}
78+
79+
String responseBody = response.getBody();
80+
81+
return resendMapper.readValue(responseBody, ContactProperty.class);
82+
}
83+
84+
/**
85+
* Updates a contact property based on the provided contact property ID.
86+
*
87+
* @param updateContactPropertyOptions The object with the contact property id and fallback value to update.
88+
* @return The UpdateContactPropertyResponseSuccess with the details of the updated contact property.
89+
* @throws ResendException If an error occurs during the contact property update process.
90+
*/
91+
public UpdateContactPropertyResponseSuccess update(UpdateContactPropertyOptions updateContactPropertyOptions) throws ResendException {
92+
if (updateContactPropertyOptions.getId() == null || updateContactPropertyOptions.getId().isEmpty()) {
93+
throw new IllegalArgumentException("Contact property id must be provided");
94+
}
95+
96+
String payload = super.resendMapper.writeValue(updateContactPropertyOptions);
97+
AbstractHttpResponse<String> response = httpClient.perform("/contact-properties/" + updateContactPropertyOptions.getId(), super.apiKey, HttpMethod.PATCH, payload, MediaType.get("application/json"));
98+
99+
if (!response.isSuccessful()) {
100+
throw new ResendException(response.getCode(), response.getBody());
101+
}
102+
103+
String responseBody = response.getBody();
104+
105+
return resendMapper.readValue(responseBody, UpdateContactPropertyResponseSuccess.class);
106+
}
107+
108+
/**
109+
* Deletes a contact property based on the provided contact property ID.
110+
*
111+
* @param id The identifier of the contact property to delete.
112+
* @return The RemoveContactPropertyResponseSuccess with the details of the removed contact property.
113+
* @throws ResendException If an error occurs during the contact property deletion process.
114+
*/
115+
public RemoveContactPropertyResponseSuccess remove(String id) throws ResendException {
116+
if (id == null || id.isEmpty()) {
117+
throw new IllegalArgumentException("Contact property id must be provided");
118+
}
119+
120+
AbstractHttpResponse<String> response = httpClient.perform("/contact-properties/" + id, super.apiKey, HttpMethod.DELETE, "", null);
121+
122+
if (!response.isSuccessful()) {
123+
throw new ResendException(response.getCode(), response.getBody());
124+
}
125+
126+
String responseBody = response.getBody();
127+
128+
return resendMapper.readValue(responseBody, RemoveContactPropertyResponseSuccess.class);
129+
}
130+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.resend.services.contactproperties.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
/**
6+
* Base contact property with common properties
7+
*/
8+
public abstract class BaseContactProperty {
9+
@JsonProperty("id")
10+
private String id;
11+
12+
@JsonProperty("object")
13+
private String object;
14+
15+
/**
16+
* Default constructor
17+
*/
18+
public BaseContactProperty() {
19+
}
20+
21+
/**
22+
* Constructs a base contact property.
23+
*
24+
* @param id The ID of the contact property.
25+
* @param object The object type of the contact property.
26+
*/
27+
public BaseContactProperty(final String id, final String object) {
28+
this.id = id;
29+
this.object = object;
30+
}
31+
32+
/**
33+
* Gets the ID of the contact property.
34+
*
35+
* @return The ID of the contact property.
36+
*/
37+
public String getId() {
38+
return id;
39+
}
40+
41+
/**
42+
* Gets the object type of the contact property.
43+
*
44+
* @return The object type of the contact property.
45+
*/
46+
public String getObject() {
47+
return object;
48+
}
49+
50+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package com.resend.services.contactproperties.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
/**
6+
* Represents a contact property item.
7+
*/
8+
public class ContactProperty {
9+
10+
@JsonProperty("id")
11+
private String id;
12+
13+
@JsonProperty("key")
14+
private String key;
15+
16+
@JsonProperty("object")
17+
private String object;
18+
19+
@JsonProperty("created_at")
20+
private String createdAt;
21+
22+
@JsonProperty("type")
23+
private String type;
24+
25+
@JsonProperty("fallback_value")
26+
private Object fallbackValue;
27+
28+
/**
29+
* Default constructor
30+
*/
31+
public ContactProperty() {
32+
33+
}
34+
35+
/**
36+
* Creates an instance of ContactProperty with the specified attributes.
37+
*
38+
* @param id The ID of the contact property.
39+
* @param key The key of the contact property.
40+
* @param object The object type of the contact property.
41+
* @param createdAt The creation timestamp of the contact property.
42+
* @param type The type of the contact property.
43+
* @param fallbackValue The fallback value of the contact property.
44+
*/
45+
public ContactProperty(final String id, final String key, final String object, final String createdAt, final String type, final Object fallbackValue) {
46+
this.id = id;
47+
this.key = key;
48+
this.object = object;
49+
this.createdAt = createdAt;
50+
this.type = type;
51+
this.fallbackValue = fallbackValue;
52+
}
53+
54+
/**
55+
* Gets the ID of the contact property.
56+
*
57+
* @return The ID of the contact property.
58+
*/
59+
public String getId() {
60+
return id;
61+
}
62+
63+
/**
64+
* Gets the key of the contact property.
65+
*
66+
* @return The key of the contact property.
67+
*/
68+
public String getKey() {
69+
return key;
70+
}
71+
72+
/**
73+
* Gets the object type of the contact property.
74+
*
75+
* @return The object type of the contact property.
76+
*/
77+
public String getObject() {
78+
return object;
79+
}
80+
81+
/**
82+
* Gets the creation timestamp of the contact property.
83+
*
84+
* @return The creation timestamp of the contact property.
85+
*/
86+
public String getCreatedAt() {
87+
return createdAt;
88+
}
89+
90+
/**
91+
* Gets the type of the contact property.
92+
*
93+
* @return The type of the contact property.
94+
*/
95+
public String getType() {
96+
return type;
97+
}
98+
99+
/**
100+
* Gets the fallback value of the contact property.
101+
*
102+
* @return The fallback value of the contact property.
103+
*/
104+
public Object getFallbackValue() {
105+
return fallbackValue;
106+
}
107+
}

0 commit comments

Comments
 (0)