Skip to content

Commit d915c74

Browse files
committed
refactor(Broadcasts): cleanup types definitions
1 parent 9c9527a commit d915c74

2 files changed

Lines changed: 113 additions & 130 deletions

File tree

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 = {

resend/broadcasts/_broadcasts.py

Lines changed: 112 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -24,123 +24,9 @@
2424
)
2525

2626

27-
class _CreateResponse(TypedDict):
28-
id: str
29-
"""
30-
id of the created broadcast
31-
"""
32-
33-
34-
class _UpdateResponse(TypedDict):
35-
id: str
36-
"""
37-
id of the updated broadcast
38-
"""
39-
40-
41-
class _SendResponse(_CreateResponse):
42-
pass
43-
44-
45-
class _RemoveResponse(TypedDict):
46-
object: str
47-
"""
48-
object type: "broadcast"
49-
"""
50-
id: str
51-
"""
52-
id of the removed broadcast
53-
"""
54-
deleted: bool
55-
"""
56-
True if the broadcast was deleted
57-
"""
58-
59-
60-
class _ListResponse(TypedDict):
61-
object: str
62-
"""
63-
object type: "list"
64-
"""
65-
data: List[Broadcast]
66-
"""
67-
A list of broadcast objects
68-
"""
69-
70-
71-
class _CreateParamsDefault(_CreateParamsFrom):
72-
audience_id: str
73-
"""
74-
The ID of the audience you want to send to.
75-
"""
76-
subject: str
77-
"""
78-
Email subject.
79-
"""
80-
reply_to: NotRequired[Union[List[str], str]]
81-
"""
82-
Reply-to email address. For multiple addresses, send as an array of strings.
83-
"""
84-
html: NotRequired[str]
85-
"""
86-
The HTML version of the message.
87-
"""
88-
text: NotRequired[str]
89-
"""
90-
The text version of the message.
91-
"""
92-
name: NotRequired[str]
93-
"""
94-
The friendly name of the broadcast. Only used for internal reference.
95-
"""
96-
97-
98-
class _UpdateParamsDefault(_UpdateParamsFrom):
99-
broadcast_id: str
100-
"""
101-
The ID of the broadcast you want to update.
102-
"""
103-
audience_id: NotRequired[str]
104-
"""
105-
The ID of the audience you want to send to.
106-
"""
107-
subject: NotRequired[str]
108-
"""
109-
Email subject.
110-
"""
111-
reply_to: NotRequired[Union[List[str], str]]
112-
"""
113-
Reply-to email address. For multiple addresses, send as an array of strings.
114-
"""
115-
html: NotRequired[str]
116-
"""
117-
The HTML version of the message.
118-
"""
119-
text: NotRequired[str]
120-
"""
121-
The text version of the message.
122-
"""
123-
name: NotRequired[str]
124-
"""
125-
The friendly name of the broadcast. Only used for internal reference.
126-
"""
127-
128-
129-
class _SendBroadcastParams(TypedDict):
130-
broadcast_id: str
131-
"""
132-
The ID of the broadcast to send.
133-
"""
134-
scheduled_at: NotRequired[str]
135-
"""
136-
Schedule email to be sent later.
137-
The date should be in natural language (e.g.: in 1 min) or ISO 8601 format (e.g: 2024-08-05T11:52:01.858Z).
138-
"""
139-
140-
14127
class Broadcasts:
14228

143-
class CreateParams(_CreateParamsDefault):
29+
class CreateParams(_CreateParamsFrom):
14430
"""CreateParams is the class that wraps the parameters for the create method.
14531
14632
Attributes:
@@ -153,7 +39,32 @@ class CreateParams(_CreateParamsDefault):
15339
name (NotRequired[str]): The friendly name of the broadcast. Only used for internal reference.
15440
"""
15541

156-
class UpdateParams(_UpdateParamsDefault):
42+
audience_id: str
43+
"""
44+
The ID of the audience you want to send to.
45+
"""
46+
subject: str
47+
"""
48+
Email subject.
49+
"""
50+
reply_to: NotRequired[Union[List[str], str]]
51+
"""
52+
Reply-to email address. For multiple addresses, send as an array of strings.
53+
"""
54+
html: NotRequired[str]
55+
"""
56+
The HTML version of the message.
57+
"""
58+
text: NotRequired[str]
59+
"""
60+
The text version of the message.
61+
"""
62+
name: NotRequired[str]
63+
"""
64+
The friendly name of the broadcast. Only used for internal reference.
65+
"""
66+
67+
class UpdateParams(_UpdateParamsFrom):
15768
"""UpdateParams is the class that wraps the parameters for the update method.
15869
15970
Attributes:
@@ -167,7 +78,36 @@ class UpdateParams(_UpdateParamsDefault):
16778
name (NotRequired[str]): The friendly name of the broadcast. Only used for internal reference.
16879
"""
16980

170-
class SendParams(_SendBroadcastParams):
81+
broadcast_id: str
82+
"""
83+
The ID of the broadcast you want to update.
84+
"""
85+
audience_id: NotRequired[str]
86+
"""
87+
The ID of the audience you want to send to.
88+
"""
89+
subject: NotRequired[str]
90+
"""
91+
Email subject.
92+
"""
93+
reply_to: NotRequired[Union[List[str], str]]
94+
"""
95+
Reply-to email address. For multiple addresses, send as an array of strings.
96+
"""
97+
html: NotRequired[str]
98+
"""
99+
The HTML version of the message.
100+
"""
101+
text: NotRequired[str]
102+
"""
103+
The text version of the message.
104+
"""
105+
name: NotRequired[str]
106+
"""
107+
The friendly name of the broadcast. Only used for internal reference.
108+
"""
109+
110+
class SendParams(TypedDict):
171111
"""SendParams is the class that wraps the parameters for the send method.
172112
173113
Attributes:
@@ -176,31 +116,51 @@ class SendParams(_SendBroadcastParams):
176116
The date should be in natural language (e.g.: in 1 min) or ISO 8601 format (e.g: 2024-08-05T11:52:01.858Z).
177117
"""
178118

