Skip to content
Open
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
14 changes: 9 additions & 5 deletions examples/async/domains_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ async def main() -> None:
"tls": "enforced",
}

updated_domain: resend.Domain = await resend.Domains.update_async(update_params)
updated_domain: resend.Domains.UpdateDomainResponse = (
await resend.Domains.update_async(update_params)
)
print(f"Updated domain: {updated_domain['id']}")

domains: resend.Domains.ListResponse = await resend.Domains.list_async()
Expand All @@ -41,13 +43,15 @@ async def main() -> None:
for d in domains["data"]:
print(d)

verified_domain: resend.Domain = await resend.Domains.verify_async(
domain_id=domain["id"]
verified_domain: resend.Domains.VerifyDomainResponse = (
await resend.Domains.verify_async(domain_id=domain["id"])
)
print("Verified")
print("Verification requested")
print(verified_domain)

rm_domain: resend.Domain = await resend.Domains.remove_async(domain_id=domain["id"])
rm_domain: resend.Domains.RemoveDomainResponse = await resend.Domains.remove_async(
domain_id=domain["id"]
)
print(rm_domain)


Expand Down
14 changes: 10 additions & 4 deletions examples/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"tls": "enforced",
}

updated_domain: resend.Domain = resend.Domains.update(update_params)
updated_domain: resend.Domains.UpdateDomainResponse = resend.Domains.update(
update_params
)
print(f"Updated domain: {updated_domain['id']}")

domains: resend.Domains.ListResponse = resend.Domains.list()
Expand All @@ -54,9 +56,13 @@
else:
print("No domains available for pagination example")

verified_domain: resend.Domain = resend.Domains.verify(domain_id=domain["id"])
print(f"Verified")
verified_domain: resend.Domains.VerifyDomainResponse = resend.Domains.verify(
domain_id=domain["id"]
)
print("Verification requested")
print(verified_domain)

rm_domain: resend.Domain = resend.Domains.remove(domain_id=domain["id"])
rm_domain: resend.Domains.RemoveDomainResponse = resend.Domains.remove(
domain_id=domain["id"]
)
print(rm_domain)
59 changes: 39 additions & 20 deletions resend/domains/_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,25 @@ class CreateDomainResponse(BaseResponse):
The custom subdomain used for click and open tracking links (e.g., "links")
"""

class UpdateDomainResponse(BaseResponse):
"""Response from updating a domain."""

object: str
id: str

class VerifyDomainResponse(BaseResponse):
"""Response from requesting verification of a domain."""

object: str
id: str

class RemoveDomainResponse(BaseResponse):
"""Response from removing a domain."""

object: str
id: str
deleted: bool

class UpdateParams(TypedDict):
id: str
"""
Expand Down Expand Up @@ -194,7 +213,7 @@ def create(cls, params: CreateParams) -> CreateDomainResponse:
return resp

