Skip to content

Commit 5988eb1

Browse files
committed
feat: impl update broadcast
1 parent 934a08f commit 5988eb1

File tree

3 files changed

+112
-1
lines changed

3 files changed

+112
-1
lines changed

examples/broadcasts.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,28 @@
1616
"subject": "Hello, world!",
1717
"html": "<p>Hello, world!</p>",
1818
"text": "Hello, world!",
19-
"reply_to": ["lel@lel.com", "lil@lil.com"],
19+
"reply_to": ["foo@resend.dev", "bar@resend.dev"],
2020
"name": "Hello, world!",
2121
}
2222

2323
broadcast: resend.Broadcasts.CreateResponse = resend.Broadcasts.create(create_params)
2424
print("Created broadcast !")
2525
print(broadcast)
2626

27+
update_params: resend.Broadcasts.UpdateParams = {
28+
"broadcast_id": broadcast["id"],
29+
"audience_id": audience_id,
30+
"html": "<p>Hello, world! Updated</p>",
31+
"text": "Hello, world! Updated",
32+
"name": "Hello, world! Updated",
33+
}
34+
35+
updated_broadcast: resend.Broadcasts.UpdateResponse = resend.Broadcasts.update(
36+
update_params
37+
)
38+
print("Updated broadcast!")
39+
print(updated_broadcast)
40+
2741
send_params: resend.Broadcasts.SendParams = {
2842
"broadcast_id": broadcast["id"],
2943
}

resend/broadcasts/_broadcasts.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
},
1717
)
1818

19+
_UpdateParamsFrom = TypedDict(
20+
"_UpdateParamsFrom",
21+
{
22+
"from": NotRequired[str],
23+
},
24+
)
25+
1926

2027
class _CreateResponse(TypedDict):
2128
id: str
@@ -24,6 +31,13 @@ class _CreateResponse(TypedDict):
2431
"""
2532

2633

34+
class _UpdateResponse(TypedDict):
35+
id: str
36+
"""
37+
id of the updated broadcast
38+
"""
39+
40+
2741
class _SendResponse(_CreateResponse):
2842
pass
2943

@@ -81,6 +95,37 @@ class _CreateParamsDefault(_CreateParamsFrom):
8195
"""
8296

8397

98+
class _UpdateParamsDefault(_UpdateParamsFrom):
99+
broadcast_id: str
100+
"""
101+
The ID of the broadcast you want to update.
102+
"""
103+
audience_id: 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+
84129
class _SendBroadcastParams(TypedDict):
85130
broadcast_id: str
86131
"""
@@ -108,6 +153,20 @@ class CreateParams(_CreateParamsDefault):
108153
name (NotRequired[str]): The friendly name of the broadcast. Only used for internal reference.
109154
"""
110155

156+
class UpdateParams(_UpdateParamsDefault):
157+
"""UpdateParams is the class that wraps the parameters for the update method.
158+
159+
Attributes:
160+
broadcast_id (str): The ID of the broadcast you want to update.
161+
audience_id (str): The ID of the audience you want to send to.
162+
from (str): The sender email address
163+
subject (NotRequired[str]): Email subject.
164+
reply_to (NotRequired[Union[List[str], str]]): Reply-to email address(es).
165+
html (NotRequired[str]): The HTML version of the message.
166+
text (NotRequired[str]): The text version of the message.
167+
name (NotRequired[str]): The friendly name of the broadcast. Only used for internal reference.
168+
"""
169+
111170
class SendParams(_SendBroadcastParams):
112171
"""SendParams is the class that wraps the parameters for the send method.
113172
@@ -125,6 +184,14 @@ class CreateResponse(_CreateResponse):
125184
id (str): id of the created broadcast
126185
"""
127186

187+
class UpdateResponse(_UpdateResponse):
188+
"""
189+
UpdateResponse is the class that wraps the response of the update method.
190+
191+
Attributes:
192+
id (str): id of the updated broadcast
193+
"""
194+
128195
class SendResponse(_SendResponse):
129196
"""
130197
SendResponse is the class that wraps the response of the send method.
@@ -170,6 +237,24 @@ def create(cls, params: CreateParams) -> CreateResponse:
170237
).perform_with_content()
171238
return resp
172239

240+
@classmethod
241+
def update(cls, params: UpdateParams) -> UpdateResponse:
242+
"""
243+
Update a broadcast.
244+
see more: https://resend.com/docs/api-reference/broadcasts/update-broadcast
245+
246+
Args:
247+
params (UpdateParams): The broadcast update parameters
248+
249+
Returns:
250+
UpdateResponse: The updated broadcast object response
251+
"""
252+
path = f"/broadcasts/{params['broadcast_id']}"
253+
resp = request.Request[_UpdateResponse](
254+
path=path, params=cast(Dict[Any, Any], params), verb="patch"
255+
).perform_with_content()
256+
return resp
257+
173258
@classmethod
174259
def send(cls, params: SendParams) -> SendResponse:
175260
"""

tests/broadcasts_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ def test_broadcasts_create(self) -> None:
1818
broadcast: resend.Broadcasts.CreateResponse = resend.Broadcasts.create(params)
1919
assert broadcast["id"] == "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"
2020

21+
def test_broadcasts_update(self) -> None:
22+
self.set_mock_json({"id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"})
23+
24+
params: resend.Broadcasts.UpdateParams = {
25+
"broadcast_id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794",
26+
"audience_id": "78b8d3bc-a55a-45a3-aee6-6ec0a5e13d7e",
27+
"subject": "Hello, world! Updated!",
28+
"name": "Python SDK Broadcast",
29+
}
30+
broadcast: resend.Broadcasts.UpdateResponse = resend.Broadcasts.update(params)
31+
assert broadcast["id"] == "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"
32+
2133
def test_broadcasts_get(self) -> None:
2234
self.set_mock_json(
2335
{

0 commit comments

Comments
 (0)