diff --git a/examples/api_keys.py b/examples/api_keys.py index 90095b9..e38da58 100644 --- a/examples/api_keys.py +++ b/examples/api_keys.py @@ -10,15 +10,15 @@ "name": "example.com", } -key: resend.ApiKey = resend.ApiKeys.create(params=create_params) +key: resend.ApiKeys.CreateResponse = resend.ApiKeys.create(params=create_params) print("Created new api key") print(f"Key id: {key['id']} and token: {key['token']}") keys: resend.ApiKeys.ListResponse = resend.ApiKeys.list() -for key in keys["data"]: - print(key["id"]) - print(key["name"]) - print(key["created_at"]) +for k in keys["data"]: + print(k["id"]) + print(k["name"]) + print(k["created_at"]) if len(keys) > 0: resend.ApiKeys.remove(api_key_id=keys["data"][0]["id"]) diff --git a/examples/audiences.py b/examples/audiences.py index a1cb1c7..4099208 100644 --- a/examples/audiences.py +++ b/examples/audiences.py @@ -10,7 +10,7 @@ create_params: resend.Audiences.CreateParams = { "name": "New Audience from Python SDK", } -audience: resend.Audience = resend.Audiences.create(create_params) +audience: resend.Audiences.CreateResponse = resend.Audiences.create(create_params) print(f"Created audience: {audience['id']}") print(audience) @@ -20,6 +20,6 @@ audiences: resend.Audiences.ListResponse = resend.Audiences.list() print("List of audiences:", [a["id"] for a in audiences["data"]]) -rmed: resend.Audience = resend.Audiences.remove(id=audience["id"]) +rmed: resend.Audiences.RemoveResponse = resend.Audiences.remove(id=audience["id"]) print(f"Deleted audience") print(rmed) diff --git a/examples/contacts.py b/examples/contacts.py index 4239d0e..f2226a1 100644 --- a/examples/contacts.py +++ b/examples/contacts.py @@ -17,7 +17,7 @@ "unsubscribed": False, } -contact: resend.Contact = resend.Contacts.create(create_params) +contact: resend.Contacts.CreateResponse = resend.Contacts.create(create_params) print("Created contact !") print(contact) @@ -28,7 +28,7 @@ "first_name": "Steve1", } -updated: resend.Contact = resend.Contacts.update(update_params) +updated: resend.Contacts.CreateResponse = resend.Contacts.update(update_params) print("updated contact !") print(updated) @@ -38,11 +38,13 @@ contacts: resend.Contacts.ListResponse = resend.Contacts.list(audience_id=audience_id) print("List of contacts") -for contact in contacts["data"]: - print(contact) +for c in contacts["data"]: + print(c) # remove by email -rmed = resend.Contacts.remove(audience_id=audience_id, email=cont["email"]) +rmed: resend.Contacts.RemoveResponse = resend.Contacts.remove( + audience_id=audience_id, email=cont["email"] +) # remove by id # rmed: resend.Contact = resend.Contacts.remove(audience_id=audience_id, id=cont["id"]) diff --git a/examples/domains.py b/examples/domains.py index 9ed0d3a..3b075a8 100644 --- a/examples/domains.py +++ b/examples/domains.py @@ -11,7 +11,7 @@ "name": "example.com", "region": "us-east-1", } -domain: resend.Domain = resend.Domains.create(params=create_params) +domain: resend.Domains.CreateResponse = resend.Domains.create(params=create_params) print(domain) retrieved: resend.Domain = resend.Domains.get(domain_id=domain["id"]) @@ -27,18 +27,20 @@ "click_tracking": True, } -updated_domain: resend.Domain = resend.Domains.update(update_params) +updated_domain: resend.Domains.UpdateResponse = resend.Domains.update(update_params) print(f"Updated domain: {updated_domain['id']}") domains: resend.Domains.ListResponse = resend.Domains.list() if not domains: print("No domains found") -for domain in domains["data"]: - print(domain) +for d in domains["data"]: + print(d) -verified_domain: resend.Domain = resend.Domains.verify(domain_id=domain["id"]) +verified_domain: resend.Domains.VerifyResponse = resend.Domains.verify( + domain_id=domain["id"] +) print(f"Verified") print(verified_domain) -rm_domain: resend.Domain = resend.Domains.remove(domain_id=domain["id"]) +rm_domain: resend.Domains.RemoveResponse = resend.Domains.remove(domain_id=domain["id"]) print(rm_domain) diff --git a/examples/simple_email.py b/examples/simple_email.py index d744a0b..18aeeac 100644 --- a/examples/simple_email.py +++ b/examples/simple_email.py @@ -19,7 +19,7 @@ ], } -email: resend.Email = resend.Emails.send(params) +email: resend.Emails.SendResponse = resend.Emails.send(params) print(f"Sent email") print("Email ID: ", email["id"]) diff --git a/examples/with_attachments.py b/examples/with_attachments.py index 51e2c6d..5269801 100644 --- a/examples/with_attachments.py +++ b/examples/with_attachments.py @@ -23,6 +23,6 @@ "attachments": [attachment], } -email: resend.Email = resend.Emails.send(params) +email: resend.Emails.SendResponse = resend.Emails.send(params) print("Sent email with attachment") print(email) diff --git a/examples/with_b64_attachments.py b/examples/with_b64_attachments.py index e621903..e4f2460 100644 --- a/examples/with_b64_attachments.py +++ b/examples/with_b64_attachments.py @@ -28,6 +28,6 @@ } # Send email -email: resend.Email = resend.Emails.send(params) +email: resend.Emails.SendResponse = resend.Emails.send(params) print("Email sent with base64 string attachment") print(email) diff --git a/examples/with_exception.py b/examples/with_exception.py index 3b8bc1d..207966c 100644 --- a/examples/with_exception.py +++ b/examples/with_exception.py @@ -14,6 +14,6 @@ } try: - email: resend.Email = resend.Emails.send(params) + email: resend.Emails.SendResponse = resend.Emails.send(params) except resend.exceptions.ResendError as e: print(f"Error sending email: {e}") diff --git a/examples/with_html_file_as_b64_attachment.py b/examples/with_html_file_as_b64_attachment.py index ca53db2..d94820a 100644 --- a/examples/with_html_file_as_b64_attachment.py +++ b/examples/with_html_file_as_b64_attachment.py @@ -28,6 +28,6 @@ } # Send email -email: resend.Email = resend.Emails.send(params) +email: resend.Emails.SendResponse = resend.Emails.send(params) print("Sent email with base64 string attachment") print("Email ID: ", email["id"]) diff --git a/resend/api_keys/_api_key.py b/resend/api_keys/_api_key.py index cb5a5ba..70cc66b 100644 --- a/resend/api_keys/_api_key.py +++ b/resend/api_keys/_api_key.py @@ -6,10 +6,6 @@ class ApiKey(TypedDict): """ The api key ID """ - token: str - """ - The api key token - """ name: str """ The api key token diff --git a/resend/api_keys/_api_keys.py b/resend/api_keys/_api_keys.py index 60f0361..600ddc2 100644 --- a/resend/api_keys/_api_keys.py +++ b/resend/api_keys/_api_keys.py @@ -13,8 +13,28 @@ class _ListResponse(TypedDict): """ +class _CreateResponse(TypedDict): + id: str + """ + The api key ID + """ + token: str + """ + The api key token + """ + + class ApiKeys: + class CreateResponse(_CreateResponse): + """ + Class that wraps the response of the create API key endpoint + + Attributes: + id (str): The API key ID + token (str): The API key token + """ + class ListResponse(_ListResponse): """ ListResponse type that wraps a list of API key objects @@ -41,7 +61,7 @@ class CreateParams(TypedDict): """ @classmethod - def create(cls, params: CreateParams) -> ApiKey: + def create(cls, params: CreateParams) -> CreateResponse: """ Add a new API key to authenticate communications with Resend. see more: https://resend.com/docs/api-reference/api-keys/create-api-key @@ -53,7 +73,7 @@ def create(cls, params: CreateParams) -> ApiKey: ApiKey: The new API key object """ path = "/api-keys" - resp = request.Request[ApiKey]( + resp = request.Request[_CreateResponse]( path=path, params=cast(Dict[Any, Any], params), verb="post" ).perform_with_content() return resp diff --git a/resend/audiences/_audience.py b/resend/audiences/_audience.py index e6cbe40..3d416ca 100644 --- a/resend/audiences/_audience.py +++ b/resend/audiences/_audience.py @@ -1,7 +1,9 @@ -from typing_extensions import TypedDict +from typing_extensions import Literal, TypedDict +AudienceObject = Literal["audience"] -class Audience(TypedDict): + +class ShortAudience(TypedDict): id: str """ The unique identifier of the audience. @@ -14,7 +16,10 @@ class Audience(TypedDict): """ The date and time the audience was created. """ - deleted: bool + + +class Audience(ShortAudience): + object: AudienceObject """ - Wether the audience was deleted. Only returned on the "remove" call + The object type """ diff --git a/resend/audiences/_audiences.py b/resend/audiences/_audiences.py index cfff751..42b447f 100644 --- a/resend/audiences/_audiences.py +++ b/resend/audiences/_audiences.py @@ -1,27 +1,82 @@ from typing import Any, Dict, List, cast -from typing_extensions import TypedDict +from typing_extensions import Literal, TypedDict from resend import request -from ._audience import Audience +from ._audience import Audience, AudienceObject, ShortAudience class _ListResponse(TypedDict): - data: List[Audience] + object: Literal["list"] + """ + The object type + """ + data: List[ShortAudience] """ A list of audience objects """ +class _CreateResponse(TypedDict): + object: AudienceObject + """ + The object type + """ + id: str + """ + The unique identifier of the audience. + """ + name: str + """ + The name of the audience. + """ + + +class _RemoveResponse(TypedDict): + object: AudienceObject + """ + The object type + """ + id: str + """ + The unique identifier of the audience. + """ + deleted: bool + """ + Whether the audience was deleted. + """ + + class Audiences: + class CreateResponse(_CreateResponse): + """ + Class that wraps the response of the create audience endpoint + + Attributes: + object (str): The object type + id (str): The audience ID + name (str): The audience name + """ + class ListResponse(_ListResponse): """ ListResponse type that wraps a list of audience objects Attributes: - data (List[Audience]): A list of audience objects + object (str): The object type + data (List[ShortAudience]): A list of audience objects + """ + + class RemoveResponse(_RemoveResponse): + """ + Class that wraps the response of the remove audience endpoint + + Attributes: + object (str): The object type + id (str): The audience ID + deleted (bool): Whether the audience was deleted """ class CreateParams(TypedDict): @@ -31,7 +86,7 @@ class CreateParams(TypedDict): """ @classmethod - def create(cls, params: CreateParams) -> Audience: + def create(cls, params: CreateParams) -> CreateResponse: """ Create a list of contacts. see more: https://resend.com/docs/api-reference/audiences/create-audience @@ -43,7 +98,7 @@ def create(cls, params: CreateParams) -> Audience: Audience: The new audience object """ path = "/audiences" - resp = request.Request[Audience]( + resp = request.Request[_CreateResponse]( path=path, params=cast(Dict[Any, Any], params), verb="post" ).perform_with_content() return resp @@ -82,7 +137,7 @@ def get(cls, id: str) -> Audience: return resp @classmethod - def remove(cls, id: str) -> Audience: + def remove(cls, id: str) -> RemoveResponse: """ Delete a single audience. see more: https://resend.com/docs/api-reference/audiences/delete-audience @@ -94,7 +149,7 @@ def remove(cls, id: str) -> Audience: Audience: The audience object """ path = f"/audiences/{id}" - resp = request.Request[Audience]( + resp = request.Request[_RemoveResponse]( path=path, params={}, verb="delete" ).perform_with_content() return resp diff --git a/resend/contacts/_contact.py b/resend/contacts/_contact.py index 5c1ec4f..e47b7bd 100644 --- a/resend/contacts/_contact.py +++ b/resend/contacts/_contact.py @@ -1,7 +1,9 @@ -from typing_extensions import TypedDict +from typing_extensions import Literal, TypedDict +ContactObject = Literal["contact"] -class Contact(TypedDict): + +class ShortContact(TypedDict): id: str """ The contact id. @@ -26,7 +28,10 @@ class Contact(TypedDict): """ The unsubscribed status of the contact. """ - deleted: bool + + +class Contact(ShortContact): + object: ContactObject """ - Wether the contact is deleted or not. + The object type """ diff --git a/resend/contacts/_contacts.py b/resend/contacts/_contacts.py index 7f89216..73e14cf 100644 --- a/resend/contacts/_contacts.py +++ b/resend/contacts/_contacts.py @@ -1,27 +1,85 @@ from typing import Any, Dict, List, cast -from typing_extensions import NotRequired, TypedDict +from typing_extensions import Literal, NotRequired, TypedDict from resend import request -from ._contact import Contact +from ._contact import Contact, ContactObject, ShortContact class _ListResponse(TypedDict): - data: List[Contact] + object: Literal["list"] + """ + The object type + """ + data: List[ShortContact] """ A list of contact objects """ +class _CreateUpdateRemoveResponse(TypedDict): + object: ContactObject + """ + The object type + """ + id: str + """ + The contact id + """ + + +class _CreateResponse(_CreateUpdateRemoveResponse): + pass + + +class _UpdateResponse(_CreateUpdateRemoveResponse): + pass + + +class _RemoveResponse(_CreateUpdateRemoveResponse): + deleted: bool + """ + The deleted status of the contact + """ + + class Contacts: + class CreateResponse(_CreateResponse): + """ + Class that wraps the response of the create contact endpoint + + Attributes: + object (Literal["contact"]): The object type + id (str): The contact ID + """ + + class UpdateResponse(_UpdateResponse): + """ + Class that wraps the response of the update contact endpoint + + Attributes: + object (Literal["contact"]): The object type + id (str): The contact ID + """ + class ListResponse(_ListResponse): """ ListResponse type that wraps a list of contact objects Attributes: - data (List[Contact]): A list of contact objects + data (List[ShortContact]): A list of contact objects + """ + + class RemoveResponse(_RemoveResponse): + """ + Class that wraps the response of the remove contact endpoint + + Attributes: + object (Literal["contact"]): The object type + id (str): The contact ID + deleted (bool): The deleted status of the contact """ class CreateParams(TypedDict): @@ -73,7 +131,7 @@ class UpdateParams(TypedDict): """ @classmethod - def create(cls, params: CreateParams) -> Contact: + def create(cls, params: CreateParams) -> CreateResponse: """ Create a new contact. see more: https://resend.com/docs/api-reference/contacts/create-contact @@ -85,13 +143,13 @@ def create(cls, params: CreateParams) -> Contact: Contact: The new contact object """ path = f"/audiences/{params['audience_id']}/contacts" - resp = request.Request[Contact]( + resp = request.Request[_CreateResponse]( path=path, params=cast(Dict[Any, Any], params), verb="post" ).perform_with_content() return resp @classmethod - def update(cls, params: UpdateParams) -> Contact: + def update(cls, params: UpdateParams) -> UpdateResponse: """ Update an existing contact. see more: https://resend.com/docs/api-reference/contacts/update-contact @@ -103,7 +161,7 @@ def update(cls, params: UpdateParams) -> Contact: Contact: The updated contact object """ path = f"/audiences/{params['audience_id']}/contacts/{params['id']}" - resp = request.Request[Contact]( + resp = request.Request[_UpdateResponse]( path=path, params=cast(Dict[Any, Any], params), verb="patch" ).perform_with_content() return resp @@ -146,7 +204,7 @@ def get(cls, id: str, audience_id: str) -> Contact: return resp @classmethod - def remove(cls, audience_id: str, id: str = "", email: str = "") -> Contact: + def remove(cls, audience_id: str, id: str = "", email: str = "") -> RemoveResponse: """ Remove a contact by ID or by Email see more: https://resend.com/docs/api-reference/contacts/delete-contact @@ -164,7 +222,7 @@ def remove(cls, audience_id: str, id: str = "", email: str = "") -> Contact: raise ValueError("id or email must be provided") path = f"/audiences/{audience_id}/contacts/{contact}" - resp = request.Request[Contact]( + resp = request.Request[_RemoveResponse]( path=path, params={}, verb="delete" ).perform_with_content() return resp diff --git a/resend/domains/_domain.py b/resend/domains/_domain.py index 06de159..b7dbfd5 100644 --- a/resend/domains/_domain.py +++ b/resend/domains/_domain.py @@ -1,11 +1,13 @@ from typing import List, Union -from typing_extensions import TypedDict +from typing_extensions import Literal, TypedDict from resend.domains._record import Record +DomainObject = Literal["domain"] -class Domain(TypedDict): + +class ShortDomain(TypedDict): id: str """ The domain ID @@ -22,15 +24,19 @@ class Domain(TypedDict): """ Status of the domain: not_started, etc.. """ - region: str + region: Literal["us-east-1", "eu-west-1", "sa-east-1", "ap-northeast-1"] """ - The region where emails will be sent from. Possible values: us-east-1' | 'eu-west-1' | 'sa-east-1' | 'ap-northeast-1' + The region where emails will be sent from. + Possible values: us-east-1' | 'eu-west-1' | 'sa-east-1' | 'ap-northeast-1' """ - records: Union[List[Record], None] + + +class Domain(ShortDomain): + object: DomainObject """ - The list of domain records + The object type """ - deleted: bool + records: Union[List[Record], None] """ - Wether the domain is deleted or not + The list of domain records """ diff --git a/resend/domains/_domains.py b/resend/domains/_domains.py index 689899a..7314f68 100644 --- a/resend/domains/_domains.py +++ b/resend/domains/_domains.py @@ -1,26 +1,99 @@ -from typing import Any, Dict, List, cast +from typing import Any, Dict, List, Union, cast from typing_extensions import NotRequired, TypedDict from resend import request -from resend.domains._domain import Domain +from resend.domains._domain import Domain, DomainObject, ShortDomain +from resend.domains._record import Record class _ListResponse(TypedDict): - data: List[Domain] + data: List[ShortDomain] """ A list of domain objects """ +class _CreateResponse(ShortDomain): + records: Union[List[Record], None] + """ + The list of domain records + """ + + +class _VerifyResponse(TypedDict): + object: DomainObject + """ + The object type + """ + id: str + """ + The domain ID + """ + + +class _UpdateResponse(_VerifyResponse): + pass + + +class _RemoveResponse(_VerifyResponse): + deleted: bool + """ + The domain deletion status + """ + + class Domains: + class CreateResponse(_CreateResponse): + """ + CreateResponse type that wraps a domain object + + Attributes: + id (str): The domain ID + name (str): The domain name + created_at (str): When domain was created + status (str): Status of the domain: not_started, etc.. + region (str): The region where emails will be sent from. + Possible values: us-east-1' | 'eu-west-1' | 'sa-east-1' | 'ap-northeast-1' + records (List[Record]): The list of domain records + dnsProvider (str): The domain DNS provider + """ + class ListResponse(_ListResponse): """ ListResponse type that wraps a list of domain objects Attributes: - data (List[Domain]): A list of domain objects + data (List[ShortDomain]): A list of domain objects + """ + + class RemoveResponse(_RemoveResponse): + """ + RemoveResponse type that wraps a domain object + + Attributes: + object (str): The object type + id (str): The domain ID + deleted (bool): The domain deletion status + """ + + class VerifyResponse(_VerifyResponse): + """ + VerifyResponse type that wraps a domain object + + Attributes: + object (str): The object type + id (str): The domain ID + """ + + class UpdateResponse(_UpdateResponse): + """ + UpdateResponse type that wraps a domain object + + Attributes: + object (str): The object type + id (str): The domain ID """ class UpdateParams(TypedDict): @@ -49,7 +122,7 @@ class CreateParams(TypedDict): """ @classmethod - def create(cls, params: CreateParams) -> Domain: + def create(cls, params: CreateParams) -> CreateResponse: """ Create a domain through the Resend Email API. see more: https://resend.com/docs/api-reference/domains/create-domain @@ -61,13 +134,13 @@ def create(cls, params: CreateParams) -> Domain: Domain: The new domain object """ path = "/domains" - resp = request.Request[Domain]( + resp = request.Request[_CreateResponse]( path=path, params=cast(Dict[Any, Any], params), verb="post" ).perform_with_content() return resp @classmethod - def update(cls, params: UpdateParams) -> Domain: + def update(cls, params: UpdateParams) -> UpdateResponse: """ Update an existing domain. see more: https://resend.com/docs/api-reference/domains/update-domain @@ -79,7 +152,7 @@ def update(cls, params: UpdateParams) -> Domain: Domain: The updated domain object """ path = f"/domains/{params['id']}" - resp = request.Request[Domain]( + resp = request.Request[_UpdateResponse]( path=path, params=cast(Dict[Any, Any], params), verb="patch" ).perform_with_content() return resp @@ -118,7 +191,7 @@ def list(cls) -> ListResponse: return resp @classmethod - def remove(cls, domain_id: str) -> Domain: + def remove(cls, domain_id: str) -> RemoveResponse: """ Remove an existing domain. see more: https://resend.com/docs/api-reference/domains/delete-domain @@ -130,13 +203,13 @@ def remove(cls, domain_id: str) -> Domain: Domain: The removed domain object """ path = f"/domains/{domain_id}" - resp = request.Request[Domain]( + resp = request.Request[_RemoveResponse]( path=path, params={}, verb="delete" ).perform_with_content() return resp @classmethod - def verify(cls, domain_id: str) -> Domain: + def verify(cls, domain_id: str) -> VerifyResponse: """ Verify an existing domain. see more: https://resend.com/docs/api-reference/domains/verify-domain @@ -148,7 +221,7 @@ def verify(cls, domain_id: str) -> Domain: Domain: The verified domain object """ path = f"/domains/{domain_id}/verify" - resp = request.Request[Domain]( + resp = request.Request[_VerifyResponse]( path=path, params={}, verb="post" ).perform_with_content() return resp diff --git a/resend/emails/_batch.py b/resend/emails/_batch.py index 0c8c194..de33e15 100644 --- a/resend/emails/_batch.py +++ b/resend/emails/_batch.py @@ -4,12 +4,11 @@ from resend import request -from ._email import Email from ._emails import Emails class _SendResponse(TypedDict): - data: List[Email] + data: List[Emails.SendResponse] """ A list of email objects """ @@ -22,7 +21,7 @@ class SendResponse(_SendResponse): SendResponse type that wraps a list of email objects Attributes: - data (List[Email]): A list of email objects + data (List[Emails.SendResponse]): A list of SendResponse objects """ @classmethod diff --git a/resend/emails/_email.py b/resend/emails/_email.py index 09dd1af..a41197f 100644 --- a/resend/emails/_email.py +++ b/resend/emails/_email.py @@ -1,6 +1,6 @@ from typing import List, Union -from typing_extensions import TypedDict +from typing_extensions import Literal, TypedDict # Uses functional typed dict syntax here in order to support "from" reserved keyword _FromParam = TypedDict( @@ -12,6 +12,10 @@ class _EmailDefaultAttrs(_FromParam): + object: Literal["email"] + """ + The object type + """ id: str """ The Email ID. @@ -59,6 +63,7 @@ class Email(_EmailDefaultAttrs): Email type that wraps the email object Attributes: + object (Literal["email"]): The object type id (str): The Email ID. from (str): The email address the email was sent from. to (Union[List[str], str]): List of email addresses to send the email to. diff --git a/resend/emails/_emails.py b/resend/emails/_emails.py index 9e49fb1..d8e8e04 100644 --- a/resend/emails/_emails.py +++ b/resend/emails/_emails.py @@ -61,7 +61,22 @@ class _SendParamsDefault(_SendParamsFrom): """ +class _SendResponse(TypedDict): + id: str + """ + The email ID + """ + + class Emails: + class SendResponse(_SendResponse): + """ + SendResponse type that wraps a email object + + Attributes: + id (str): The email ID + """ + class SendParams(_SendParamsDefault): """SendParams is the class that wraps the parameters for the send method. @@ -80,7 +95,7 @@ class SendParams(_SendParamsDefault): """ @classmethod - def send(cls, params: SendParams) -> Email: + def send(cls, params: SendParams) -> SendResponse: """ Send an email through the Resend Email API. see more: https://resend.com/docs/api-reference/emails/send-email @@ -92,7 +107,7 @@ def send(cls, params: SendParams) -> Email: Email: The email object that was sent """ path = "/emails" - resp = request.Request[Email]( + resp = request.Request[_SendResponse]( path=path, params=cast(Dict[Any, Any], params), verb="post", diff --git a/tests/api_keys_test.py b/tests/api_keys_test.py index f730d54..9f35094 100644 --- a/tests/api_keys_test.py +++ b/tests/api_keys_test.py @@ -17,7 +17,7 @@ def test_api_keys_create(self) -> None: params: resend.ApiKeys.CreateParams = { "name": "prod", } - key: resend.ApiKey = resend.ApiKeys.create(params) + key: resend.ApiKeys.CreateResponse = resend.ApiKeys.create(params) assert key["id"] == "dacf4072-4119-4d88-932f-6202748ac7c8" def test_should_create_api_key_raise_exception_when_no_content(self) -> None: diff --git a/tests/audiences_test.py b/tests/audiences_test.py index b85ef8f..dc08edb 100644 --- a/tests/audiences_test.py +++ b/tests/audiences_test.py @@ -83,8 +83,10 @@ def test_audiences_list(self) -> None: ) audiences: resend.Audiences.ListResponse = resend.Audiences.list() + assert audiences["object"] == "list" assert audiences["data"][0]["id"] == "78261eea-8f8b-4381-83c6-79fa7120f1cf" assert audiences["data"][0]["name"] == "Registered Users" + assert audiences["data"][0]["created_at"] == "2023-10-06T22:59:55.977Z" def test_should_list_audiences_raise_exception_when_no_content(self) -> None: self.set_mock_json(None) diff --git a/tests/contacts_test.py b/tests/contacts_test.py index 2100023..111607a 100644 --- a/tests/contacts_test.py +++ b/tests/contacts_test.py @@ -18,7 +18,7 @@ def test_contacts_create(self) -> None: "last_name": "Wozniak", "unsubscribed": True, } - contact: resend.Contact = resend.Contacts.create(params) + contact: resend.Contacts.CreateResponse = resend.Contacts.create(params) assert contact["id"] == "479e3145-dd38-476b-932c-529ceb705947" def test_should_create_contacts_raise_exception_when_no_content(self) -> None: @@ -78,6 +78,7 @@ def test_contacts_get(self) -> None: id="e169aa45-1ecf-4183-9955-b1499d5701d3", audience_id="48c269ed-9873-4d60-bdd9-cd7e6fc0b9b8", ) + assert contact["object"] == "contact" assert contact["id"] == "e169aa45-1ecf-4183-9955-b1499d5701d3" assert contact["email"] == "steve.wozniak@gmail.com" assert contact["first_name"] == "Steve" @@ -102,10 +103,11 @@ def test_contacts_remove_by_id(self) -> None: } ) - rmed = resend.Contacts.remove( + rmed: resend.Contacts.RemoveResponse = resend.Contacts.remove( audience_id="48c269ed-9873-4d60-bdd9-cd7e6fc0b9b8", id="78261eea-8f8b-4381-83c6-79fa7120f1cf", ) + assert rmed["object"] == "contact" assert rmed["id"] == "520784e2-887d-4c25-b53c-4ad46ad38100" assert rmed["deleted"] is True @@ -126,10 +128,11 @@ def test_contacts_remove_by_email(self) -> None: } ) - rmed: resend.Contact = resend.Contacts.remove( + rmed: resend.Contacts.RemoveResponse = resend.Contacts.remove( audience_id="48c269ed-9873-4d60-bdd9-cd7e6fc0b9b8", email="someemail@email.com", ) + assert rmed["object"] == "contact" assert rmed["id"] == "520784e2-887d-4c25-b53c-4ad46ad38100" assert rmed["deleted"] is True @@ -173,6 +176,7 @@ def test_contacts_list(self) -> None: contacts: resend.Contacts.ListResponse = resend.Contacts.list( audience_id="48c269ed-9873-4d60-bdd9-cd7e6fc0b9b8" ) + assert contacts["object"] == "list" assert contacts["data"][0]["id"] == "e169aa45-1ecf-4183-9955-b1499d5701d3" assert contacts["data"][0]["email"] == "steve.wozniak@gmail.com" assert contacts["data"][0]["first_name"] == "Steve" diff --git a/tests/domains_test.py b/tests/domains_test.py index 814b887..2189544 100644 --- a/tests/domains_test.py +++ b/tests/domains_test.py @@ -69,6 +69,8 @@ def test_domains_create(self) -> None: assert domain["status"] == "not_started" assert domain["created_at"] == "2023-03-28T17:12:02.059593+00:00" assert domain["region"] == "us-east-1" + if domain["records"]: + assert domain["records"][0]["record"] == "SPF" def test_should_create_domains_raise_exception_when_no_content(self) -> None: self.set_mock_json(None) @@ -93,6 +95,7 @@ def test_domains_get(self) -> None: domain = resend.Domains.get( domain_id="d91cd9bd-1176-453e-8fc1-35364d380206", ) + assert domain["object"] == "domain" assert domain["id"] == "d91cd9bd-1176-453e-8fc1-35364d380206" assert domain["name"] == "example.com" assert domain["status"] == "not_started" @@ -163,6 +166,7 @@ def test_domains_verify(self) -> None: domain = resend.Domains.verify( domain_id="d91cd9bd-1176-453e-8fc1-35364d380206", ) + assert domain["object"] == "domain" assert domain["id"] == "d91cd9bd-1176-453e-8fc1-35364d380206" def test_should_verify_domains_raise_exception_when_no_content(self) -> None: diff --git a/tests/emails_test.py b/tests/emails_test.py index 6e64dd6..70c6a81 100644 --- a/tests/emails_test.py +++ b/tests/emails_test.py @@ -19,7 +19,7 @@ def test_email_send_with_from(self) -> None: "subject": "subject", "html": "html", } - email: resend.Email = resend.Emails.send(params) + email: resend.Emails.SendResponse = resend.Emails.send(params) assert email["id"] == "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794" def test_should_send_email_raise_exception_when_no_content(self) -> None: @@ -55,6 +55,7 @@ def test_email_get(self) -> None: email_id="4ef9a417-02e9-4d39-ad75-9611e0fcc33c", ) assert email["id"] == "4ef9a417-02e9-4d39-ad75-9611e0fcc33c" + assert email["object"] == "email" def test_should_get_email_raise_exception_when_no_content(self) -> None: self.set_mock_json(None)