Skip to main content

apify_client/clients/
actor_version.rs

1//! Client for a single Actor version (`/v2/actors/{actorId}/versions/{versionNumber}`).
2
3use serde::Serialize;
4
5use crate::clients::actor_env_var::ActorEnvVarClient;
6use crate::clients::actor_env_var_collection::ActorEnvVarCollectionClient;
7use crate::clients::base::{delete_resource, get_resource, update_resource, ResourceContext};
8use crate::common::QueryParams;
9use crate::error::ApifyClientResult;
10use crate::http_client::HttpClient;
11use crate::models::ActorVersion;
12
13/// Client for a specific Actor version.
14#[derive(Debug, Clone)]
15pub struct ActorVersionClient {
16    ctx: ResourceContext,
17}
18
19impl ActorVersionClient {
20    pub(crate) fn new(http: HttpClient, base_url: &str, version_number: &str) -> Self {
21        Self {
22            ctx: ResourceContext::single(http, base_url, "versions", version_number),
23        }
24    }
25
26    /// Fetches the version, or `None` if it does not exist.
27    pub async fn get(&self) -> ApifyClientResult<Option<ActorVersion>> {
28        get_resource(&self.ctx, None, &QueryParams::new()).await
29    }
30
31    /// Updates the version with the given fields.
32    pub async fn update<T: Serialize>(&self, new_fields: &T) -> ApifyClientResult<ActorVersion> {
33        update_resource(&self.ctx, None, new_fields).await
34    }
35
36    /// Deletes the version.
37    pub async fn delete(&self) -> ApifyClientResult<()> {
38        delete_resource(&self.ctx, None).await
39    }
40
41    /// Returns a client for a specific environment variable of this version.
42    pub fn env_var(&self, name: &str) -> ActorEnvVarClient {
43        ActorEnvVarClient::new(self.ctx.http.clone(), &self.ctx.url(None), name)
44    }
45
46    /// Returns a client for this version's environment variable collection.
47    pub fn env_vars(&self) -> ActorEnvVarCollectionClient {
48        ActorEnvVarCollectionClient::new(self.ctx.http.clone(), &self.ctx.url(None))
49    }
50}