Skip to content

Commit 70f9538

Browse files
stainless-botrattrayalex
authored andcommitted
Rename path params (eg, from "id" to "account_token").
1 parent 4287d34 commit 70f9538

13 files changed

Lines changed: 113 additions & 95 deletions

lithic/_base_client.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
ProxiesTypes,
4141
RequestFiles,
4242
RequestOptions,
43+
ModelBuilderProtocol,
4344
)
4445
from ._models import BaseModel, GenericModel, FinalRequestOptions
4546
from ._base_exceptions import (
@@ -55,7 +56,7 @@
5556

5657

5758
PageParamsT = TypeVar("PageParamsT", bound=Query)
58-
ResponseT = TypeVar("ResponseT", bound=Union[BaseModel, str, None])
59+
ResponseT = TypeVar("ResponseT", bound=Union[BaseModel, ModelBuilderProtocol, str, None])
5960

6061
_T = TypeVar("_T")
6162
_T_co = TypeVar("_T_co", covariant=True)
@@ -312,17 +313,22 @@ def process_response(
312313

313314
model_cls = cast(Type[BaseModel], cast_to)
314315

315-
content_type = response.headers.get("content-type")
316+
# split is required to handle cases where additional information is included
317+
# in the response, e.g. application/json; charset=utf-8
318+
content_type, *_ = response.headers.get("content-type").split(";")
316319
if content_type != "application/json":
317320
raise ValueError(
318321
f"Expected Content-Type response header to be `application/json` but received {content_type} instead."
319322
)
320323

321324
data = response.json()
325+
if issubclass(cast_to, ModelBuilderProtocol):
326+
return cast(ResponseT, cast_to.build(response=response, data=data))
327+
322328
if self._strict_response_validation:
323329
return cast(ResponseT, model_cls(**data))
324-
else:
325-
return cast(ResponseT, model_cls.construct(**data))
330+
331+
return cast(ResponseT, model_cls.construct(**data))
326332

327333
@property
328334
def qs(self) -> Querystring:

lithic/_types.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
Optional,
1313
Sequence,
1414
)
15-
from typing_extensions import Literal, TypedDict
15+
from typing_extensions import Literal, Protocol, TypedDict, runtime_checkable
1616

1717
import pydantic
18-
from httpx import Proxy, Timeout, BaseTransport
18+
from httpx import Proxy, Timeout, Response, BaseTransport
1919

2020
Transport = BaseTransport
2121
Query = Mapping[str, object]
@@ -109,4 +109,16 @@ class Omit:
109109
"""
110110

111111

112+
@runtime_checkable
113+
class ModelBuilderProtocol(Protocol):
114+
@classmethod
115+
def build(
116+
cls: type[_T],
117+
*,
118+
response: Response,
119+
data: object,
120+
) -> _T:
121+
...
122+
123+
112124
Headers = Mapping[str, str]

lithic/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# File generated from our OpenAPI spec by Stainless.
22

33
__title__ = "lithic"
4-
__version__ = "0.1.4"
4+
__version__ = "0.1.5"

lithic/pagination.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# File generated from our OpenAPI spec by Stainless.
22

3-
from typing import List, Generic, Optional
3+
from typing import List, Generic, TypeVar, Optional
44
from typing_extensions import TypedDict
55

6+
from pydantic import BaseModel
7+
68
from ._types import ModelT
79
from ._base_client import BasePage, BaseSyncPage, BaseAsyncPage
810

911
__all__ = ["PageParams", "SyncPage", "AsyncPage"]
1012

13+
_BaseModelT = TypeVar("_BaseModelT", bound=BaseModel)
14+
1115

1216
class PageParams(TypedDict, total=False):
1317
page: int

lithic/resources/account_holders.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def create(
4949

5050
def retrieve(
5151
self,
52-
id: str,
52+
account_holder_token: str,
5353
*,
5454
headers: Union[Headers, NotGiven] = NOT_GIVEN,
5555
max_retries: Union[int, NotGiven] = NOT_GIVEN,
@@ -58,7 +58,7 @@ def retrieve(
5858
"""Check the current status of a KYC or KYB evaluation."""
5959
options = make_request_options(headers, max_retries, timeout)
6060
return self._get(
61-
f"/account_holders/{id}",
61+
f"/account_holders/{account_holder_token}",
6262
options=options,
6363
cast_to=AccountHolder,
6464
)
@@ -95,7 +95,7 @@ def create_webhook(
9595

9696
def list_documents(
9797
self,
98-
id: str,
98+
account_holder_token: str,
9999
*,
100100
headers: Union[Headers, NotGiven] = NOT_GIVEN,
101101
max_retries: Union[int, NotGiven] = NOT_GIVEN,
@@ -120,14 +120,14 @@ def list_documents(
120120
"""
121121
options = make_request_options(headers, max_retries, timeout)
122122
return self._get(
123-
f"/account_holders/{id}/documents",
123+
f"/account_holders/{account_holder_token}/documents",
124124
options=options,
125125
cast_to=AccountHolderListDocumentsResponse,
126126
)
127127

128128
def resubmit(
129129
self,
130-
id: str,
130+
account_holder_token: str,
131131
body: AccountHolderResubmitParams,
132132
*,
133133
headers: Union[Headers, NotGiven] = NOT_GIVEN,
@@ -147,7 +147,7 @@ def resubmit(
147147
"""
148148
options = make_request_options(headers, max_retries, timeout)
149149
return self._post(
150-
f"/account_holders/{id}/resubmit",
150+
f"/account_holders/{account_holder_token}/resubmit",
151151
body=body,
152152
options=options,
153153
cast_to=AccountHolder,
@@ -156,7 +156,7 @@ def resubmit(
156156
def retrieve_document(
157157
self,
158158
account_holder_token: str,
159-
id: str,
159+
document_token: str,
160160
*,
161161
headers: Union[Headers, NotGiven] = NOT_GIVEN,
162162
max_retries: Union[int, NotGiven] = NOT_GIVEN,
@@ -180,14 +180,14 @@ def retrieve_document(
180180
"""
181181
options = make_request_options(headers, max_retries, timeout)
182182
return self._get(
183-
f"/account_holders/{account_holder_token}/documents/{id}",
183+
f"/account_holders/{account_holder_token}/documents/{document_token}",
184184
options=options,
185185
cast_to=AccountHolderDocument,
186186
)
187187

188188
def upload_document(
189189
self,
190-
id: str,
190+
account_holder_token: str,
191191
body: AccountHolderUploadDocumentParams,
192192
*,
193193
headers: Union[Headers, NotGiven] = NOT_GIVEN,
@@ -216,7 +216,7 @@ def upload_document(
216216
"""
217217
options = make_request_options(headers, max_retries, timeout)
218218
return self._post(
219-
f"/account_holders/{id}/documents",
219+
f"/account_holders/{account_holder_token}/documents",
220220
body=body,
221221
options=options,
222222
cast_to=AccountHolderDocument,
@@ -251,7 +251,7 @@ async def create(
251251

252252
async def retrieve(
253253
self,
254-
id: str,
254+
account_holder_token: str,
255255
*,
256256
headers: Union[Headers, NotGiven] = NOT_GIVEN,
257257
max_retries: Union[int, NotGiven] = NOT_GIVEN,
@@ -260,7 +260,7 @@ async def retrieve(
260260
"""Check the current status of a KYC or KYB evaluation."""
261261
options = make_request_options(headers, max_retries, timeout)
262262
return await self._get(
263-
f"/account_holders/{id}",
263+
f"/account_holders/{account_holder_token}",
264264
options=options,
265265
cast_to=AccountHolder,
266266
)
@@ -297,7 +297,7 @@ async def create_webhook(
297297

298298
async def list_documents(
299299
self,
300-
id: str,
300+
account_holder_token: str,
301301
*,
302302
headers: Union[Headers, NotGiven] = NOT_GIVEN,
303303
max_retries: Union[int, NotGiven] = NOT_GIVEN,
@@ -322,14 +322,14 @@ async def list_documents(
322322
"""
323323
options = make_request_options(headers, max_retries, timeout)
324324
return await self._get(
325-
f"/account_holders/{id}/documents",
325+
f"/account_holders/{account_holder_token}/documents",
326326
options=options,
327327
cast_to=AccountHolderListDocumentsResponse,
328328
)
329329

330330
async def resubmit(
331331
self,
332-
id: str,
332+
account_holder_token: str,
333333
body: AccountHolderResubmitParams,
334334
*,
335335
headers: Union[Headers, NotGiven] = NOT_GIVEN,
@@ -349,7 +349,7 @@ async def resubmit(
349349
"""
350350
options = make_request_options(headers, max_retries, timeout)
351351
return await self._post(
352-
f"/account_holders/{id}/resubmit",
352+
f"/account_holders/{account_holder_token}/resubmit",
353353
body=body,
354354
options=options,
355355
cast_to=AccountHolder,
@@ -358,7 +358,7 @@ async def resubmit(
358358
async def retrieve_document(
359359
self,
360360
account_holder_token: str,
361-
id: str,
361+
document_token: str,
362362
*,
363363
headers: Union[Headers, NotGiven] = NOT_GIVEN,
364364
max_retries: Union[int, NotGiven] = NOT_GIVEN,
@@ -382,14 +382,14 @@ async def retrieve_document(
382382
"""
383383
options = make_request_options(headers, max_retries, timeout)
384384
return await self._get(
385-
f"/account_holders/{account_holder_token}/documents/{id}",
385+
f"/account_holders/{account_holder_token}/documents/{document_token}",
386386
options=options,
387387
cast_to=AccountHolderDocument,
388388
)
389389

390390
async def upload_document(
391391
self,
392-
id: str,
392+
account_holder_token: str,
393393
body: AccountHolderUploadDocumentParams,
394394
*,
395395
headers: Union[Headers, NotGiven] = NOT_GIVEN,
@@ -418,7 +418,7 @@ async def upload_document(
418418
"""
419419
options = make_request_options(headers, max_retries, timeout)
420420
return await self._post(
421-
f"/account_holders/{id}/documents",
421+
f"/account_holders/{account_holder_token}/documents",
422422
body=body,
423423
options=options,
424424
cast_to=AccountHolderDocument,

lithic/resources/accounts.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class Accounts(SyncAPIResource):
1717
def retrieve(
1818
self,
19-
id: str,
19+
account_token: str,
2020
*,
2121
headers: Union[Headers, NotGiven] = NOT_GIVEN,
2222
max_retries: Union[int, NotGiven] = NOT_GIVEN,
@@ -25,14 +25,14 @@ def retrieve(
2525
"""Get account configuration such as spend limits."""
2626
options = make_request_options(headers, max_retries, timeout)
2727
return self._get(
28-
f"/accounts/{id}",
28+
f"/accounts/{account_token}",
2929
options=options,
3030
cast_to=Account,
3131
)
3232

3333
def update(
3434
self,
35-
id: str,
35+
account_token: str,
3636
body: AccountUpdateParams,
3737
*,
3838
headers: Union[Headers, NotGiven] = NOT_GIVEN,
@@ -49,7 +49,7 @@ def update(
4949
"""
5050
options = make_request_options(headers, max_retries, timeout)
5151
return self._patch(
52-
f"/accounts/{id}",
52+
f"/accounts/{account_token}",
5353
body=body,
5454
options=options,
5555
cast_to=Account,
@@ -77,7 +77,7 @@ def list(
7777
class AsyncAccounts(AsyncAPIResource):
7878
async def retrieve(
7979
self,
80-
id: str,
80+
account_token: str,
8181
*,
8282
headers: Union[Headers, NotGiven] = NOT_GIVEN,
8383
max_retries: Union[int, NotGiven] = NOT_GIVEN,
@@ -86,14 +86,14 @@ async def retrieve(
8686
"""Get account configuration such as spend limits."""
8787
options = make_request_options(headers, max_retries, timeout)
8888
return await self._get(
89-
f"/accounts/{id}",
89+
f"/accounts/{account_token}",
9090
options=options,
9191
cast_to=Account,
9292
)
9393

9494
async def update(
9595
self,
96-
id: str,
96+
account_token: str,
9797
body: AccountUpdateParams,
9898
*,
9999
headers: Union[Headers, NotGiven] = NOT_GIVEN,
@@ -110,7 +110,7 @@ async def update(
110110
"""
111111
options = make_request_options(headers, max_retries, timeout)
112112
return await self._patch(
113-
f"/accounts/{id}",
113+
f"/accounts/{account_token}",
114114
body=body,
115115
options=options,
116116
cast_to=Account,

0 commit comments

Comments
 (0)