@classmethod
def update(cls, params: UpdateParams) -> Domain:
def update(cls, params: UpdateParams) -> UpdateDomainResponse:
"""
Update an existing domain.
see more: https://resend.com/docs/api-reference/domains/update-domain
Expand All @@ -203,10 +222,10 @@ def update(cls, params: UpdateParams) -> Domain:
params (UpdateParams): The domain update parameters

Returns:
Domain: The updated domain object
UpdateDomainResponse: The domain update acknowledgment
"""
path = f"/domains/{params['id']}"
resp = request.Request[Domain](
resp = request.Request[Domains.UpdateDomainResponse](
path=path, params=cast(Dict[Any, Any], params), verb="patch"
).perform_with_content()
return resp
Expand Down Expand Up @@ -254,7 +273,7 @@ def list(cls, params: Optional[ListParams] = None) -> ListResponse:
return resp

@classmethod
def remove(cls, domain_id: str) -> Domain:
def remove(cls, domain_id: str) -> RemoveDomainResponse:
"""
Remove an existing domain.
see more: https://resend.com/docs/api-reference/domains/delete-domain
Expand All @@ -263,28 +282,28 @@ def remove(cls, domain_id: str) -> Domain:
domain_id (str): The domain ID

Returns:
Domain: The removed domain object
RemoveDomainResponse: The domain ID and deletion result
"""
path = f"/domains/{domain_id}"
resp = request.Request[Domain](
resp = request.Request[Domains.RemoveDomainResponse](
path=path, params={}, verb="delete"
).perform_with_content()
return resp

@classmethod
def verify(cls, domain_id: str) -> Domain:
def verify(cls, domain_id: str) -> VerifyDomainResponse:
"""
Verify an existing domain.
Request verification of an existing domain.
see more: https://resend.com/docs/api-reference/domains/verify-domain

Args:
domain_id (str): The domain ID

Returns:
Domain: The verified domain object
VerifyDomainResponse: The domain verification acknowledgment
"""
path = f"/domains/{domain_id}/verify"
resp = request.Request[Domain](
resp = request.Request[Domains.VerifyDomainResponse](
path=path, params={}, verb="post"
).perform_with_content()
return resp
Expand All @@ -308,7 +327,7 @@ async def create_async(cls, params: CreateParams) -> CreateDomainResponse:
return resp

@classmethod
async def update_async(cls, params: UpdateParams) -> Domain:
async def update_async(cls, params: UpdateParams) -> UpdateDomainResponse:
"""
Update an existing domain (async).
see more: https://resend.com/docs/api-reference/domains/update-domain
Expand All @@ -317,10 +336,10 @@ async def update_async(cls, params: UpdateParams) -> Domain:
params (UpdateParams): The domain update parameters

Returns:
Domain: The updated domain object
UpdateDomainResponse: The domain update acknowledgment
"""
path = f"/domains/{params['id']}"
resp = await AsyncRequest[Domain](
resp = await AsyncRequest[Domains.UpdateDomainResponse](
path=path, params=cast(Dict[Any, Any], params), verb="patch"
).perform_with_content()
return resp
Expand Down Expand Up @@ -364,7 +383,7 @@ async def list_async(cls, params: Optional[ListParams] = None) -> ListResponse:
return resp

@classmethod
async def remove_async(cls, domain_id: str) -> Domain:
async def remove_async(cls, domain_id: str) -> RemoveDomainResponse:
"""
Remove an existing domain (async).
see more: https://resend.com/docs/api-reference/domains/delete-domain
Expand All @@ -373,28 +392,28 @@ async def remove_async(cls, domain_id: str) -> Domain:
domain_id (str): The domain ID

Returns:
Domain: The removed domain object
RemoveDomainResponse: The domain ID and deletion result
"""
path = f"/domains/{domain_id}"
resp = await AsyncRequest[Domain](
resp = await AsyncRequest[Domains.RemoveDomainResponse](
path=path, params={}, verb="delete"
).perform_with_content()
return resp

@classmethod
async def verify_async(cls, domain_id: str) -> Domain:
async def verify_async(cls, domain_id: str) -> VerifyDomainResponse:
"""
Verify an existing domain (async).
Request verification of an existing domain (async).
see more: https://resend.com/docs/api-reference/domains/verify-domain

Args:
domain_id (str): The domain ID

Returns:
Domain: The verified domain object
VerifyDomainResponse: The domain verification acknowledgment
"""
path = f"/domains/{domain_id}/verify"
resp = await AsyncRequest[Domain](
resp = await AsyncRequest[Domains.VerifyDomainResponse](
path=path, params={}, verb="post"
).perform_with_content()
return resp
33 changes: 9 additions & 24 deletions tests/domains_async_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from typing_extensions import assert_type

import resend
from resend.exceptions import NoContentError
Expand Down Expand Up @@ -265,10 +266,6 @@ async def test_domains_update_async(self) -> None:
{
"object": "domain",
"id": "d91cd9bd-1176-453e-8fc1-35364d380206",
"name": "example.com",
"status": "not_started",
"created_at": "2023-04-26 20:21:26.347412+00",
"region": "us-east-1",
}
)

Expand All @@ -279,11 +276,9 @@ async def test_domains_update_async(self) -> None:
"tls": "enforced",
}
domain = await resend.Domains.update_async(params=update_params)
assert_type(domain, resend.Domains.UpdateDomainResponse)
assert domain["object"] == "domain"
assert domain["id"] == "d91cd9bd-1176-453e-8fc1-35364d380206"
assert domain["name"] == "example.com"
assert domain["status"] == "not_started"
assert domain["created_at"] == "2023-04-26 20:21:26.347412+00"
assert domain["region"] == "us-east-1"

async def test_domains_update_async_with_tracking_subdomain(self) -> None:
self.set_mock_json(
Expand Down Expand Up @@ -315,22 +310,18 @@ async def test_domains_remove_async(self) -> None:
self.set_mock_json(
{
"object": "domain",
"deleted": True,
"id": "d91cd9bd-1176-453e-8fc1-35364d380206",
"name": "example.com",
"status": "not_started",
"created_at": "2023-04-26 20:21:26.347412+00",
"region": "us-east-1",
}
)

domain = await resend.Domains.remove_async(
domain_id="d91cd9bd-1176-453e-8fc1-35364d380206",
)
assert_type(domain, resend.Domains.RemoveDomainResponse)
assert domain["object"] == "domain"
assert domain["id"] == "d91cd9bd-1176-453e-8fc1-35364d380206"
assert domain["name"] == "example.com"
assert domain["status"] == "not_started"
assert domain["created_at"] == "2023-04-26 20:21:26.347412+00"
assert domain["region"] == "us-east-1"
assert domain["deleted"] is True

async def test_should_remove_domains_async_raise_exception_when_no_content(
self,
Expand All @@ -346,21 +337,15 @@ async def test_domains_verify_async(self) -> None:
{
"object": "domain",
"id": "d91cd9bd-1176-453e-8fc1-35364d380206",
"name": "example.com",
"status": "verified",
"created_at": "2023-04-26 20:21:26.347412+00",
"region": "us-east-1",
}
)

domain = await resend.Domains.verify_async(
domain_id="d91cd9bd-1176-453e-8fc1-35364d380206",
)
assert_type(domain, resend.Domains.VerifyDomainResponse)
assert domain["object"] == "domain"
assert domain["id"] == "d91cd9bd-1176-453e-8fc1-35364d380206"
assert domain["name"] == "example.com"
assert domain["status"] == "verified"
assert domain["created_at"] == "2023-04-26 20:21:26.347412+00"
assert domain["region"] == "us-east-1"

async def test_should_verify_domains_async_raise_exception_when_no_content(
self,
Expand Down
8 changes: 8 additions & 0 deletions tests/domains_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing_extensions import assert_type

import resend
from resend.exceptions import NoContentError
from tests.conftest import ResendBaseTest
Expand Down Expand Up @@ -154,6 +156,8 @@ def test_domains_remove(self) -> None:
domain_id="4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
)
assert domain["deleted"] is True
assert_type(domain, resend.Domains.RemoveDomainResponse)
assert domain["object"] == "domain"
assert domain["id"] == "4ef9a417-02e9-4d39-ad75-9611e0fcc33c"

def test_should_remove_domains_raise_exception_when_no_content(self) -> None:
Expand All @@ -171,6 +175,8 @@ def test_domains_verify(self) -> None:
domain = resend.Domains.verify(
domain_id="d91cd9bd-1176-453e-8fc1-35364d380206",
)
assert_type(domain, resend.Domains.VerifyDomainResponse)
assert domain["object"] == "domain"
assert domain["id"] == "d91cd9bd-1176-453e-8fc1-35364d380206"

def test_should_verify_domains_raise_exception_when_no_content(self) -> None:
Expand Down Expand Up @@ -311,6 +317,8 @@ def test_domains_update(self) -> None:
"tls": "opportunistic",
}
domain = resend.Domains.update(params)
assert_type(domain, resend.Domains.UpdateDomainResponse)
assert domain["object"] == "domain"
assert domain["id"] == "479e3145-dd38-476b-932c-529ceb705947"

def test_domains_update_with_tracking_subdomain(self) -> None:
Expand Down
Loading