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::{single_page_iterator, 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 listing is not offset-paginated (the API returns every variable in a single page), so this
31    /// yields all of them from that one page and then completes. It exists for interface parity
32    /// with the other collection clients and the reference client.
33    pub fn iterate(&self) -> ListIterator<ActorEnvVar> {
34        single_page_iterator!(self)
35    }
36
37    /// Creates a new environment variable.
38    pub async fn create(&self, env_var: &ActorEnvVar) -> ApifyClientResult<ActorEnvVar> {
39        create_resource(&self.ctx, &QueryParams::new(), env_var).await
40    }
41}