Skip to content

Commit fab59f9

Browse files
committed
fix: add RemoveContactResponse type, update tests, rm created_at from audiences class
1 parent 176644e commit fab59f9

5 files changed

Lines changed: 53 additions & 26 deletions

File tree

examples/contacts.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@
5050
print(c)
5151

5252
# remove by email
53-
rmed = resend.Contacts.remove(audience_id=audience_id, email=cont_by_email["email"])
53+
rmed: resend.Contacts.RemoveContactResponse = resend.Contacts.remove(
54+
audience_id=audience_id, email=cont_by_email["email"]
55+
)
5456

5557
# remove by id
56-
# rmed: resend.Contact = resend.Contacts.remove(audience_id=audience_id, id=cont["id"])
58+
# rmed: resend.Contacts.RemoveContactResponse = resend.Contacts.remove(audience_id=audience_id, id=cont["id"])
5759

58-
print(f"Removed contact")
60+
print(f"Removed contact with ID: {rmed['contact']}")
5961
print(rmed)

resend/audiences/_audiences.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ class CreateAudienceResponse(TypedDict):
2727
CreateAudienceResponse is the type that wraps the response of the audience that was created
2828
2929
Attributes:
30+
object (str): The object type, "audience"
3031
id (str): The ID of the created audience
3132
name (str): The name of the created audience
3233
created_at (str): When the audience was created
3334
"""
3435

36+
object: str
37+
"""
38+
The object type, "audience"
39+
"""
3540
id: str
3641
"""
3742
The ID of the created audience
@@ -40,10 +45,6 @@ class CreateAudienceResponse(TypedDict):
4045
"""
4146
The name of the created audience
4247
"""
43-
created_at: str
44-
"""
45-
When the audience was created
46-
"""
4748

4849
class CreateParams(TypedDict):
4950
name: str

resend/contacts/_contact.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing_extensions import TypedDict
1+
from typing_extensions import NotRequired, TypedDict
22

33

44
class Contact(TypedDict):
@@ -10,11 +10,11 @@ class Contact(TypedDict):
1010
"""
1111
The email of the contact.
1212
"""
13-
first_name: str
13+
first_name: NotRequired[str]
1414
"""
1515
The first name of the contact.
1616
"""
17-
last_name: str
17+
last_name: NotRequired[str]
1818
"""
1919
The last name of the contact.
2020
"""
@@ -26,7 +26,3 @@ class Contact(TypedDict):
2626
"""
2727
The unsubscribed status of the contact.
2828
"""
29-
deleted: bool
30-
"""
31-
Wether the contact is deleted or not.
32-
"""

resend/contacts/_contacts.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,42 @@
99

1010
class Contacts:
1111

12+
class RemoveContactResponse(TypedDict):
13+
"""
14+
RemoveContactResponse is the type that wraps the response of the contact that was removed
15+
16+
Attributes:
17+
object (str): 'contact'
18+
contact (str): The ID of the removed contact
19+
deleted (bool): Whether the contact was deleted
20+
"""
21+
22+
object: str
23+
"""
24+
The object type: contact
25+
"""
26+
contact: str
27+
"""
28+
The ID of the removed contact.
29+
"""
30+
deleted: bool
31+
"""
32+
Whether the contact was deleted.
33+
"""
34+
1235
class ListResponse(TypedDict):
1336
"""
1437
ListResponse type that wraps a list of contact objects
1538
1639
Attributes:
40+
object (str): The object type: list
1741
data (List[Contact]): A list of contact objects
1842
"""
1943

