Skip to content

Commit 1544eb2

Browse files
authored
chore: Move ListPage from apify_shared (#444)
### Description `ListPage` is used only here. This will make it possible to render it in docs.
1 parent 6b27cce commit 1544eb2

14 files changed

+51
-15
lines changed

src/apify_client/clients/base/resource_collection_client.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,46 @@
11
from __future__ import annotations
22

3-
from typing import Any
3+
from typing import Any, Generic, TypeVar
44

5-
from apify_shared.models import ListPage
65
from apify_shared.utils import ignore_docs, parse_date_fields
76

87
from apify_client._utils import pluck_data
98
from apify_client.clients.base.base_client import BaseClient, BaseClientAsync
109

10+
T = TypeVar('T')
11+
12+
13+
class ListPage(Generic[T]):
14+
"""A single page of items returned from a list() method."""
15+
16+
items: list[T]
17+
"""List of returned objects on this page"""
18+
19+
count: int
20+
"""Count of the returned objects on this page"""
21+
22+
offset: int
23+
"""The limit on the number of returned objects offset specified in the API call"""
24+
25+
limit: int
26+
"""The offset of the first object specified in the API call"""
27+
28+
total: int
29+
"""Total number of objects matching the API call criteria"""
30+
31+
desc: bool
32+
"""Whether the listing is descending or not"""
33+
34+
@ignore_docs
35+
def __init__(self, data: dict) -> None:
36+
"""Initialize a ListPage instance from the API response data."""
37+
self.items = data.get('items', [])
38+
self.offset = data.get('offset', 0)
39+
self.limit = data.get('limit', 0)
40+
self.count = data['count'] if 'count' in data else len(self.items)
41+
self.total = data['total'] if 'total' in data else self.offset + self.count
42+
self.desc = data.get('desc', False)
43+
1144

1245
@ignore_docs
1346
class ResourceCollectionClient(BaseClient):

src/apify_client/clients/resource_clients/actor_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from apify_client.clients.resource_clients.actor import get_actor_representation
99

1010
if TYPE_CHECKING:
11-
from apify_shared.models import ListPage
11+
from apify_client.clients.base.resource_collection_client import ListPage
1212

1313

1414
class ActorCollectionClient(ResourceCollectionClient):

src/apify_client/clients/resource_clients/actor_env_var_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from apify_client.clients.resource_clients.actor_env_var import get_actor_env_var_representation
99

1010
if TYPE_CHECKING:
11-
from apify_shared.models import ListPage
11+
from apify_client.clients.base.resource_collection_client import ListPage
1212

1313

1414
class ActorEnvVarCollectionClient(ResourceCollectionClient):

src/apify_client/clients/resource_clients/actor_version_collection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
if TYPE_CHECKING:
1111
from apify_shared.consts import ActorSourceType
12-
from apify_shared.models import ListPage
12+
13+
from apify_client.clients.base.resource_collection_client import ListPage
1314

1415

1516
class ActorVersionCollectionClient(ResourceCollectionClient):

src/apify_client/clients/resource_clients/build_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from apify_client.clients.base import ResourceCollectionClient, ResourceCollectionClientAsync
88

99
if TYPE_CHECKING:
10-
from apify_shared.models import ListPage
10+
from apify_client.clients.base.resource_collection_client import ListPage
1111

1212

1313
class BuildCollectionClient(ResourceCollectionClient):

src/apify_client/clients/resource_clients/dataset_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from apify_client.clients.base import ResourceCollectionClient, ResourceCollectionClientAsync
88

99
if TYPE_CHECKING:
10-
from apify_shared.models import ListPage
10+
from apify_client.clients.base.resource_collection_client import ListPage
1111

1212

1313
class DatasetCollectionClient(ResourceCollectionClient):

src/apify_client/clients/resource_clients/key_value_store_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from apify_client.clients.base import ResourceCollectionClient, ResourceCollectionClientAsync
88

99
if TYPE_CHECKING:
10-
from apify_shared.models import ListPage
10+
from apify_client.clients.base.resource_collection_client import ListPage
1111

1212

1313
class KeyValueStoreCollectionClient(ResourceCollectionClient):

src/apify_client/clients/resource_clients/request_queue_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from apify_client.clients.base import ResourceCollectionClient, ResourceCollectionClientAsync
88

99
if TYPE_CHECKING:
10-
from apify_shared.models import ListPage
10+
from apify_client.clients.base.resource_collection_client import ListPage
1111

1212

1313
class RequestQueueCollectionClient(ResourceCollectionClient):

src/apify_client/clients/resource_clients/run_collection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
if TYPE_CHECKING:
1010
from apify_shared.consts import ActorJobStatus
11-
from apify_shared.models import ListPage
11+
12+
from apify_client.clients.base.resource_collection_client import ListPage
1213

1314

1415
class RunCollectionClient(ResourceCollectionClient):

src/apify_client/clients/resource_clients/schedule_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from apify_client.clients.resource_clients.schedule import _get_schedule_representation
99

1010
if TYPE_CHECKING:
11-
from apify_shared.models import ListPage
11+
from apify_client.clients.base.resource_collection_client import ListPage
1212

1313

1414
class ScheduleCollectionClient(ResourceCollectionClient):

0 commit comments

Comments
 (0)