Skip to content

Commit baf880c

Browse files
authored
fix: wrong return types for creation methods (#159)
1 parent 23fb1a2 commit baf880c

17 files changed

Lines changed: 386 additions & 234 deletions

examples/api_keys.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
"name": "example.com",
1111
}
1212

13-
key: resend.ApiKey = resend.ApiKeys.create(params=create_params)
13+
created_key: resend.ApiKeys.CreateApiKeyResponse = resend.ApiKeys.create(
14+
params=create_params
15+
)
1416
print("Created new api key")
15-
print(f"Key id: {key['id']} and token: {key['token']}")
17+
print(f"Key id: {created_key['id']} and token: {created_key['token']}")
1618

1719
keys: resend.ApiKeys.ListResponse = resend.ApiKeys.list()
1820
for key in keys["data"]:
1921
print(key["id"])
2022
print(key["name"])
2123
print(key["created_at"])
2224

23-
if len(keys) > 0:
25+
if len(keys["data"]) > 0:
2426
resend.ApiKeys.remove(api_key_id=keys["data"][0]["id"])

examples/audiences.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
create_params: resend.Audiences.CreateParams = {
1111
"name": "New Audience from Python SDK",
1212
}
13-
audience: resend.Audience = resend.Audiences.create(create_params)
13+
audience: resend.Audiences.CreateAudienceResponse = resend.Audiences.create(
14+
create_params
15+
)
1416
print(f"Created audience: {audience['id']}")
1517
print(audience)
1618

@@ -20,6 +22,8 @@
2022
audiences: resend.Audiences.ListResponse = resend.Audiences.list()
2123
print("List of audiences:", [a["id"] for a in audiences["data"]])
2224

23-
rmed: resend.Audience = resend.Audiences.remove(id=audience["id"])
24-
print(f"Deleted audience")
25+
rmed: resend.Audiences.RemoveAudienceResponse = resend.Audiences.remove(
26+
id=audience["id"]
27+
)
28+
print(f"Deleted audience with ID: {audience['id']}")
2529
print(rmed)

examples/broadcasts.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import os
2-
from typing import List
32

43
import resend
5-
import resend.broadcasts
64

75
if not os.environ["RESEND_API_KEY"]:
86
raise EnvironmentError("RESEND_API_KEY is missing")
@@ -21,7 +19,7 @@
2119
}
2220

2321
broadcast: resend.Broadcasts.CreateResponse = resend.Broadcasts.create(create_params)
24-
print("Created broadcast !")
22+
print("Created broadcast with ID: {}".format(broadcast["id"]))
2523
print(broadcast)
2624

2725
update_params: resend.Broadcasts.UpdateParams = {

examples/contacts.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"unsubscribed": False,
1818
}
1919

20-
contact: resend.Contact = resend.Contacts.create(create_params)
21-
print("Created contact !")
20+
contact: resend.Contacts.CreateContactResponse = resend.Contacts.create(create_params)
21+
print("Created contact with ID: {}".format(contact["id"]))
2222
print(contact)
2323

2424
update_params: resend.Contacts.UpdateParams = {
@@ -28,8 +28,8 @@
2828
"first_name": "Steve",
2929
}
3030

31-
updated: resend.Contact = resend.Contacts.update(update_params)
32-
print("updated contact !")
31+
updated: resend.Contacts.UpdateContactResponse = resend.Contacts.update(update_params)
32+
print("updated contact with ID: {}".format(updated["id"]))
3333
print(updated)
3434