44+
object: str
45+
"""
46+
The object type: list
47+
"""
2048
data: List[Contact]
2149
"""
2250
A list of contact objects
@@ -195,7 +223,7 @@ def get(
195223
@classmethod
196224
def remove(
197225
cls, audience_id: str, id: Optional[str] = None, email: Optional[str] = None
198-
) -> Contact:
226+
) -> RemoveContactResponse:
199227
"""
200228
Remove a contact by ID or by Email
201229
see more: https://resend.com/docs/api-reference/contacts/delete-contact
@@ -206,14 +234,14 @@ def remove(
206234
email (str): The contact email
207235
208236
Returns:
209-
Contact: The removed contact object
237+
RemoveContactResponse: The removed contact response object
210238
"""
211239
contact = email if id is None else id
212240
if contact is None:
213241
raise ValueError("id or email must be provided")
214242
path = f"/audiences/{audience_id}/contacts/{contact}"
215243

216-
resp = request.Request[Contact](
244+
resp = request.Request[Contacts.RemoveContactResponse](
217245
path=path, params={}, verb="delete"
218246
).perform_with_content()
219247
return resp

tests/contacts_test.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def test_contacts_get(self) -> None:
9393
)
9494
assert contact["id"] == "e169aa45-1ecf-4183-9955-b1499d5701d3"
9595
assert contact["email"] == "steve.wozniak@gmail.com"
96-
assert contact["first_name"] == "Steve"
97-
assert contact["last_name"] == "Wozniak"
96+
assert contact.get("first_name") == "Steve"
97+
assert contact.get("last_name") == "Wozniak"
9898
assert contact["created_at"] == "2023-10-06T23:47:56.678Z"
9999
assert contact["unsubscribed"] is False
100100

@@ -144,7 +144,7 @@ def test_contacts_remove_by_id(self) -> None:
144144
self.set_mock_json(
145145
{
146146
"object": "contact",
147-
"id": "520784e2-887d-4c25-b53c-4ad46ad38100",
147+
"contact": "520784e2-887d-4c25-b53c-4ad46ad38100",
148148
"deleted": True,
149149
}
150150
)
@@ -153,7 +153,7 @@ def test_contacts_remove_by_id(self) -> None:
153153
audience_id="48c269ed-9873-4d60-bdd9-cd7e6fc0b9b8",
154154
id="78261eea-8f8b-4381-83c6-79fa7120f1cf",
155155
)
156-
assert rmed["id"] == "520784e2-887d-4c25-b53c-4ad46ad38100"
156+
assert rmed["contact"] == "520784e2-887d-4c25-b53c-4ad46ad38100"
157157
assert rmed["deleted"] is True
158158

159159
def test_should_remove_contacts_by_id_raise_exception_when_no_content(self) -> None:
@@ -168,16 +168,16 @@ def test_contacts_remove_by_email(self) -> None:
168168
self.set_mock_json(
169169
{
170170
"object": "contact",
171-
"id": "520784e2-887d-4c25-b53c-4ad46ad38100",
171+
"contact": "520784e2-887d-4c25-b53c-4ad46ad38100",
172172
"deleted": True,
173173
}
174174
)
175175

176-
rmed: resend.Contact = resend.Contacts.remove(
176+
rmed: resend.Contacts.RemoveContactResponse = resend.Contacts.remove(
177177
audience_id="48c269ed-9873-4d60-bdd9-cd7e6fc0b9b8",
178178
email="someemail@email.com",
179179
)
180-
assert rmed["id"] == "520784e2-887d-4c25-b53c-4ad46ad38100"
180+
assert rmed["contact"] == "520784e2-887d-4c25-b53c-4ad46ad38100"
181181
assert rmed["deleted"] is True
182182

183183
def test_should_remove_contacts_by_email_raise_exception_when_no_content(
@@ -222,8 +222,8 @@ def test_contacts_list(self) -> None:
222222
)
223223
assert contacts["data"][0]["id"] == "e169aa45-1ecf-4183-9955-b1499d5701d3"
224224
assert contacts["data"][0]["email"] == "steve.wozniak@gmail.com"
225-
assert contacts["data"][0]["first_name"] == "Steve"
226-
assert contacts["data"][0]["last_name"] == "Wozniak"
225+
assert contacts["data"][0].get("first_name") == "Steve"
226+
assert contacts["data"][0].get("last_name") == "Wozniak"
227227
assert contacts["data"][0]["created_at"] == "2023-10-06T23:47:56.678Z"
228228
assert contacts["data"][0]["unsubscribed"] is False
229229

0 commit comments

Comments
 (0)