diff --git a/resend/broadcasts/_broadcasts.py b/resend/broadcasts/_broadcasts.py index ca4352b..415c774 100644 --- a/resend/broadcasts/_broadcasts.py +++ b/resend/broadcasts/_broadcasts.py @@ -238,6 +238,24 @@ class ListResponse(BaseResponse): Whether there are more results available for pagination """ + class CancelResponse(BaseResponse): + """ + CancelResponse is the class that wraps the response of the cancel method. + + Attributes: + object (str): object type: "broadcast" + id (str): id of the canceled broadcast + """ + + object: str + """ + object type: "broadcast" + """ + id: str + """ + id of the canceled broadcast + """ + class RemoveResponse(BaseResponse): """ RemoveResponse is the class that wraps the response of the remove method. @@ -360,6 +378,24 @@ def get(cls, id: str) -> Broadcast: ).perform_with_content() return resp + @classmethod + def cancel(cls, id: str) -> CancelResponse: + """ + Cancel a queued or scheduled broadcast. + see more: https://resend.com/docs/api-reference/broadcasts/cancel-broadcast + + Args: + id (str): The broadcast ID + + Returns: + CancelResponse: The cancel response object + """ + path = f"/broadcasts/{id}/cancel" + resp = request.Request[Broadcasts.CancelResponse]( + path=path, params={}, verb="post" + ).perform_with_content() + return resp + @classmethod def remove(cls, id: str) -> RemoveResponse: """ @@ -470,6 +506,24 @@ async def get_async(cls, id: str) -> Broadcast: ).perform_with_content() return resp + @classmethod + async def cancel_async(cls, id: str) -> CancelResponse: + """ + Cancel a queued or scheduled broadcast (async). + see more: https://resend.com/docs/api-reference/broadcasts/cancel-broadcast + + Args: + id (str): The broadcast ID + + Returns: + CancelResponse: The cancel response object + """ + path = f"/broadcasts/{id}/cancel" + resp = await AsyncRequest[Broadcasts.CancelResponse]( + path=path, params={}, verb="post" + ).perform_with_content() + return resp + @classmethod async def remove_async(cls, id: str) -> RemoveResponse: """ diff --git a/tests/broadcasts_async_test.py b/tests/broadcasts_async_test.py index 1f4a759..efa4eb6 100644 --- a/tests/broadcasts_async_test.py +++ b/tests/broadcasts_async_test.py @@ -125,6 +125,20 @@ async def test_should_send_broadcasts_async_raise_exception_when_no_content( with pytest.raises(NoContentError): _ = await resend.Broadcasts.send_async(params) + async def test_broadcasts_cancel_async(self) -> None: + self.set_mock_json( + { + "object": "broadcast", + "id": "78261eea-8f8b-4381-83c6-79fa7120f1cf", + } + ) + + canceled = await resend.Broadcasts.cancel_async( + "78261eea-8f8b-4381-83c6-79fa7120f1cf" + ) + assert canceled["id"] == "78261eea-8f8b-4381-83c6-79fa7120f1cf" + assert canceled["object"] == "broadcast" + async def test_broadcasts_remove_async(self) -> None: self.set_mock_json( { diff --git a/tests/broadcasts_test.py b/tests/broadcasts_test.py index 4b1332c..6ed49ce 100644 --- a/tests/broadcasts_test.py +++ b/tests/broadcasts_test.py @@ -101,6 +101,18 @@ def test_broadcasts_create_and_schedule(self) -> None: broadcast: resend.Broadcasts.CreateResponse = resend.Broadcasts.create(params) assert broadcast["id"] == "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794" + def test_broadcasts_cancel(self) -> None: + self.set_mock_json( + { + "object": "broadcast", + "id": "78261eea-8f8b-4381-83c6-79fa7120f1cf", + } + ) + + canceled = resend.Broadcasts.cancel("78261eea-8f8b-4381-83c6-79fa7120f1cf") + assert canceled["id"] == "78261eea-8f8b-4381-83c6-79fa7120f1cf" + assert canceled["object"] == "broadcast" + def test_broadcasts_remove(self) -> None: self.set_mock_json( {