Skip to content

Commit ee8775b

Browse files
feat(api): manual updates (#10)
1 parent ac996eb commit ee8775b

File tree

6 files changed

+515
-451
lines changed

6 files changed

+515
-451
lines changed

api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ Methods:
2020
- <code title="post /connect/magic-link">client.<a href="./src/openint/_client.py">create_magic_link</a>(\*\*<a href="src/openint/types/client_create_magic_link_params.py">params</a>) -> <a href="./src/openint/types/create_magic_link_response.py">CreateMagicLinkResponse</a></code>
2121
- <code title="post /connect/token">client.<a href="./src/openint/_client.py">create_token</a>(\*\*<a href="src/openint/types/client_create_token_params.py">params</a>) -> <a href="./src/openint/types/create_token_response.py">CreateTokenResponse</a></code>
2222
- <code title="get /connection">client.<a href="./src/openint/_client.py">get_connection</a>(\*\*<a href="src/openint/types/client_get_connection_params.py">params</a>) -> <a href="./src/openint/types/get_connection_response.py">GetConnectionResponse</a></code>
23-
- <code title="get /connector-config">client.<a href="./src/openint/_client.py">list_connection_configs</a>(\*\*<a href="src/openint/types/client_list_connection_configs_params.py">params</a>) -> <a href="./src/openint/types/list_connection_configs_response.py">ListConnectionConfigsResponse</a></code>
23+
- <code title="get /connector-config">client.<a href="./src/openint/_client.py">list_connection_configs</a>(\*\*<a href="src/openint/types/client_list_connection_configs_params.py">params</a>) -> <a href="./src/openint/types/list_connection_configs_response.py">SyncOffsetPagination[ListConnectionConfigsResponse]</a></code>
2424
- <code title="get /connection/{id}">client.<a href="./src/openint/_client.py">list_connections</a>(id, \*\*<a href="src/openint/types/client_list_connections_params.py">params</a>) -> <a href="./src/openint/types/list_connections_response.py">ListConnectionsResponse</a></code>
25-
- <code title="get /event">client.<a href="./src/openint/_client.py">list_events</a>(\*\*<a href="src/openint/types/client_list_events_params.py">params</a>) -> <a href="./src/openint/types/list_events_response.py">ListEventsResponse</a></code>
25+
- <code title="get /event">client.<a href="./src/openint/_client.py">list_events</a>(\*\*<a href="src/openint/types/client_list_events_params.py">params</a>) -> <a href="./src/openint/types/list_events_response.py">SyncOffsetPagination[ListEventsResponse]</a></code>

src/openint/_client.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@
4444
async_to_streamed_response_wrapper,
4545
)
4646
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
47+
from .pagination import SyncOffsetPagination, AsyncOffsetPagination
4748
from ._exceptions import APIStatusError
4849
from ._base_client import (
4950
DEFAULT_MAX_RETRIES,
5051
SyncAPIClient,
5152
AsyncAPIClient,
53+
AsyncPaginator,
5254
make_request_options,
5355
)
5456
from .types.list_events_response import ListEventsResponse
@@ -605,7 +607,7 @@ def list_connection_configs(
605607
extra_query: Query | None = None,
606608
extra_body: Body | None = None,
607609
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
608-
) -> ListConnectionConfigsResponse:
610+
) -> SyncOffsetPagination[ListConnectionConfigsResponse]:
609611
"""
610612
List all connector configurations with optional filtering
611613
@@ -620,8 +622,9 @@ def list_connection_configs(
620622
621623
timeout: Override the client-level default timeout for this request, in seconds
622624
"""
623-
return self.get(
625+
return self.get_api_list(
624626
"/connector-config",
627+
page=SyncOffsetPagination[ListConnectionConfigsResponse],
625628
options=make_request_options(
626629
extra_headers=extra_headers,
627630
extra_query=extra_query,
@@ -637,7 +640,9 @@ def list_connection_configs(
637640
client_list_connection_configs_params.ClientListConnectionConfigsParams,
638641
),
639642
),
640-
cast_to=ListConnectionConfigsResponse,
643+
model=cast(
644+
Any, ListConnectionConfigsResponse
645+
), # Union types cannot be passed in as arguments in the type system
641646
)
642647

643648
def list_connections(
@@ -708,7 +713,7 @@ def list_events(
708713
extra_query: Query | None = None,
709714
extra_body: Body | None = None,
710715
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
711-
) -> ListEventsResponse:
716+
) -> SyncOffsetPagination[ListEventsResponse]:
712717
"""
713718
List all events for an organization
714719
@@ -721,8 +726,9 @@ def list_events(
721726
722727
timeout: Override the client-level default timeout for this request, in seconds
723728
"""
724-
return self.get(
729+
return self.get_api_list(
725730
"/event",
731+
page=SyncOffsetPagination[ListEventsResponse],
726732
options=make_request_options(
727733
extra_headers=extra_headers,
728734
extra_query=extra_query,
@@ -736,7 +742,7 @@ def list_events(
736742
client_list_events_params.ClientListEventsParams,
737743
),
738744
),
739-
cast_to=ListEventsResponse,
745+
model=ListEventsResponse,
740746
)
741747

742748
@override
@@ -1248,7 +1254,7 @@ async def get_connection(
12481254
cast_to=GetConnectionResponse,
12491255
)
12501256

1251-
async def list_connection_configs(
1257+
def list_connection_configs(
12521258
self,
12531259
*,
12541260
connector_name: Literal[
@@ -1316,7 +1322,7 @@ async def list_connection_configs(
13161322
extra_query: Query | None = None,
13171323
extra_body: Body | None = None,
13181324
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
1319-
) -> ListConnectionConfigsResponse:
1325+
) -> AsyncPaginator[ListConnectionConfigsResponse, AsyncOffsetPagination[ListConnectionConfigsResponse]]:
13201326
"""
13211327
List all connector configurations with optional filtering
13221328
@@ -1331,14 +1337,15 @@ async def list_connection_configs(
13311337
13321338
timeout: Override the client-level default timeout for this request, in seconds
13331339
"""
1334-
return await self.get(
1340+
return self.get_api_list(
13351341
"/connector-config",
1342+
page=AsyncOffsetPagination[ListConnectionConfigsResponse],
13361343
options=make_request_options(
13371344
extra_headers=extra_headers,
13381345
extra_query=extra_query,
13391346
extra_body=extra_body,
13401347
timeout=timeout,
1341-
query=await async_maybe_transform(
1348+
query=maybe_transform(
13421349
{
13431350
"connector_name": connector_name,
13441351
"expand": expand,
@@ -1348,7 +1355,9 @@ async def list_connection_configs(
13481355
client_list_connection_configs_params.ClientListConnectionConfigsParams,
13491356
),
13501357
),
1351-
cast_to=ListConnectionConfigsResponse,
1358+
model=cast(
1359+
Any, ListConnectionConfigsResponse
1360+
), # Union types cannot be passed in as arguments in the type system
13521361
)
13531362

13541363
async def list_connections(
@@ -1408,7 +1417,7 @@ async def list_connections(
14081417
),
14091418
)
14101419

1411-
async def list_events(
1420+
def list_events(
14121421
self,
14131422
*,
14141423
limit: int | NotGiven = NOT_GIVEN,
@@ -1419,7 +1428,7 @@ async def list_events(
14191428
extra_query: Query | None = None,
14201429
extra_body: Body | None = None,
14211430
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
1422-
) -> ListEventsResponse:
1431+
) -> AsyncPaginator[ListEventsResponse, AsyncOffsetPagination[ListEventsResponse]]:
14231432
"""
14241433
List all events for an organization
14251434
@@ -1432,22 +1441,23 @@ async def list_events(
14321441
14331442
timeout: Override the client-level default timeout for this request, in seconds
14341443
"""
1435-
return await self.get(
1444+
return self.get_api_list(
14361445
"/event",
1446+
page=AsyncOffsetPagination[ListEventsResponse],
14371447
options=make_request_options(
14381448
extra_headers=extra_headers,
14391449
extra_query=extra_query,
14401450
extra_body=extra_body,
14411451
timeout=timeout,
1442-
query=await async_maybe_transform(
1452+
query=maybe_transform(
14431453
{
14441454
"limit": limit,
14451455
"offset": offset,
14461456
},
14471457
client_list_events_params.ClientListEventsParams,
14481458
),
14491459
),
1450-
cast_to=ListEventsResponse,
1460+
model=ListEventsResponse,
14511461
)
14521462

14531463
@override

src/openint/pagination.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import List, Generic, TypeVar, Optional
4+
from typing_extensions import override
5+
6+
from ._base_client import BasePage, PageInfo, BaseSyncPage, BaseAsyncPage
7+
8+
__all__ = ["SyncOffsetPagination", "AsyncOffsetPagination"]
9+
10+
_T = TypeVar("_T")
11+
12+
13+
class SyncOffsetPagination(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
14+
items: List[_T]
15+
total: Optional[int] = None
16+
offset: Optional[int] = None
17+
limit: Optional[int] = None
18+
19+
@override
20+
def _get_page_items(self) -> List[_T]:
21+
items = self.items
22+
if not items:
23+
return []
24+
return items
25+
26+
@override
27+
def next_page_info(self) -> Optional[PageInfo]:
28+
offset = self.offset
29+
if offset is None:
30+
return None
31+
32+
length = len(self._get_page_items())
33+
current_count = offset + length
34+
35+
total = self.total
36+
if total is None:
37+
return None
38+
39+
if current_count < total:
40+
return PageInfo(params={"offset": current_count})
41+
42+
return None
43+
44+
45+
class AsyncOffsetPagination(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
46+
items: List[_T]
47+
total: Optional[int] = None
48+
offset: Optional[int] = None
49+
limit: Optional[int] = None
50+
51+
@override
52+
def _get_page_items(self) -> List[_T]:
53+
items = self.items
54+
if not items:
55+
return []
56+
return items
57+
58+
@override
59+
def next_page_info(self) -> Optional[PageInfo]:
60+
offset = self.offset
61+
if offset is None:
62+
return None
63+
64+
length = len(self._get_page_items())
65+
current_count = offset + length
66+
67+
total = self.total
68+
if total is None:
69+
return None
70+
71+
if current_count < total:
72+
return PageInfo(params={"offset": current_count})
73+
74+
return None

0 commit comments

Comments
 (0)