Skip to content

Commit 83b192b

Browse files
committed
refactor(ApiKeys): change return type of send method
1 parent 23fb1a2 commit 83b192b

3 files changed

Lines changed: 30 additions & 14 deletions

File tree

examples/api_keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"name": "example.com",
1111
}
1212

13-
key: resend.ApiKey = resend.ApiKeys.create(params=create_params)
13+
key: resend.ApiKeys.CreateApiKeyResponse = resend.ApiKeys.create(params=create_params)
1414
print("Created new api key")
1515
print(f"Key id: {key['id']} and token: {key['token']}")
1616

resend/api_keys/_api_keys.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,39 @@
66
from resend.api_keys._api_key import ApiKey
77

88

9-
class _ListResponse(TypedDict):
10-
data: List[ApiKey]
11-
"""
12-
A list of API key objects
13-
"""
14-
15-
169
class ApiKeys:
1710

18-
class ListResponse(_ListResponse):
11+
class ListResponse(TypedDict):
1912
"""
2013
ListResponse type that wraps a list of API key objects
2114
2215
Attributes:
2316
data (List[Dict[str, Any]]): A list of API key objects
2417
"""
2518

19+
data: List[ApiKey]
20+
"""
21+
A list of API key objects
22+
"""
23+
24+
class CreateApiKeyResponse(TypedDict):
25+
"""
26+
CreateApiKeyResponse is the type that wraps the response of the API key that was created
27+
28+
Attributes:
29+
id (str): The ID of the created API key
30+
token (str): The token of the created API key
31+
"""
32+
33+
id: str
34+
"""
35+
The ID of the created API key
36+
"""
37+
token: str
38+
"""
39+
The token of the created API key
40+
"""
41+
2642
class CreateParams(TypedDict):
2743
name: str
2844
"""
@@ -41,7 +57,7 @@ class CreateParams(TypedDict):
4157
"""
4258

4359
@classmethod
44-
def create(cls, params: CreateParams) -> ApiKey:
60+
def create(cls, params: CreateParams) -> CreateApiKeyResponse:
4561
"""
4662
Add a new API key to authenticate communications with Resend.
4763
see more: https://resend.com/docs/api-reference/api-keys/create-api-key
@@ -50,10 +66,10 @@ def create(cls, params: CreateParams) -> ApiKey:
5066
params (CreateParams): The API key creation parameters
5167
5268
Returns:
53-
ApiKey: The new API key object
69+
CreateApiKeyResponse: The created API key response with id and token
5470
"""
5571
path = "/api-keys"
56-
resp = request.Request[ApiKey](
72+
resp = request.Request[ApiKeys.CreateApiKeyResponse](
5773
path=path, params=cast(Dict[Any, Any], params), verb="post"
5874
).perform_with_content()
5975
return resp
@@ -68,7 +84,7 @@ def list(cls) -> ListResponse:
6884
ListResponse: A list of API key objects
6985
"""
7086
path = "/api-keys"
71-
resp = request.Request[_ListResponse](
87+
resp = request.Request[ApiKeys.ListResponse](
7288
path=path, params={}, verb="get"
7389
).perform_with_content()
7490
return resp

tests/api_keys_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_api_keys_create(self) -> None:
1717
params: resend.ApiKeys.CreateParams = {
1818
"name": "prod",
1919
}
20-
key: resend.ApiKey = resend.ApiKeys.create(params)
20+
key: resend.ApiKeys.CreateApiKeyResponse = resend.ApiKeys.create(params)
2121
assert key["id"] == "dacf4072-4119-4d88-932f-6202748ac7c8"
2222

2323
def test_should_create_api_key_raise_exception_when_no_content(self) -> None:

0 commit comments

Comments
 (0)