Skip to content

Commit 45e451e

Browse files
authored
feat: make new attachments API conform to updated spec (#174)
1 parent c10c805 commit 45e451e

9 files changed

Lines changed: 179 additions & 88 deletions

File tree

examples/receiving_email.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import resend
44
# Type imports
5-
from resend import AttachmentsReceiving, EmailsReceiving
5+
from resend import EmailsReceiving
66

77
if not os.environ["RESEND_API_KEY"]:
88
raise EnvironmentError("RESEND_API_KEY is missing")
@@ -102,7 +102,7 @@
102102
print(f"Next page has more: {next_page['has_more']}")
103103

104104
print("\n--- Listing All Attachments ---")
105-
all_attachments: AttachmentsReceiving.ListResponse = resend.Attachments.Receiving.list(
105+
all_attachments: EmailsReceiving.Attachments.ListResponse = resend.Emails.Receiving.Attachments.list(
106106
email_id=email_id
107107
)
108108

@@ -123,8 +123,8 @@
123123

124124
print(f"\n--- Retrieving Attachment Details: {first_attachment['filename']} ---")
125125

126-
attachment_details: resend.ReceivedEmailAttachmentDetails = (
127-
resend.Attachments.Receiving.get(
126+
attachment_details: resend.EmailAttachmentDetails = (
127+
resend.Emails.Receiving.Attachments.get(
128128
email_id=email_id,
129129
attachment_id=attachment_id,
130130
)

resend/__init__.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from .api_keys._api_key import ApiKey
44
from .api_keys._api_keys import ApiKeys
5-
from .attachments._attachments import Attachments
6-
from .attachments._receiving import Receiving as AttachmentsReceiving
75
from .audiences._audience import Audience
86
from .audiences._audiences import Audiences
97
from .broadcasts._broadcast import Broadcast
@@ -13,12 +11,12 @@
1311
from .domains._domain import Domain
1412
from .domains._domains import Domains
1513
from .emails._attachment import Attachment, RemoteAttachment
14+
from .emails._attachments import Attachments as EmailAttachments
1615
from .emails._batch import Batch, BatchValidationError
1716
from .emails._email import Email
1817
from .emails._emails import Emails
19-
from .emails._received_email import (ListReceivedEmail, ReceivedEmail,
20-
ReceivedEmailAttachment,
21-
ReceivedEmailAttachmentDetails)
18+
from .emails._received_email import (EmailAttachment, EmailAttachmentDetails,
19+
ListReceivedEmail, ReceivedEmail)
2220
from .emails._receiving import Receiving as EmailsReceiving
2321
from .emails._tag import Tag
2422
from .http_client import HTTPClient
@@ -53,7 +51,6 @@
5351
"Contacts",
5452
"Broadcasts",
5553
"Webhooks",
56-
"Attachments",
5754
"Topics",
5855
# Types
5956
"Audience",
@@ -73,12 +70,12 @@
7370
"Topic",
7471
"BatchValidationError",
7572
"ReceivedEmail",
76-
"ReceivedEmailAttachment",
77-
"ReceivedEmailAttachmentDetails",
73+
"EmailAttachment",
74+
"EmailAttachmentDetails",
7875
"ListReceivedEmail",
7976
# Receiving types (for type hints)
8077
"EmailsReceiving",
81-
"AttachmentsReceiving",
78+
"EmailAttachments",
8279
# Default HTTP Client
8380
"RequestsClient",
8481
]

resend/attachments/__init__.py

Whitespace-only changes.

resend/attachments/_attachments.py

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,11 @@
33
from typing_extensions import NotRequired, TypedDict
44

55
from resend import request
6-
from resend.emails._received_email import (ReceivedEmailAttachment,
7-
ReceivedEmailAttachmentDetails)
6+
from resend.emails._received_email import (EmailAttachment,
7+
EmailAttachmentDetails)
88
from resend.pagination_helper import PaginationHelper
99

1010

11-
# Internal wrapper type for get attachment API response
12-
class _GetAttachmentResponse(TypedDict):
13-
object: str
14-
data: ReceivedEmailAttachmentDetails
15-
16-
1711
class _ListParams(TypedDict):
1812
limit: NotRequired[int]
1913
"""
@@ -34,7 +28,7 @@ class _ListResponse(TypedDict):
3428
"""
3529
The object type: "list"
3630
"""
37-
data: List[ReceivedEmailAttachment]
31+
data: List[EmailAttachment]
3832
"""
3933
The list of attachment objects.
4034
"""
@@ -44,9 +38,9 @@ class _ListResponse(TypedDict):
4438
"""
4539

4640

47-
class Receiving:
41+
class Attachments:
4842
"""
49-
Receiving class that provides methods for retrieving attachments from received emails.
43+
Attachments class that provides methods for retrieving attachments from sent emails.
5044
"""
5145

5246
class ListParams(_ListParams):
@@ -65,49 +59,48 @@ class ListResponse(_ListResponse):
6559
6660
Attributes:
6761
object (str): The object type: "list"
68-
data (List[ReceivedEmailAttachment]): The list of attachment objects.
62+
data (List[EmailAttachment]): The list of attachment objects.
6963
has_more (bool): Whether there are more attachments available for pagination.
7064
"""
7165

7266
@classmethod
73-
def get(cls, email_id: str, attachment_id: str) -> ReceivedEmailAttachmentDetails:
67+
def get(cls, email_id: str, attachment_id: str) -> EmailAttachmentDetails:
7468
"""
75-
Retrieve a single attachment from a received email.
76-
see more: https://resend.com/docs/api-reference/attachments/retrieve-attachment
69+
Retrieve a single attachment from a sent email.
70+
see more: https://resend.com/docs/api-reference/attachments/retrieve-sent-email-attachment
7771
7872
Args:
79-
email_id (str): The ID of the received email
73+
email_id (str): The ID of the sent email
8074
attachment_id (str): The ID of the attachment to retrieve
8175
8276
Returns:
83-
ReceivedEmailAttachmentDetails: The attachment details including download URL
77+
EmailAttachmentDetails: The attachment details including download URL
8478
"""
85-
path = f"/emails/receiving/{email_id}/attachments/{attachment_id}"
86-
resp = request.Request[_GetAttachmentResponse](
79+
path = f"/emails/{email_id}/attachments/{attachment_id}"
80+
resp = request.Request[EmailAttachmentDetails](
8781
path=path,
8882
params={},
8983
verb="get",
9084
).perform_with_content()
91-
# Extract the data field from the wrapped response
92-
return resp["data"]
85+
return resp
9386

9487
@classmethod
9588
def list(cls, email_id: str, params: Optional[ListParams] = None) -> ListResponse:
9689
"""
97-
Retrieve a list of attachments from a received email.
98-
see more: https://resend.com/docs/api-reference/attachments/list-attachments
90+
Retrieve a list of attachments from a sent email.
91+
see more: https://resend.com/docs/api-reference/attachments/list-sent-email-attachments
9992
10093
Args:
101-
email_id (str): The ID of the received email
94+
email_id (str): The ID of the sent email
10295
params (Optional[ListParams]): The list parameters for pagination
10396
10497
Returns:
10598
ListResponse: A paginated list of attachment objects
10699
"""
107-
base_path = f"/emails/receiving/{email_id}/attachments"
100+
base_path = f"/emails/{email_id}/attachments"
108101
query_params = cast(Dict[Any, Any], params) if params else None
109102
path = PaginationHelper.build_paginated_path(base_path, query_params)
110-
resp = request.Request[Receiving.ListResponse](
103+
resp = request.Request[Attachments.ListResponse](
111104
path=path,
112105
params={},
113106
verb="get",

resend/emails/_emails.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from resend import request
66
from resend.emails._attachment import Attachment, RemoteAttachment
7+
from resend.emails._attachments import Attachments
78
from resend.emails._email import Email
89
from resend.emails._receiving import Receiving
910
from resend.emails._tag import Tag
@@ -104,6 +105,7 @@ class _SendParamsDefault(_SendParamsFrom):
104105

105106

106107
class Emails:
108+
Attachments = Attachments
107109
Receiving = Receiving
108110

109111
class CancelScheduledEmailResponse(_CancelScheduledEmailResponse):

resend/emails/_received_email.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from typing_extensions import NotRequired, TypedDict
44

55

6-
class ReceivedEmailAttachment(TypedDict):
6+
class EmailAttachment(TypedDict):
77
"""
8-
ReceivedEmailAttachment type that wraps an attachment object from a received email.
8+
EmailAttachment type that wraps an attachment object from an email.
99
1010
Attributes:
1111
id (str): The attachment ID.
@@ -42,11 +42,12 @@ class ReceivedEmailAttachment(TypedDict):
4242
"""
4343

4444

45-
class ReceivedEmailAttachmentDetails(TypedDict):
45+
class EmailAttachmentDetails(TypedDict):
4646
"""
47-
ReceivedEmailAttachmentDetails type that wraps a received email attachment with download details.
47+
EmailAttachmentDetails type that wraps an email attachment with download details.
4848
4949
Attributes:
50+
object (str): The object type.
5051
id (str): The attachment ID.
5152
filename (str): The filename of the attachment.
5253
content_type (str): The content type of the attachment.
@@ -56,6 +57,10 @@ class ReceivedEmailAttachmentDetails(TypedDict):
5657
expires_at (str): When the download URL expires.
5758
"""
5859

60+
object: str
61+
"""
62+
The object type.
63+
"""
5964
id: str
6065
"""
6166
The attachment ID.
@@ -153,7 +158,7 @@ class _ReceivedEmailDefaultAttrs(_ReceivedEmailFromParam):
153158
"""
154159
Email headers.
155160
"""
156-
attachments: List[ReceivedEmailAttachment]
161+
attachments: List[EmailAttachment]
157162
"""
158163
List of attachments.
159164
"""
@@ -177,7 +182,7 @@ class ReceivedEmail(_ReceivedEmailDefaultAttrs):
177182
reply_to (Optional[List[str]]): Reply-to addresses.
178183
message_id (str): The message ID of the email.
179184
headers (NotRequired[Dict[str, str]]): Email headers.
180-
attachments (List[ReceivedEmailAttachment]): List of attachments.
185+
attachments (List[EmailAttachment]): List of attachments.
181186
"""
182187

183188

@@ -214,7 +219,7 @@ class _ListReceivedEmailDefaultAttrs(_ListReceivedEmailFromParam):
214219
"""
215220
The message ID of the email.
216221
"""
217-
attachments: List[ReceivedEmailAttachment]
222+
attachments: List[EmailAttachment]
218223
"""
219224
List of attachments.
220225
"""
@@ -235,5 +240,5 @@ class ListReceivedEmail(_ListReceivedEmailDefaultAttrs):
235240
cc (Optional[List[str]]): Cc recipients.
236241
reply_to (Optional[List[str]]): Reply-to addresses.
237242
message_id (str): The message ID of the email.
238-
attachments (List[ReceivedEmailAttachment]): List of attachments.
243+
attachments (List[EmailAttachment]): List of attachments.
239244
"""

0 commit comments

Comments
 (0)