|
1 | | -import http |
2 | 1 | from contextlib import asynccontextmanager |
3 | | -from typing import Any, Mapping, Optional |
4 | | - |
| 2 | +from typing import Any, AsyncIterator, Mapping |
| 3 | +import http |
5 | 4 | import aiohttp |
| 5 | +from pydantic import BaseModel |
6 | 6 |
|
7 | 7 | from clerk.errors import ClerkAPIException |
8 | 8 |
|
@@ -59,31 +59,37 @@ def organizations(self): |
59 | 59 |
|
60 | 60 | @asynccontextmanager |
61 | 61 | async def get( |
62 | | - self, endpoint: str, params: Optional[Mapping[str, str]] = None |
63 | | - ) -> aiohttp.ClientResponse: |
| 62 | + self, endpoint: str, params: Mapping[str, str] | None = None |
| 63 | + ) -> AsyncIterator[aiohttp.ClientResponse]: |
64 | 64 | async with self._session.get(self._make_url(endpoint), params=params) as r: |
65 | 65 | await self._check_response_err(r) |
66 | 66 | yield r |
67 | 67 |
|
68 | 68 | @asynccontextmanager |
69 | 69 | async def post( |
70 | | - self, endpoint: str, data: Any = None, json: Any = None |
71 | | - ) -> aiohttp.ClientResponse: |
72 | | - async with self._session.post(self._make_url(endpoint), data=data, json=json) as r: |
| 70 | + self, endpoint: str, request: BaseModel | None = None, json: Any = None |
| 71 | + ) -> AsyncIterator[aiohttp.ClientResponse]: |
| 72 | + async with self._session.post( |
| 73 | + self._make_url(endpoint), |
| 74 | + data=request and request.model_dump_json(), |
| 75 | + json=json, |
| 76 | + ) as r: |
73 | 77 | await self._check_response_err(r) |
74 | 78 | yield r |
75 | 79 |
|
76 | 80 | @asynccontextmanager |
77 | | - async def delete(self, endpoint: str) -> aiohttp.ClientResponse: |
| 81 | + async def delete(self, endpoint: str) -> AsyncIterator[aiohttp.ClientResponse]: |
78 | 82 | async with self._session.delete(self._make_url(endpoint)) as r: |
79 | 83 | await self._check_response_err(r) |
80 | 84 | yield r |
81 | 85 |
|
82 | 86 | @asynccontextmanager |
83 | 87 | async def patch( |
84 | | - self, endpoint: str, data: Any = None, json: Any = None |
85 | | - ) -> aiohttp.ClientResponse: |
86 | | - async with self._session.patch(self._make_url(endpoint), data=data, json=json) as r: |
| 88 | + self, endpoint: str, request: BaseModel | None = None, json: Any = None |
| 89 | + ) -> AsyncIterator[aiohttp.ClientResponse]: |
| 90 | + async with self._session.patch( |
| 91 | + self._make_url(endpoint), data=request and request.model_dump_json(), json=json |
| 92 | + ) as r: |
87 | 93 | await self._check_response_err(r) |
88 | 94 | yield r |
89 | 95 |
|
|
0 commit comments