Skip to content

Commit ce11336

Browse files
docs: creating docstrings for all methods and function to improve the developer/user experience (#74)
1 parent 8353425 commit ce11336

File tree

13 files changed

+211
-4
lines changed

13 files changed

+211
-4
lines changed

resend/api_keys/_api_key.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ def __init__(self, id: str, token: str, name: str, created_at: str):
2424

2525
@staticmethod
2626
def new_from_request(val) -> "ApiKey":
27+
"""Creates a new ApiKey object from the
28+
JSON response from the API.
29+
30+
Args:
31+
val (Dict): The JSON response from the API
32+
33+
Returns:
34+
ApiKey: The new ApiKey object
35+
"""
2736
return ApiKey(
2837
id=val["id"],
2938
token=val["token"] if "token" in val else None,

resend/api_keys/_api_keys.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ def create(cls, params: CreateParams) -> ApiKey:
2929
"""
3030
Add a new API key to authenticate communications with Resend.
3131
see more: https://resend.com/docs/api-reference/api-keys/create-api-key
32+
33+
Args:
34+
params (CreateParams): The API key creation parameters
35+
36+
Returns:
37+
ApiKey: The new API key object
3238
"""
3339
path = "/api-keys"
3440
return ApiKey.new_from_request(
@@ -42,6 +48,9 @@ def list(cls) -> List[ApiKey]:
4248
"""
4349
Retrieve a list of API keys for the authenticated user.
4450
see more: https://resend.com/docs/api-reference/api-keys/list-api-keys
51+
52+
Returns:
53+
List[ApiKey]: A list of API key objects
4554
"""
4655
path = "/api-keys"
4756
resp = request.Request(path=path, params={}, verb="get").perform()
@@ -52,6 +61,12 @@ def remove(cls, api_key_id: str = "") -> None:
5261
"""
5362
Remove an existing API key.
5463
see more: https://resend.com/docs/api-reference/api-keys/delete-api-key
64+
65+
Args:
66+
api_key_id (str): The ID of the API key to remove
67+
68+
Returns:
69+
None
5570
"""
5671
path = f"/api-keys/{api_key_id}"
5772

resend/audiences/_audience.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ def __init__(self, id, name, created_at, deleted=False):
2424

2525
@staticmethod
2626
def new_from_request(val) -> "Audience":
27+
"""Creates a new Audience object from the
28+
JSON response from the API.
29+
30+
Args:
31+
val (Dict): The JSON response from the API
32+
33+
Returns:
34+
Audience: The new Audience object
35+
"""
2736
audience = Audience(
2837
id=val["id"] if "id" in val else None,
2938
name=val["name"] if "name" in val else None,

resend/audiences/_audiences.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ def create(cls, params: CreateParams) -> Audience:
1919
"""
2020
Create a list of contacts.
2121
see more: https://resend.com/docs/api-reference/audiences/create-audience
22+
23+
Args:
24+
params (CreateParams): The audience creation parameters
25+
26+
Returns:
27+
Audience: The new audience object
2228
"""
2329
path = "/audiences"
2430
return Audience.new_from_request(
@@ -32,6 +38,9 @@ def list(cls) -> List[Audience]:
3238
"""
3339
Retrieve a list of audiences.
3440
see more: https://resend.com/docs/api-reference/audiences/list-audiences
41+
42+
Returns:
43+
List[Audience]: A list of audience objects
3544
"""
3645
path = "/audiences/"
3746
resp = request.Request(path=path, params={}, verb="get").perform()
@@ -46,6 +55,12 @@ def get(cls, id: str) -> Audience:
4655
"""
4756
Retrieve a single audience.
4857
see more: https://resend.com/docs/api-reference/audiences/get-audience
58+
59+
Args:
60+
id (str): The audience ID
61+
62+
Returns:
63+
Audience: The audience object
4964
"""
5065
path = f"/audiences/{id}"
5166
return Audience.new_from_request(
@@ -57,6 +72,12 @@ def remove(cls, id: str) -> Audience:
5772
"""
5873
Delete a single audience.
5974
see more: https://resend.com/docs/api-reference/audiences/delete-audience
75+
76+
Args:
77+
id (str): The audience ID
78+
79+
Returns:
80+
Audience: The audience object
6081
"""
6182
path = f"/audiences/{id}"
6283
return Audience.new_from_request(

resend/contacts/_contact.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ def __init__(
4848

4949
@staticmethod
5050
def new_from_request(val) -> "Contact":
51+
"""Creates a new Contact object from the
52+
JSON response from the API.
53+
54+
Args:
55+
val (Dict): The JSON response from the API
56+
57+
Returns:
58+
Contact: The new Contact object
59+
"""
5160
contact = Contact(
5261
id=val["id"] if "id" in val else "",
5362
email=val["email"] if "email" in val else "",

resend/contacts/_contacts.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ def create(cls, params: CreateParams) -> Contact:
6161
"""
6262
Create a new contact.
6363
see more: https://resend.com/docs/api-reference/contacts/create-contact
64+
65+
Args:
66+
params (CreateParams): The contact creation parameters
67+
68+
Returns:
69+
Contact: The new contact object
6470
"""
6571
path = f"/audiences/{params['audience_id']}/contacts"
6672
return Contact.new_from_request(
@@ -74,6 +80,12 @@ def update(cls, params: UpdateParams) -> Contact:
7480
"""
7581
Update an existing contact.
7682
see more: https://resend.com/docs/api-reference/contacts/update-contact
83+
84+
Args:
85+
params (UpdateParams): The contact update parameters
86+
87+
Returns:
88+
Contact: The updated contact object
7789
"""
7890
path = f"/audiences/{params['audience_id']}/contacts/{params['id']}"
7991
return Contact.new_from_request(
@@ -87,6 +99,9 @@ def list(cls, audience_id: str) -> List[Contact]:
8799
"""
88100
List all contacts for the provided audience.
89101
see more: https://resend.com/docs/api-reference/contacts/list-contacts
102+
103+
Returns:
104+
List[Contact]: A list of contact objects
90105
"""
91106
path = f"/audiences/{audience_id}/contacts"
92107
resp = request.Request(path=path, params={}, verb="get").perform()
@@ -101,6 +116,13 @@ def get(cls, id, audience_id: str) -> Contact:
101116
"""
102117
Get a contact.
103118
see more: https://resend.com/docs/api-reference/contacts/get-contact
119+
120+
Args:
121+
id (str): The contact ID
122+
audience_id (str): The audience ID
123+
124+
Returns:
125+
Contact: The contact object
104126
"""
105127
path = f"/audiences/{audience_id}/contacts/{id}"
106128
return Contact.new_from_request(
@@ -112,6 +134,14 @@ def remove(cls, audience_id: str, id: str = "", email: str = "") -> Contact:
112134
"""
113135
Remove a contact by ID or by Email
114136
see more: https://resend.com/docs/api-reference/contacts/delete-contact
137+
138+
Args:
139+
audience_id (str): The audience ID
140+
id (str): The contact ID
141+
email (str): The contact email
142+
143+
Returns:
144+
Contact: The removed contact object
115145
"""
116146
contact = email if id == "" else id
117147
if contact == "":

resend/domains/_domain.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,26 @@ def __init__(self, id, name, region, created_at, status, records, deleted=False)
4444

4545
@staticmethod
4646
def new_from_request(val) -> "Domain":
47+
"""Creates a new Domain object from the
48+
JSON response from the API.
49+
50+
Args:
51+
val (Dict): The JSON response from the API
52+
53+
Returns:
54+
Domain: The new Domain object
55+
"""
4756
domain = Domain(
4857
id=val["id"] if "id" in val else None,
4958
name=val["name"] if "name" in val else None,
5059
region=val["region"] if "region" in val else None,
5160
created_at=val["created_at"] if "created_at" in val else None,
5261
status=val["status"] if "status" in val else None,
53-
records=[Record.new_from_request(record) for record in val["records"]]
54-
if "records" in val
55-
else None,
62+
records=(
63+
[Record.new_from_request(record) for record in val["records"]]
64+
if "records" in val
65+
else None
66+
),
5667
deleted=val["deleted"] if "deleted" in val else None,
5768
)
5869
return domain

resend/domains/_domains.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ def create(cls, params: CreateParams) -> Domain:
3737
"""
3838
Create a domain through the Resend Email API.
3939
see more: https://resend.com/docs/api-reference/domains/create-domain
40+
41+
Args:
42+
params (CreateParams): The domain creation parameters
43+
44+
Returns:
45+
Domain: The new domain object
4046
"""
4147
path = "/domains"
4248
return Domain.new_from_request(
@@ -50,6 +56,12 @@ def update(cls, params: UpdateParams) -> Domain:
5056
"""
5157
Update an existing domain.
5258
see more: https://resend.com/docs/api-reference/domains/update-domain
59+
60+
Args:
61+
params (UpdateParams): The domain update parameters
62+
63+
Returns:
64+
Domain: The updated domain object
5365
"""
5466
path = f"/domains/{params['id']}"
5567
return Domain.new_from_request(
@@ -63,6 +75,12 @@ def get(cls, domain_id: str = "") -> Domain:
6375
"""
6476
Retrieve a single domain for the authenticated user.
6577
see more: https://resend.com/docs/api-reference/domains/get-domain
78+
79+
Args:
80+
domain_id (str): The domain ID
81+
82+
Returns:
83+
Domain: The domain object
6684
"""
6785
path = f"/domains/{domain_id}"
6886
return Domain.new_from_request(
@@ -74,6 +92,9 @@ def list(cls) -> List[Domain]:
7492
"""
7593
Retrieve a list of domains for the authenticated user.
7694
see more: https://resend.com/docs/api-reference/domains/list-domains
95+
96+
Returns:
97+
List[Domain]: A list of domain objects
7798
"""
7899
path = "/domains"
79100
resp = request.Request(path=path, params={}, verb="get").perform()
@@ -84,6 +105,12 @@ def remove(cls, domain_id: str = "") -> Domain:
84105
"""
85106
Remove an existing domain.
86107
see more: https://resend.com/docs/api-reference/domains/remove-domain
108+
109+
Args:
110+
domain_id (str): The domain ID
111+
112+
Returns:
113+
Domain: The removed domain object
87114
"""
88115
path = f"/domains/{domain_id}"
89116
return Domain.new_from_request(
@@ -95,6 +122,12 @@ def verify(cls, domain_id: str = "") -> Domain:
95122
"""
96123
Verify an existing domain.
97124
see more: https://resend.com/docs/api-reference/domains/verify-domain
125+
126+
Args:
127+
domain_id (str): The domain ID
128+
129+
Returns:
130+
Domain: The verified domain object
98131
"""
99132
path = f"/domains/{domain_id}/verify"
100133
return Domain.new_from_request(

resend/emails/_batch.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ def send(cls, params: List[Emails.SendParams]) -> List[Email]:
1212
"""
1313
Trigger up to 100 batch emails at once.
1414
see more: https://resend.com/docs/api-reference/emails/send-batch-emails
15+
16+
Args:
17+
params (List[Emails.SendParams]): The list of emails to send
18+
19+
Returns:
20+
List[Email]: A list of email objects
1521
"""
1622
path = "/emails/batch"
1723
resp = request.Request(

resend/emails/_email.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ def __init__(
7676

7777
@staticmethod
7878
def new_from_request(val) -> "Email":
79+
"""Creates a new Email object from the
80+
JSON response from the API.
81+
82+
Args:
83+
val (Dict): The JSON response from the API
84+
85+
Returns:
86+
Email: The new Email object
87+
"""
7988
email = Email(
8089
id=val["id"] if "id" in val else "",
8190
to=val["to"] if "to" in val else "",

resend/emails/_emails.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ def send(cls, params: SendParams) -> Email:
6161
"""
6262
Send an email through the Resend Email API.
6363
see more: https://resend.com/docs/api-reference/emails/send-email
64+
65+
Args:
66+
params (SendParams): The email parameters
67+
68+
Returns:
69+
Email: The email object that was sent
6470
"""
6571
path = "/emails"
6672

@@ -78,6 +84,12 @@ def get(cls, email_id: str = "") -> Email:
7884
"""
7985
Retrieve a single email.
8086
see more: https://resend.com/docs/api-reference/emails/retrieve-email
87+
88+
Args:
89+
email_id (str): The ID of the email to retrieve
90+
91+
Returns:
92+
Email: The email object that was retrieved
8193
"""
8294
path = f"/emails/{email_id}"
8395
return Email.new_from_request(

resend/exceptions.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
codes as outlined in https://resend.com/docs/errors.
55
"""
66

7-
87
from typing import Dict
98

109

@@ -172,6 +171,28 @@ def __init__(
172171

173172

174173
def raise_for_code_and_type(code: str, error_type: str, message: str) -> ResendError:
174+
"""Raise the appropriate error based on the code and type.
175+
176+
Args:
177+
code (str): The error code
178+
error_type (str): The error type
179+
message (str): The error message
180+
181+
Raises:
182+
ResendError: If it is a Resend err
183+
or
184+
ValidationError: If the error type is validation_error
185+
or
186+
MissingRequiredFieldsError: If the error type is missing_required_fields
187+
or
188+
MissingApiKeyError: If the error type is missing_api_key
189+
or
190+
InvalidApiKeyError: If the error type is invalid_api_key
191+
or
192+
ApplicationError: If the error type is application_error
193+
or
194+
TypeError: If the error type is not found
195+
"""
175196
error = ERRORS.get(str(code))
176197

177198
# Handle the case where the error might be unknown

0 commit comments

Comments
 (0)