Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added StoreCollectionClient for listing Actors in Apify store #147

Merged
merged 5 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/apify_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
ScheduleClientAsync,
ScheduleCollectionClient,
ScheduleCollectionClientAsync,
StoreCollectionClient,
StoreCollectionClientAsync,
TaskClient,
TaskClientAsync,
TaskCollectionClient,
Expand Down Expand Up @@ -268,6 +270,10 @@ def user(self, user_id: Optional[str] = None) -> UserClient:
"""
return UserClient(resource_id=user_id, **self._options())

def store(self) -> StoreCollectionClient:
"""Retrieve the sub-client for Apify store."""
return StoreCollectionClient(**self._options())


class ApifyClientAsync(_BaseApifyClient):
"""The asynchronous version of the Apify API client."""
Expand Down Expand Up @@ -444,3 +450,7 @@ def user(self, user_id: Optional[str] = None) -> UserClientAsync:
user_id (str, optional): ID of user to be queried. If None, queries the user belonging to the token supplied to the client
"""
return UserClientAsync(resource_id=user_id, **self._options())

def store(self) -> StoreCollectionClientAsync:
"""Retrieve the sub-client for Apify store."""
return StoreCollectionClientAsync(**self._options())
3 changes: 3 additions & 0 deletions src/apify_client/clients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
ScheduleClientAsync,
ScheduleCollectionClient,
ScheduleCollectionClientAsync,
StoreCollectionClient,
StoreCollectionClientAsync,
TaskClient,
TaskClientAsync,
TaskCollectionClient,
Expand Down Expand Up @@ -88,4 +90,5 @@
'WebhookCollectionClient', 'WebhookCollectionClientAsync',
'WebhookDispatchClient', 'WebhookDispatchClientAsync',
'WebhookDispatchCollectionClient', 'WebhookDispatchCollectionClientAsync',
'StoreCollectionClient', 'StoreCollectionClientAsync',
]
2 changes: 2 additions & 0 deletions src/apify_client/clients/resource_clients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .run_collection import RunCollectionClient, RunCollectionClientAsync
from .schedule import ScheduleClient, ScheduleClientAsync
from .schedule_collection import ScheduleCollectionClient, ScheduleCollectionClientAsync
from .store_collection import StoreCollectionClient, StoreCollectionClientAsync
from .task import TaskClient, TaskClientAsync
from .task_collection import TaskCollectionClient, TaskCollectionClientAsync
from .user import UserClient, UserClientAsync
Expand Down Expand Up @@ -48,4 +49,5 @@
'ScheduleClient', 'WebhookCollectionClientAsync',
'ScheduleCollectionClient', 'WebhookDispatchClientAsync',
'UserClient', 'WebhookDispatchCollectionClientAsync',
'StoreCollectionClient', 'StoreCollectionClientAsync',
]
100 changes: 100 additions & 0 deletions src/apify_client/clients/resource_clients/store_collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
from typing import Any, Dict, Optional

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

from ..base import ResourceCollectionClient, ResourceCollectionClientAsync


class StoreCollectionClient(ResourceCollectionClient):
"""Sub-client for Apify store."""

@ignore_docs
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Initialize the StoreCollectionClient."""
resource_path = kwargs.pop('resource_path', 'store')
super().__init__(*args, resource_path=resource_path, **kwargs)

def list(
self,
*,
limit: Optional[int] = None,
offset: Optional[int] = None,
search: Optional[str] = None,
sort_by: Optional[str] = None,
category: Optional[str] = None,
username: Optional[str] = None,
pricing_model: Optional[str] = None,
) -> ListPage[Dict]:
"""List Actors in Apify store.

https://docs.apify.com/api/v2/#/reference/store/store-actors-collection/get-list-of-actors-in-store

Args:
limit (int, optional): How many Actors to list
offset (int, optional): What Actor to include as first when retrieving the list
search (str, optional): String to search by. The search runs on the following fields: title, name, description, username, readme.
sort_be (str, optional): Specifies the field by which to sort the results.
drobnikj marked this conversation as resolved.
Show resolved Hide resolved
category (str, optional): Filter by this category
username (str, optional): Filter by this username
pricing_model (str, optional): Filter by this pricing model

Returns:
ListPage: The list of available tasks matching the specified filters.
"""
return self._list(
limit=limit,
offset=offset,
search=search,
sortBy=sort_by,
category=category,
username=username,
pricingModel=pricing_model,
)


class StoreCollectionClientAsync(ResourceCollectionClientAsync):
"""Async sub-client for Apify store."""

@ignore_docs
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Initialize the StoreCollectionClientAsync."""
resource_path = kwargs.pop('resource_path', 'store')
super().__init__(*args, resource_path=resource_path, **kwargs)

async def list(
self,
*,
limit: Optional[int] = None,
offset: Optional[int] = None,
search: Optional[str] = None,
sort_by: Optional[str] = None,
category: Optional[str] = None,
username: Optional[str] = None,
pricing_model: Optional[str] = None,
) -> ListPage[Dict]:
"""List Actors in Apify store.

https://docs.apify.com/api/v2/#/reference/store/store-actors-collection/get-list-of-actors-in-store

Args:
limit (int, optional): How many Actors to list
offset (int, optional): What Actor to include as first when retrieving the list
search (str, optional): String to search by. The search runs on the following fields: title, name, description, username, readme.
sort_be (str, optional): Specifies the field by which to sort the results.
drobnikj marked this conversation as resolved.
Show resolved Hide resolved
category (str, optional): Filter by this category
username (str, optional): Filter by this username
pricing_model (str, optional): Filter by this pricing model

Returns:
ListPage: The list of available tasks matching the specified filters.
"""
return await self._list(
limit=limit,
offset=offset,
search=search,
sortBy=sort_by,
category=category,
username=username,
pricingModel=pricing_model,
)
15 changes: 15 additions & 0 deletions tests/integration/test_store.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from apify_client import ApifyClient, ApifyClientAsync


class TestStoreCollectionSync:
def test_list(self, apify_client: ApifyClient) -> None:
actors_list = apify_client.store().list()
assert actors_list is not None
assert len(actors_list.items) != 0


class TestStoreCollectionAsync:
async def test_list(self, apify_client_async: ApifyClientAsync) -> None:
actors_list = await apify_client_async.store().list()
assert actors_list is not None
assert len(actors_list.items) != 0