Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Impl Domains#update #67

Merged
merged 3 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
retrieved = resend.Domains.get(domain_id=domain["id"])
print(retrieved)

update_params = {
"id": domain["id"],
"open_tracking": True,
"click_tracking": True,
}

updated = resend.Domains.update(update_params)
print(updated)

domains = resend.Domains.list()
print(domains)

Expand Down
6 changes: 6 additions & 0 deletions resend/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ def create(cls, params={}) -> Dict:
path = "/domains"
return request.Request(path=path, params=params, verb="post").perform()

@classmethod
# https://resend.com/docs/api-reference/domains/update-domain
def update(cls, params={}) -> Dict:
path = f"/domains/{params['id']}"
return request.Request(path=path, params=params, verb="patch").perform()

@classmethod
# https://resend.com/docs/api-reference/domains/get-domain
def get(cls, domain_id="") -> Dict:
Expand Down
29 changes: 29 additions & 0 deletions tests/domains_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,32 @@ def test_domains_verify(self):
)
assert email is None
patcher.stop()

def test_domains_update(self):
resend.api_key = "re_123"

patcher = patch("resend.Request.make_request")
mock = patcher.start()
mock.status_code = 200
m = MagicMock()
m.status_code = 200

def mock_json():
return {
"object": "domain",
"id": "479e3145-dd38-476b-932c-529ceb705947",
}

m.json = mock_json
mock.return_value = m

params = {
"id": "479e3145-dd38-476b-932c-529ceb705947",
"open_tracking": True,
"click_tracking": True,
}
contact = resend.Domains.update(params)
assert contact["id"] == "479e3145-dd38-476b-932c-529ceb705947"
assert contact["object"] == "domain"

patcher.stop()
Loading