Skip to content

Commit 23fb1a2

Browse files
gabrielmferndrish
andauthored
fix: wrong response types for creation methods (#158)
Co-authored-by: Derich Pacheco <carlosderich@gmail.com>
1 parent 3149ad5 commit 23fb1a2

12 files changed

Lines changed: 53 additions & 45 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ params: resend.Emails.SendParams = {
5252
],
5353
}
5454

55-
email: resend.Email = resend.Emails.send(params)
55+
email: resend.Emails.SendResponse = resend.Emails.send(params)
5656
print(email)
5757
```

examples/scheduled_email.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# Here is an example on how to create a date in the ISO 8601 format:
2020
# from datetime import datetime
2121
# datetime.now().isoformat()
22-
email: resend.Email = resend.Emails.send(params)
22+
email: resend.Emails.SendResponse = resend.Emails.send(params)
2323

2424
print(f"Email scheduled: {email['id']}")
2525

examples/simple_email.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121

2222

2323
# Without Idempotency Key
24-
email_non_idempotent: resend.Email = resend.Emails.send(params)
24+
email_non_idempotent: resend.Emails.SendResponse = resend.Emails.send(params)
2525
print(f"Sent email without idempotency key: {email_non_idempotent['id']}")
2626

2727
# With Idempotency Key
2828
options: resend.Emails.SendOptions = {
2929
"idempotency_key": "44",
3030
}
31-
email_idempotent: resend.Email = resend.Emails.send(params, options)
31+
email_idempotent: resend.Emails.SendResponse = resend.Emails.send(params, options)
3232
print(f"Sent email with idempotency key: {email_idempotent['id']}")
3333

3434
email_resp: resend.Email = resend.Emails.get(email_id=email_non_idempotent["id"])

examples/with_attachments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
"attachments": [attachment],
2828
}
2929

30-
email: resend.Email = resend.Emails.send(params)
30+
email: resend.Emails.SendResponse = resend.Emails.send(params)
3131
print("Sent email with attachment")
3232
print(email)

examples/with_b64_attachments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
}
2929

3030
# Send email
31-
email: resend.Email = resend.Emails.send(params)
31+
email: resend.Emails.SendResponse = resend.Emails.send(params)
3232
print("Email sent with base64 string attachment")
3333
print(email)

examples/with_custom_http_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ def request(
5858
}
5959

6060

61-
email: resend.Email = resend.Emails.send(params)
61+
email: resend.Emails.SendResponse = resend.Emails.send(params)
6262
print(f"{email}")

examples/with_exception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
}
1515

1616
try:
17-
email: resend.Email = resend.Emails.send(params)
17+
email: resend.Emails.SendResponse = resend.Emails.send(params)
1818
except resend.exceptions.ResendError as e:
1919
print(f"Error sending email: {e}")

examples/with_html_file_as_b64_attachment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
}
2929

3030
# Send email
31-
email: resend.Email = resend.Emails.send(params)
31+
email: resend.Emails.SendResponse = resend.Emails.send(params)
3232
print("Sent email with base64 string attachment")
3333
print("Email ID: ", email["id"])

examples/with_inline_attachments.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"attachments": [local_attachment],
2828
}
2929

30-
local_email: resend.Email = resend.Emails.send(local_params)
30+
local_email: resend.Emails.SendResponse = resend.Emails.send(local_params)
3131
print("Sent email with local inline attachment")
3232
print(local_email)
3333

@@ -46,6 +46,6 @@
4646
"attachments": [remote_attachment],
4747
}
4848

49-
remote_email: resend.Email = resend.Emails.send(remote_params)
49+
remote_email: resend.Emails.SendResponse = resend.Emails.send(remote_params)
5050
print("Sent email with remote inline attachment")
5151
print(remote_email)

resend/emails/_batch.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,19 @@
44

55
from resend import request
66

7-
from ._email import Email
87
from ._emails import Emails
98

109

11-
class _SendOptions(TypedDict):
12-
idempotency_key: NotRequired[str]
10+
class SendEmailResponse(TypedDict):
11+
id: str
1312
"""
14-
Unique key that ensures the same operation is not processed multiple times.
15-
Allows for safe retries without duplicating operations.
16-
If provided, will be sent as the `Idempotency-Key` header.
17-
"""
18-
19-
20-
class _SendResponse(TypedDict):
21-
data: List[Email]
22-
"""
23-
A list of email objects
13+
The sent Email ID.
2414
"""
2515

2616

2717
class Batch:
2818

29-
class SendOptions(_SendOptions):
19+
class SendOptions(TypedDict):
3020
"""
3121
SendOptions is the class that wraps the options for the batch send method.
3222
@@ -36,12 +26,17 @@ class SendOptions(_SendOptions):
3626
If provided, will be sent as the `Idempotency-Key` header.
3727
"""
3828

39-
class SendResponse(_SendResponse):
29+
idempotency_key: NotRequired[str]
30+
"""
31+
Unique key that ensures the same operation is not processed multiple times.
32+
Allows for safe retries without duplicating operations.
33+
If provided, will be sent as the `Idempotency-Key` header.
4034
"""
41-
SendResponse type that wraps a list of email objects
4235

43-
Attributes:
44-
data (List[Email]): A list of email objects
36+
class SendResponse(TypedDict):
37+
data: List[SendEmailResponse]
38+
"""
39+
A list of email objects
4540
"""
4641

4742
@classmethod
@@ -61,7 +56,7 @@ def send(
6156
"""
6257
path = "/emails/batch"
6358

64-
resp = request.Request[_SendResponse](
59+
resp = request.Request[Batch.SendResponse](
6560
path=path,
6661
params=cast(List[Dict[Any, Any]], params),
6762
verb="post",

0 commit comments

Comments
 (0)