ya_client/activity/requestor/
state.rs

1//! Requestor state part of Activity API
2use ya_client_model::activity::{
3    ActivityState, ActivityUsage, ExeScriptCommandState, ACTIVITY_API_PATH,
4};
5
6use crate::{web::WebClient, web::WebInterface, Result};
7
8/// Bindings for Requestor State part of the Activity API.
9#[derive(Clone)]
10pub struct ActivityRequestorStateApi {
11    client: WebClient,
12}
13
14impl WebInterface for ActivityRequestorStateApi {
15    const API_URL_ENV_VAR: &'static str = crate::activity::ACTIVITY_URL_ENV_VAR;
16    const API_SUFFIX: &'static str = ACTIVITY_API_PATH;
17
18    fn from_client(client: WebClient) -> Self {
19        ActivityRequestorStateApi { client }
20    }
21}
22
23impl ActivityRequestorStateApi {
24    /// Get running command for a specified Activity.
25    pub async fn get_running_command(&self, activity_id: &str) -> Result<ExeScriptCommandState> {
26        let uri = url_format!("activity/{activity_id}/command");
27        self.client.get(&uri).send().json().await
28    }
29
30    /// Get state of specified Activity.
31    pub async fn get_state(&self, activity_id: &str) -> Result<ActivityState> {
32        let uri = url_format!("activity/{activity_id}/state");
33        self.client.get(&uri).send().json().await
34    }
35
36    /// Get usage of specified Activity.
37    pub async fn get_usage(&self, activity_id: &str) -> Result<ActivityUsage> {
38        let uri = url_format!("activity/{activity_id}/usage");
39        self.client.get(&uri).send().json().await
40    }
41}