Skip to content

Commit

Permalink
Import ListPage from apify-shared
Browse files Browse the repository at this point in the history
  • Loading branch information
vdusek committed Jul 25, 2023
1 parent 61551a5 commit cf299a3
Show file tree
Hide file tree
Showing 18 changed files with 18 additions and 65 deletions.
19 changes: 0 additions & 19 deletions docs/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6155,22 +6155,3 @@ List all webhook dispatches of a user.
* **Return type**

[`ListPage`](#listpage)

***

### [](#listpage) ListPage

A single page of items returned from a list() method.

#### Instance attributes

Name | Type | Description
---- | ---- | -----------
`items` | `list` | List of returned objects on this page
`offset` | `int` | The limit on the number of returned objects offset specified in the API call
`limit` | `int` | The offset of the first object specified in the API call
`count` | `int` | Count of the returned objects on this page
`total` | `int` | Total number of objects matching the API call criteria
`desc` | `bool` | Whether the listing is descending or not

***
2 changes: 0 additions & 2 deletions docs/res/sphinx-config/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@
:members:
.. automodule:: apify_client.clients.resource_clients
:members:
.. autoclass:: apify_client._utils.ListPage
:members:
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ classifiers = [

requires-python = ">=3.8"
dependencies = [
"apify-shared ~= 1.0.0b2",
"apify-shared ~= 1.0.0b3",
"httpx >= 0.24.1",
]

Expand Down
31 changes: 2 additions & 29 deletions src/apify_client/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import random
import time
from http import HTTPStatus
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict, Generic, List, Optional, Tuple, TypeVar, cast
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict, List, Optional, Tuple, TypeVar, cast

from apify_shared.utils import ignore_docs, is_file_or_bytes, maybe_extract_enum_member_value
from apify_shared.utils import is_file_or_bytes, maybe_extract_enum_member_value

if TYPE_CHECKING:
from ._errors import ApifyApiError
Expand Down Expand Up @@ -146,30 +146,3 @@ def _encode_key_value_store_record_value(value: Any, content_type: Optional[str]
value = json.dumps(value, ensure_ascii=False, indent=2, allow_nan=False, default=str).encode('utf-8')

return (value, content_type)


class ListPage(Generic[T]):
"""A single page of items returned from a list() method."""

#: list: List of returned objects on this page
items: List[T]
#: int: Count of the returned objects on this page
count: int
#: int: The limit on the number of returned objects offset specified in the API call
offset: int
#: int: The offset of the first object specified in the API call
limit: int
#: int: Total number of objects matching the API call criteria
total: int
#: bool: Whether the listing is descending or not
desc: bool

@ignore_docs
def __init__(self, data: Dict) -> None:
"""Initialize a ListPage instance from the API response data."""
self.items = data['items'] if 'items' in data else []
self.offset = data['offset'] if 'offset' in data else 0
self.limit = data['limit'] if 'limit' in data else 0
self.count = data['count'] if 'count' in data else len(self.items)
self.total = data['total'] if 'total' in data else self.offset + self.count
self.desc = data['desc'] if 'desc' in data else False
3 changes: 2 additions & 1 deletion src/apify_client/clients/base/resource_collection_client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import Any, Dict, Optional

from apify_shared.models import ListPage
from apify_shared.utils import ignore_docs, parse_date_fields

from ..._utils import ListPage, _pluck_data
from ..._utils import _pluck_data
from .base_client import BaseClient, BaseClientAsync


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Any, Dict, List, Optional

from apify_shared.models import ListPage
from apify_shared.utils import filter_out_none_values_recursively, ignore_docs

from ..._utils import ListPage
from ..base import ResourceCollectionClient, ResourceCollectionClientAsync
from .actor import _get_actor_representation

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Any, Dict, Optional

from apify_shared.models import ListPage
from apify_shared.utils import filter_out_none_values_recursively, ignore_docs

from ..._utils import ListPage
from ..base import ResourceCollectionClient, ResourceCollectionClientAsync
from .actor_env_var import _get_actor_env_var_representation

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Any, Dict, List, Optional

from apify_shared.consts import ActorSourceType
from apify_shared.models import ListPage
from apify_shared.utils import filter_out_none_values_recursively, ignore_docs

from ..._utils import ListPage
from ..base import ResourceCollectionClient, ResourceCollectionClientAsync
from .actor_version import _get_actor_version_representation

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Any, Dict, Optional

from apify_shared.models import ListPage
from apify_shared.utils import ignore_docs

from ..._utils import ListPage
from ..base import ResourceCollectionClient, ResourceCollectionClientAsync


Expand Down
2 changes: 1 addition & 1 deletion src/apify_client/clients/resource_clients/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import httpx

from apify_shared.models import ListPage
from apify_shared.types import JSONSerializable
from apify_shared.utils import filter_out_none_values_recursively, ignore_docs

from ..._utils import ListPage
from ..base import ResourceClient, ResourceClientAsync


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Any, Dict, Optional

from apify_shared.models import ListPage
from apify_shared.utils import filter_out_none_values_recursively, ignore_docs

from ..._utils import ListPage
from ..base import ResourceCollectionClient, ResourceCollectionClientAsync


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Any, Dict, Optional

from apify_shared.models import ListPage
from apify_shared.utils import filter_out_none_values_recursively, ignore_docs

from ..._utils import ListPage
from ..base import ResourceCollectionClient, ResourceCollectionClientAsync


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Any, Dict, Optional

from apify_shared.models import ListPage
from apify_shared.utils import ignore_docs

from ..._utils import ListPage
from ..base import ResourceCollectionClient, ResourceCollectionClientAsync


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Any, Dict, Optional

from apify_shared.consts import ActorJobStatus
from apify_shared.models import ListPage
from apify_shared.utils import ignore_docs, maybe_extract_enum_member_value

from ..._utils import ListPage
from ..base import ResourceCollectionClient, ResourceCollectionClientAsync


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Any, Dict, List, Optional

from apify_shared.models import ListPage
from apify_shared.utils import filter_out_none_values_recursively, ignore_docs

from ..._utils import ListPage
from ..base import ResourceCollectionClient, ResourceCollectionClientAsync
from .schedule import _get_schedule_representation

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Any, Dict, Optional

from apify_shared.models import ListPage
from apify_shared.utils import filter_out_none_values_recursively, ignore_docs

from ..._utils import ListPage
from ..base import ResourceCollectionClient, ResourceCollectionClientAsync
from .task import _get_task_representation

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Any, Dict, List, Optional

from apify_shared.consts import WebhookEventType
from apify_shared.models import ListPage
from apify_shared.utils import filter_out_none_values_recursively, ignore_docs

from ..._utils import ListPage
from ..base import ResourceCollectionClient, ResourceCollectionClientAsync
from .webhook import _get_webhook_representation

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Any, Dict, Optional

from apify_shared.models import ListPage
from apify_shared.utils import ignore_docs

from ..._utils import ListPage
from ..base import ResourceCollectionClient, ResourceCollectionClientAsync


Expand Down

0 comments on commit cf299a3

Please sign in to comment.