3535
cont_by_id: resend.Contact = resend.Contacts.get(
@@ -46,14 +46,16 @@
4646

4747
contacts: resend.Contacts.ListResponse = resend.Contacts.list(audience_id=audience_id)
4848
print("List of contacts")
49-
for contact in contacts["data"]:
50-
print(contact)
49+
for c in contacts["data"]:
50+
print(c)
5151

5252
# remove by email
53-
rmed = resend.Contacts.remove(audience_id=audience_id, email=contact["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)

examples/domains.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"region": "us-east-1",
1313
"custom_return_path": "outbound",
1414
}
15-
domain: resend.Domain = resend.Domains.create(params=create_params)
15+
domain: resend.Domains.CreateDomainResponse = resend.Domains.create(
16+
params=create_params
17+
)
1618
print(domain)
1719

1820
retrieved: resend.Domain = resend.Domains.get(domain_id=domain["id"])

resend/api_keys/_api_key.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
class ApiKey(TypedDict):
55
id: str
66
"""
7-
The api key ID
8-
"""
9-
token: str
10-
"""
11-
The api key token
7+
The API key ID
128
"""
139
name: str
1410
"""
15-
The api key token
11+
The API key name
1612
"""
1713
created_at: str
1814
"""
19-
Api key creation date
15+
The API key creation date
2016
"""

resend/api_keys/_api_keys.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,37 @@
66
from resend.api_keys._api_key import ApiKey
77

88

9-
class _ListResponse(TypedDict):
10-
data: List[ApiKey]
11-
"""
12-
A list of API key objects
13-
"""
14-
15-
169
class ApiKeys:
1710

18-
class ListResponse(_ListResponse):
11+
class ListResponse(TypedDict):
1912
"""
2013
ListResponse type that wraps a list of API key objects
2114
2215
Attributes:
23-
data (List[Dict[str, Any]]): A list of API key objects
16+
data (List[ApiKey]): A list of API key objects
17+
"""
18+
19+
data: List[ApiKey]
20+
"""
21+
A list of API key objects
22+
"""
23+
24+
class CreateApiKeyResponse(TypedDict):
25+
"""
26+
CreateApiKeyResponse is the type that wraps the response of the API key that was created
27+
28+
Attributes:
29+
id (str): The ID of the created API key
30+
token (str): The token of the created API key
31+
"""
32+
33+
id: str
34+
"""
35+
The ID of the created API key
36+
"""
37+
token: str
38+
"""
39+
The token of the created API key
2440
"""
2541

2642
class CreateParams(TypedDict):
@@ -41,7 +57,7 @@ class CreateParams(TypedDict):
4157
"""
4258

4359
@classmethod
44-
def create(cls, params: CreateParams) -> ApiKey:
60+
def create(cls, params: CreateParams) -> CreateApiKeyResponse:
4561
"""
4662
Add a new API key to authenticate communications with Resend.
4763
see more: https://resend.com/docs/api-reference/api-keys/create-api-key
@@ -50,10 +66,10 @@ def create(cls, params: CreateParams) -> ApiKey:
5066
params (CreateParams): The API key creation parameters
5167
5268
Returns:
53-
ApiKey: The new API key object
69+
CreateApiKeyResponse: The created API key response with id and token
5470
"""
5571
path = "/api-keys"
56-
resp = request.Request[ApiKey](
72+
resp = request.Request[ApiKeys.CreateApiKeyResponse](
5773
path=path, params=cast(Dict[Any, Any], params), verb="post"
5874
).perform_with_content()
5975
return resp
@@ -68,7 +84,7 @@ def list(cls) -> ListResponse:
6884
ListResponse: A list of API key objects
6985
"""
7086
path = "/api-keys"
71-
resp = request.Request[_ListResponse](
87+
resp = request.Request[ApiKeys.ListResponse](
7288
path=path, params={}, verb="get"
7389
).perform_with_content()
7490
return resp

resend/audiences/_audience.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,3 @@ class Audience(TypedDict):
1414
"""
1515
The date and time the audience was created.
1616
"""
17-
deleted: bool
18-
"""
19-
Wether the audience was deleted. Only returned on the "remove" call
20-
"""

resend/audiences/_audiences.py

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,80 @@
77
from ._audience import Audience
88

99

10-
class _ListResponse(TypedDict):
11-
data: List[Audience]
12-
"""
13-
A list of audience objects
14-
"""
10+
class Audiences:
1511

12+
class RemoveAudienceResponse(TypedDict):
13+
"""
14+
RemoveAudienceResponse is the type that wraps the response of the audience that was removed
1615
17-
class Audiences:
16+
Attributes:
17+
object (str): The object type, "audience"
18+
id (str): The ID of the removed audience
19+
deleted (bool): Whether the audience was deleted
20+
"""
1821

19-
class ListResponse(_ListResponse):
22+
object: str
23+
"""
24+
The object type, "audience"
25+
"""
26+
id: str
27+
"""
28+
The ID of the removed audience
29+
"""
30+
deleted: bool
31+
"""
32+
Whether the audience was deleted
33+
"""
34+
35+
class ListResponse(TypedDict):
2036
"""
2137
ListResponse type that wraps a list of audience objects
2238
2339
Attributes:
40+
object (str): The object type, "list"
2441
data (List[Audience]): A list of audience objects
2542
"""
2643

44+
object: str
45+
"""
46+
The object type, "list"
47+
"""
48+
data: List[Audience]
49+
"""
50+
A list of audience objects
51+
"""
52+
53+
class CreateAudienceResponse(TypedDict):
54+
"""
55+
CreateAudienceResponse is the type that wraps the response of the audience that was created
56+
57+
Attributes:
58+
object (str): The object type, "audience"
59+
id (str): The ID of the created audience
60+
name (str): The name of the created audience
61+
"""
62+
63+
object: str
64+
"""
65+
The object type, "audience"
66+
"""
67+
id: str
68+
"""
69+
The ID of the created audience
70+
"""
71+
name: str
72+
"""
73+
The name of the created audience
74+
"""
75+
2776
class CreateParams(TypedDict):
2877
name: str
2978
"""
3079
The name of the audience.
3180
"""
3281

3382
@classmethod
34-
def create(cls, params: CreateParams) -> Audience:
83+
def create(cls, params: CreateParams) -> CreateAudienceResponse:
3584
"""
3685
Create a list of contacts.
3786
see more: https://resend.com/docs/api-reference/audiences/create-audience
@@ -40,10 +89,11 @@ def create(cls, params: CreateParams) -> Audience:
4089
params (CreateParams): The audience creation parameters
4190
4291
Returns:
43-
Audience: The new audience object
92+
CreateAudienceResponse: The created audience response
4493
"""
94+
4595
path = "/audiences"
46-
resp = request.Request[Audience](
96+
resp = request.Request[Audiences.CreateAudienceResponse](
4797
path=path, params=cast(Dict[Any, Any], params), verb="post"
4898
).perform_with_content()
4999
return resp
@@ -58,7 +108,7 @@ def list(cls) -> ListResponse:
58108
ListResponse: A list of audience objects
59109
"""
60110
path = "/audiences/"
61-
resp = request.Request[_ListResponse](
111+
resp = request.Request[Audiences.ListResponse](
62112
path=path, params={}, verb="get"
63113
).perform_with_content()
64114
return resp
@@ -82,7 +132,7 @@ def get(cls, id: str) -> Audience:
82132
return resp
83133

84134
@classmethod
85-
def remove(cls, id: str) -> Audience:
135+
def remove(cls, id: str) -> RemoveAudienceResponse:
86136
"""
87137
Delete a single audience.
88138
see more: https://resend.com/docs/api-reference/audiences/delete-audience
@@ -91,10 +141,10 @@ def remove(cls, id: str) -> Audience:
91141
id (str): The audience ID
92142
93143
Returns:
94-
Audience: The audience object
144+
RemoveAudienceResponse: The removed audience response
95145
"""
96146
path = f"/audiences/{id}"
97-
resp = request.Request[Audience](
147+
resp = request.Request[Audiences.RemoveAudienceResponse](
98148
path=path, params={}, verb="delete"
99149
).perform_with_content()
100150
return resp

0 commit comments

Comments
 (0)