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::{single_page_iterator, ListIterator};
7use crate::common::{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. The endpoint takes no query parameters and returns every
26    /// version in a single page.
27    pub async fn list(&self) -> ApifyClientResult<PaginationList<ActorVersion>> {
28        list_resource(&self.ctx, None, &QueryParams::new()).await
29    }
30
31    /// Lazily iterates over the Actor's versions.
32    ///
33    /// The listing is not offset-paginated (the API returns every version in a single page), so this
34    /// yields all of them from that one page and then completes. It exists for interface parity
35    /// with the other collection clients and the reference client.
36    pub fn iterate(&self) -> ListIterator<ActorVersion> {
37        single_page_iterator!(self)
38    }
39
40    /// Creates a new Actor version.
41    pub async fn create<T: Serialize>(&self, version: &T) -> ApifyClientResult<ActorVersion> {
42        create_resource(&self.ctx, &QueryParams::new(), version).await
43    }
44}