179-
class CreateResponse(_CreateResponse):
119+
broadcast_id: str
120+
"""
121+
The ID of the broadcast to send.
122+
"""
123+
scheduled_at: NotRequired[str]
124+
"""
125+
Schedule email to be sent later.
126+
The date should be in natural language (e.g.: in 1 min) or ISO 8601 format (e.g: 2024-08-05T11:52:01.858Z).
127+
"""
128+
129+
class CreateResponse(TypedDict):
180130
"""
181131
CreateResponse is the class that wraps the response of the create method.
182132
183133
Attributes:
184134
id (str): id of the created broadcast
185135
"""
186136

187-
class UpdateResponse(_UpdateResponse):
137+
id: str
138+
"""
139+
id of the created broadcast
140+
"""
141+
142+
class UpdateResponse(TypedDict):
188143
"""
189144
UpdateResponse is the class that wraps the response of the update method.
190145
191146
Attributes:
192147
id (str): id of the updated broadcast
193148
"""
194149

195-
class SendResponse(_SendResponse):
150+
id: str
151+
"""
152+
id of the updated broadcast
153+
"""
154+
155+
class SendResponse(CreateResponse):
196156
"""
197157
SendResponse is the class that wraps the response of the send method.
198158
199159
Attributes:
200160
id (str): id of the created broadcast
201161
"""
202162

203-
class ListResponse(_ListResponse):
163+
class ListResponse(TypedDict):
204164
"""
205165
ListResponse is the class that wraps the response of the list method.
206166
@@ -209,7 +169,16 @@ class ListResponse(_ListResponse):
209169
data (List[Broadcast]): A list of broadcast objects
210170
"""
211171

212-
class RemoveResponse(_RemoveResponse):
172+
object: str
173+
"""
174+
object type: "list"
175+
"""
176+
data: List[Broadcast]
177+
"""
178+
A list of broadcast objects
179+
"""
180+
181+
class RemoveResponse(TypedDict):
213182
"""
214183
RemoveResponse is the class that wraps the response of the remove method.
215184
@@ -219,6 +188,19 @@ class RemoveResponse(_RemoveResponse):
219188
deleted (bool): True if the broadcast was deleted
220189
"""
221190

191+
object: str
192+
"""
193+
object type: "broadcast"
194+
"""
195+
id: str
196+
"""
197+
id of the removed broadcast
198+
"""
199+
deleted: bool
200+
"""
201+
True if the broadcast was deleted
202+
"""
203+
222204
@classmethod
223205
def create(cls, params: CreateParams) -> CreateResponse:
224206
"""
@@ -231,8 +213,9 @@ def create(cls, params: CreateParams) -> CreateResponse:
231213
Returns:
232214
CreateResponse: The new broadcast object response
233215
"""
216+
234217
path = "/broadcasts"
235-
resp = request.Request[_CreateResponse](
218+
resp = request.Request[Broadcasts.CreateResponse](
236219
path=path, params=cast(Dict[Any, Any], params), verb="post"
237220
).perform_with_content()
238221
return resp
@@ -249,8 +232,9 @@ def update(cls, params: UpdateParams) -> UpdateResponse:
249232
Returns:
250233
UpdateResponse: The updated broadcast object response
251234
"""
235+
252236
path = f"/broadcasts/{params['broadcast_id']}"
253-
resp = request.Request[_UpdateResponse](
237+
resp = request.Request[Broadcasts.UpdateResponse](
254238
path=path, params=cast(Dict[Any, Any], params), verb="patch"
255239
).perform_with_content()
256240
return resp
@@ -267,8 +251,9 @@ def send(cls, params: SendParams) -> SendResponse:
267251
Returns:
268252
SendResponse: The new broadcast object response
269253
"""
254+
270255
path = f"/broadcasts/{params['broadcast_id']}/send"
271-
resp = request.Request[_SendResponse](
256+
resp = request.Request[Broadcasts.SendResponse](
272257
path=path, params=cast(Dict[Any, Any], params), verb="post"
273258
).perform_with_content()
274259
return resp
@@ -283,7 +268,7 @@ def list(cls) -> ListResponse:
283268
ListResponse: A list of broadcast objects
284269
"""
285270
path = "/broadcasts/"
286-
resp = request.Request[_ListResponse](
271+
resp = request.Request[Broadcasts.ListResponse](
287272
path=path, params={}, verb="get"
288273
).perform_with_content()
289274
return resp
@@ -319,7 +304,7 @@ def remove(cls, id: str) -> RemoveResponse:
319304
RemoveResponse: The remove response object
320305
"""
321306
path = f"/broadcasts/{id}"
322-
resp = request.Request[_RemoveResponse](
307+
resp = request.Request[Broadcasts.RemoveResponse](
323308
path=path, params={}, verb="delete"
324309
).perform_with_content()
325310
return resp

0 commit comments

Comments
 (0)