Skip to main content

apify_client/clients/
actor_env_var_collection.rs

1//! Client for an Actor version's environment variable collection.
2
3use crate::clients::base::{create_resource, list_resource, ResourceContext};
4use crate::clients::pagination::ListIterator;
5use crate::common::{PaginationList, QueryParams};
6use crate::error::ApifyClientResult;
7use crate::http_client::HttpClient;
8use crate::models::ActorEnvVar;
9
10/// Client for listing and creating environment variables of an Actor version.
11#[derive(Debug, Clone)]
12pub struct ActorEnvVarCollectionClient {
13    ctx: ResourceContext,
14}
15
16impl ActorEnvVarCollectionClient {
17    pub(crate) fn new(http: HttpClient, base_url: &str) -> Self {
18        Self {
19            ctx: ResourceContext::collection(http, base_url, "env-vars"),
20        }
21    }
22
23    /// Lists the environment variables of the Actor version.
24    pub async fn list(&self) -> ApifyClientResult<PaginationList<ActorEnvVar>> {
25        list_resource(&self.ctx, None, &QueryParams::new()).await
26    }
27
28    /// Lazily iterates over the Actor version's environment variables.
29    ///
30    /// The env-var listing is not offset-paginated (the API returns every variable in a single
31    /// page), so this yields all variables from that one page and then completes. It exists for
32    /// interface parity with the other collection clients and the reference client. Built with
33    /// [`ListIterator::new_single_page`], which fetches exactly once and never re-requests.
34    pub fn iterate(&self) -> ListIterator<ActorEnvVar> {
35        let client = self.clone();
36        ListIterator::new_single_page(Box::new(move |_offset, _page_limit| {
37            let client = client.clone();
38            Box::pin(async move { client.list().await })
39        }))
40    }
41
42    /// Creates a new environment variable.
43    pub async fn create(&self, env_var: &ActorEnvVar) -> ApifyClientResult<ActorEnvVar> {
44        create_resource(&self.ctx, &QueryParams::new(), env_var).await
45    }
46}