Skip to content

Commit

Permalink
fix: Better handling for contact#delete (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
drish authored Jan 15, 2024
1 parent 9c59e60 commit 66fa2d2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
6 changes: 5 additions & 1 deletion examples/contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]")

# remove by id
# rmed = resend.Contacts.remove(audience_id=audience_id, id=contact["id"])
print(rmed)
2 changes: 1 addition & 1 deletion resend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
"Domains",
"Batch",
"Audiences",
"Contacts"
"Contacts",
]
7 changes: 5 additions & 2 deletions resend/contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion resend/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.7.0"
__version__ = "0.7.1"


def get_version():
Expand Down
10 changes: 10 additions & 0 deletions tests/contacts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 66fa2d2

Please sign in to comment.