diff --git a/examples/contacts.py b/examples/contacts.py index 0133608..a24036d 100644 --- a/examples/contacts.py +++ b/examples/contacts.py @@ -37,5 +37,9 @@ contacts = resend.Contacts.list(audience_id=audience_id) print(contacts) -rmed = resend.Contacts.remove(audience_id=audience_id, id=contact["id"]) +# remove by email +rmed = resend.Contacts.remove(audience_id=audience_id, email="sw@example.com") + +# remove by id +# rmed = resend.Contacts.remove(audience_id=audience_id, id=contact["id"]) print(rmed) diff --git a/resend/__init__.py b/resend/__init__.py index b845d5d..a089ac0 100644 --- a/resend/__init__.py +++ b/resend/__init__.py @@ -26,5 +26,5 @@ "Domains", "Batch", "Audiences", - "Contacts" + "Contacts", ] diff --git a/resend/contacts.py b/resend/contacts.py index 0e21dbc..3d74911 100644 --- a/resend/contacts.py +++ b/resend/contacts.py @@ -32,6 +32,9 @@ def get(cls, audience_id, id) -> Dict: @classmethod # https://resend.com/docs/api-reference/audiences/delete-audience - def remove(cls, audience_id, id) -> Dict: - path = f"/audiences/{id}/contacts/{id}" + def remove(cls, audience_id, id="", email="") -> Dict: + contact = email if id == "" else id + if contact == "": + raise ValueError("id or email must be provided") + path = f"/audiences/{audience_id}/contacts/{contact}" return request.Request(path=path, params={}, verb="delete").perform() diff --git a/resend/version.py b/resend/version.py index b4d055e..ba0894a 100644 --- a/resend/version.py +++ b/resend/version.py @@ -1,4 +1,4 @@ -__version__ = "0.7.0" +__version__ = "0.7.1" def get_version(): diff --git a/tests/contacts_test.py b/tests/contacts_test.py index 0a4b3b4..18bd001 100644 --- a/tests/contacts_test.py +++ b/tests/contacts_test.py @@ -131,6 +131,16 @@ def mock_json(): patcher.stop() + def test_contacts_remove(self): + resend.api_key = "re_123" + + with self.assertRaises(ValueError) as context: + resend.Contacts.remove( + audience_id="48c269ed-9873-4d60-bdd9-cd7e6fc0b9b8", + ) + + self.assertEqual("id or email must be provided", str(context.exception)) + def test_contacts_list(self): resend.api_key = "re_123"