Skip to content

Commit 0dad9d6

Browse files
fix: return api key delete response (#231)
1 parent 6a9fd83 commit 0dad9d6

3 files changed

Lines changed: 61 additions & 22 deletions

File tree

resend/api_keys/_api_keys.py

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,29 @@ class CreateApiKeyResponse(BaseResponse):
5757
The token of the created API key
5858
"""
5959

60+
class DeleteApiKeyResponse(BaseResponse):
61+
"""
62+
DeleteApiKeyResponse is the type that wraps the deleted API key response.
63+
64+
Attributes:
65+
object (str): The object type, always "api_key"
66+
id (str): The ID of the deleted API key
67+
deleted (bool): Whether the API key was deleted
68+
"""
69+
70+
object: str
71+
"""
72+
The object type, always "api_key"
73+
"""
74+
id: str
75+
"""
76+
The ID of the deleted API key
77+
"""
78+
deleted: bool
79+
"""
80+
Whether the API key was deleted
81+
"""
82+
6083
class ListParams(TypedDict):
6184
limit: NotRequired[int]
6285
"""
@@ -134,7 +157,7 @@ def list(cls, params: Optional[ListParams] = None) -> ListResponse:
134157
return resp
135158

136159
@classmethod
137-
def remove(cls, api_key_id: str) -> None:
160+
def remove(cls, api_key_id: str) -> DeleteApiKeyResponse:
138161
"""
139162
Remove an existing API key.
140163
see more: https://resend.com/docs/api-reference/api-keys/delete-api-key
@@ -143,13 +166,13 @@ def remove(cls, api_key_id: str) -> None:
143166
api_key_id (str): The ID of the API key to remove
144167
145168
Returns:
146-
None
169+
DeleteApiKeyResponse: The deleted API key response
147170
"""
148171
path = f"/api-keys/{api_key_id}"
149-
150-
# This would raise if failed
151-
request.Request[None](path=path, params={}, verb="delete").perform()
152-
return None
172+
resp = request.Request[ApiKeys.DeleteApiKeyResponse](
173+
path=path, params={}, verb="delete"
174+
).perform_with_content()
175+
return resp
153176

154177
@classmethod
155178
async def create_async(cls, params: CreateParams) -> CreateApiKeyResponse:
@@ -190,7 +213,7 @@ async def list_async(cls, params: Optional[ListParams] = None) -> ListResponse:
190213
return resp
191214

192215
@classmethod
193-
async def remove_async(cls, api_key_id: str) -> None:
216+
async def remove_async(cls, api_key_id: str) -> DeleteApiKeyResponse:
194217
"""
195218
Remove an existing API key (async).
196219
see more: https://resend.com/docs/api-reference/api-keys/delete-api-key
@@ -199,10 +222,10 @@ async def remove_async(cls, api_key_id: str) -> None:
199222
api_key_id (str): The ID of the API key to remove
200223
201224
Returns:
202-
None
225+
DeleteApiKeyResponse: The deleted API key response
203226
"""
204227
path = f"/api-keys/{api_key_id}"
205-
206-
# This would raise if failed
207-
await AsyncRequest[None](path=path, params={}, verb="delete").perform()
208-
return None
228+
resp = await AsyncRequest[ApiKeys.DeleteApiKeyResponse](
229+
path=path, params={}, verb="delete"
230+
).perform_with_content()
231+
return resp

tests/api_keys_async_test.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,19 @@ async def test_should_list_api_key_async_raise_exception_when_no_content(
6161
_ = await resend.ApiKeys.list_async()
6262

6363
async def test_api_keys_remove_async(self) -> None:
64-
self.set_mock_text("")
64+
self.set_mock_json(
65+
{
66+
"object": "api_key",
67+
"id": "4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
68+
"deleted": True,
69+
}
70+
)
6571

66-
# Remove operation returns None, verify no exceptions raised
67-
await resend.ApiKeys.remove_async(
68-
api_key_id="4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
72+
deleted_key: resend.ApiKeys.DeleteApiKeyResponse = (
73+
await resend.ApiKeys.remove_async(
74+
api_key_id="4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
75+
)
6976
)
77+
assert deleted_key["object"] == "api_key"
78+
assert deleted_key["id"] == "4ef9a417-02e9-4d39-ad75-9611e0fcc33c"
79+
assert deleted_key["deleted"] is True

tests/api_keys_test.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,17 @@ def test_api_keys_list_with_before_param(self) -> None:
128128
assert keys["data"][0]["id"] == "test-key-3"
129129

130130
def test_api_keys_remove(self) -> None:
131-
self.set_mock_text("")
131+
self.set_mock_json(
132+
{
133+
"object": "api_key",
134+
"id": "4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
135+
"deleted": True,
136+
}
137+
)
132138

133-
assert (
134-
resend.ApiKeys.remove(
135-
api_key_id="4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
136-
)
137-
is None
139+
deleted_key: resend.ApiKeys.DeleteApiKeyResponse = resend.ApiKeys.remove(
140+
api_key_id="4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
138141
)
142+
assert deleted_key["object"] == "api_key"
143+
assert deleted_key["id"] == "4ef9a417-02e9-4d39-ad75-9611e0fcc33c"
144+
assert deleted_key["deleted"] is True

0 commit comments

Comments
 (0)