Skip to main content

apify_client/clients/
actor_version_collection.rs

1//! Client for an Actor's version collection (`/v2/actors/{actorId}/versions`).
2
3use serde::Serialize;
4
5use crate::clients::base::{create_resource, list_resource, ResourceContext};
6use crate::clients::pagination::{list_iterator, ListIterator};
7use crate::common::{ListOptions, PaginationList, QueryParams};
8use crate::error::ApifyClientResult;
9use crate::http_client::HttpClient;
10use crate::models::ActorVersion;
11
12/// Client for listing and creating Actor versions.
13#[derive(Debug, Clone)]
14pub struct ActorVersionCollectionClient {
15    ctx: ResourceContext,
16}
17
18impl ActorVersionCollectionClient {
19    pub(crate) fn new(http: HttpClient, base_url: &str) -> Self {
20        Self {
21            ctx: ResourceContext::collection(http, base_url, "versions"),
22        }
23    }
24
25    /// Lists the Actor's versions.
26    pub async fn list(
27        &self,
28        options: ListOptions,
29    ) -> ApifyClientResult<PaginationList<ActorVersion>> {
30        let mut params = QueryParams::new();
31        params
32            .add_int("offset", options.offset)
33            .add_int("limit", options.limit)
34            .add_bool("desc", options.desc);
35        list_resource(&self.ctx, None, &params).await
36    }
37
38    /// Lazily iterates over all versions matching `options`, fetching pages on demand.
39    ///
40    /// `options.limit` caps the *total* number of items yielded across all pages, unlike
41    /// [`list`](Self::list) where `limit` is a single page's size. Set the per-page fetch size
42    /// with [`with_chunk_size`](crate::ListIterator::with_chunk_size); see
43    /// [`ListIterator`] for details.
44    pub fn iterate(&self, options: ListOptions) -> ListIterator<ActorVersion> {
45        list_iterator!(self, options, list)
46    }
47
48    /// Creates a new Actor version.
49    pub async fn create<T: Serialize>(&self, version: &T) -> ApifyClientResult<ActorVersion> {
50        create_resource(&self.ctx, &QueryParams::new(), version).await
51    }
52}