Skip to content

Commit

Permalink
feat: broadcasts remove
Browse files Browse the repository at this point in the history
  • Loading branch information
drish committed Dec 15, 2024
1 parent 50135d5 commit 41ea893
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
18 changes: 13 additions & 5 deletions examples/broadcasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,21 @@
print("Created broadcast !")
print(broadcast)

retrieved: resend.Broadcast = resend.Broadcasts.get(id=broadcast["id"])
print("retrieved broadcast !")
print(retrieved)

send_params: resend.Broadcasts.SendParams = {
"broadcast_id": broadcast["id"],
}
sent: resend.SendBroadcastResponse = resend.Broadcasts.send(send_params)
print("Sent broadcast !")
print("Sent broadcast !\n")
print(sent)

retrieved: resend.Broadcast = resend.Broadcasts.get(id=broadcast["id"])
print("retrieved broadcast !\n")
print(retrieved)

if retrieved["status"] == "draft":
removed: resend.RemoveBroadcastResponse = resend.Broadcasts.remove(id=broadcast["id"])
print("Removed broadcast !\n")
print(removed)
print("\n")
else:
print("Broadcast is not in draft status, cannot remove it.\n")
4 changes: 2 additions & 2 deletions resend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .emails._emails import Emails
from .emails._tag import Tag
from .request import Request
from .version import get_version, __version__
from .version import __version__, get_version

# Config vars
api_key = os.environ.get("RESEND_API_KEY")
Expand All @@ -28,7 +28,7 @@
from .emails._emails import Emails # noqa

__all__ = [
"__version__"
"__version__",
"get_version",
"Request",
"Emails",
Expand Down
2 changes: 1 addition & 1 deletion resend/broadcasts/_broadcasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class CreateParams(_CreateParamsDefault):
from (str): The sender email address
audience_id (str): The ID of the audience you want to send to.
subject (str): Email subject.
reply_to (NotRequired[Union[List[str], str]]): Reply-to email address. For multiple addresses, send as an array of strings.
reply_to (NotRequired[Union[List[str], str]]): Reply-to email address(es).
html (NotRequired[str]): The HTML version of the message.
text (NotRequired[str]): The text version of the message.
name (NotRequired[str]): The friendly name of the broadcast. Only used for internal reference.
Expand Down
1 change: 1 addition & 0 deletions resend/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from typing import Any, Dict, Union


class ResendError(Exception):
"""Base class for all errors raised by Resend SDK.
This is the parent class of all exceptions (server side)
Expand Down
13 changes: 13 additions & 0 deletions tests/broadcasts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,16 @@ def test_broadcasts_send(self) -> None:
}
broadcast = resend.Broadcasts.send(params)
assert broadcast["id"] == "49a3999c-0ce1-4ea6-ab68-afcd6dc2e791"

def test_broadcasts_remove(self) -> None:
self.set_mock_json(
{
"object": "broadcasts",
"id": "78261eea-8f8b-4381-83c6-79fa7120f1cf",
"deleted": True,
}
)

rmed = resend.Broadcasts.remove("78261eea-8f8b-4381-83c6-79fa7120f1cf")
assert rmed["id"] == "78261eea-8f8b-4381-83c6-79fa7120f1cf"
assert rmed["deleted"] is True

0 comments on commit 41ea893

Please sign in to comment.