Skip to content

Commit

Permalink
feat: Added StoreCollectionClient for listing Actors in Apify store (#…
Browse files Browse the repository at this point in the history
…147)

- Added new methods for
https://docs.apify.com/api/v2/#/reference/store/store-actors-collection
- Updated actions/checkout across GH workflows because
actions/checkout#1448 (comment)
  • Loading branch information
drobnikj authored Sep 6, 2023
1 parent bf64cb2 commit 88cb4a0
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check_docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint_and_type_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changelog

### Added

- Add StoreCollectionClient for listing Actors in Apify store
- support for specifying the `max_items` parameter for pay-per result Actors and their runs

### Internal changes
Expand Down
102 changes: 102 additions & 0 deletions docs/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ The Apify API client.
* [task()](#apifyclient-task)
* [tasks()](#apifyclient-tasks)
* [user()](#apifyclient-user)
* [store()](#apifyclient-store)

***

Expand Down Expand Up @@ -531,6 +532,16 @@ Retrieve the sub-client for querying users.

***

#### [](#apifyclient-store) `ApifyClient.store()`

Retrieve the sub-client for Apify store.

* **Return type**

[`StoreCollectionClient`](#storecollectionclient)

***

### [](#apifyclientasync) ApifyClientAsync

The asynchronous version of the Apify API client.
Expand Down Expand Up @@ -558,6 +569,7 @@ The asynchronous version of the Apify API client.
* [task()](#apifyclientasync-task)
* [tasks()](#apifyclientasync-tasks)
* [user()](#apifyclientasync-user)
* [store()](#apifyclientasync-store)

***

Expand Down Expand Up @@ -850,6 +862,16 @@ Retrieve the sub-client for querying users.

***

#### [](#apifyclientasync-store) `ApifyClientAsync.store()`

Retrieve the sub-client for Apify store.

* **Return type**

`StoreCollectionClientAsync`

***

### [](#actorclient) ActorClient

Sub-client for manipulating a single actor.
Expand Down Expand Up @@ -6237,3 +6259,83 @@ List all webhook dispatches of a user.
* **Return type**

[`ListPage`](#listpage)

***

### [](#storecollectionclient) StoreCollectionClient

Sub-client for Apify store.

* [list()](#storecollectionclient-list)

***

#### [](#storecollectionclient-list) `StoreCollectionClient.list(*, limit=None, offset=None, search=None, sort_by=None, category=None, username=None, pricing_model=None)`

List Actors in Apify store.

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

* **Parameters**

* **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_by** (`str`, *optional*) – Specifies the field by which to sort the results.

* **category** (`str`, *optional*) – Filter by this category

* **username** (`str`, *optional*) – Filter by this username

* **pricing_model** (`str`, *optional*) – Filter by this pricing model

* **Returns**

The list of available tasks matching the specified filters.

* **Return type**

[`ListPage`](#listpage)

***

### [](#storecollectionclientasync) StoreCollectionClientAsync

Async sub-client for Apify store.

* [async list()](#storecollectionclientasync-list)

***

#### [](#storecollectionclientasync-list) `async StoreCollectionClientAsync.list(*, limit=None, offset=None, search=None, sort_by=None, category=None, username=None, pricing_model=None)`

List Actors in Apify store.

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

* **Parameters**

* **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_by** (`str`, *optional*) – Specifies the field by which to sort the results.

* **category** (`str`, *optional*) – Filter by this category

* **username** (`str`, *optional*) – Filter by this username

* **pricing_model** (`str`, *optional*) – Filter by this pricing model

* **Returns**

The list of available tasks matching the specified filters.

* **Return type**

[`ListPage`](#listpage)
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_by (str, optional): Specifies the field by which to sort the results.
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_by (str, optional): Specifies the field by which to sort the results.
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

0 comments on commit 88cb4a0

Please sign in to comment.