-
Notifications
You must be signed in to change notification settings - Fork 1
/
environments.rs
71 lines (68 loc) · 2.11 KB
/
environments.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use crate::client::{AdobeConnector, CloudManagerClient};
use crate::errors::throw_adobe_api_error;
use crate::models::environment::{Environment, EnvironmentsList, EnvironmentsResponse};
use crate::HOST_NAME;
use reqwest::{Error, Method};
use std::process;
/// Retrieves all environments of a given program ID.
///
/// # Arguments
///
/// * `client` - A mutable reference to a CloudManagerClient instance
/// * `program_id` - A u32 that holds the program ID
///
/// # Performed API Request
///
/// ```
/// GET https://cloudmanager.adobe.io/api/program/{program_id}/environments
/// ```
pub async fn get_environments(
client: &mut CloudManagerClient,
program_id: u32,
) -> Result<EnvironmentsList, Error> {
let request_path = format!("{}/api/program/{}/environments", HOST_NAME, program_id);
let response = client
.perform_request(Method::GET, request_path, None::<()>, None)
.await?
.text()
.await?;
let environments: EnvironmentsResponse = serde_json::from_str(response.as_str())
.unwrap_or_else(|_| {
throw_adobe_api_error(response);
process::exit(1);
});
Ok(environments.environments_list)
}
/// Retrieves a single environment.
///
/// # Arguments
///
/// * `client` - A mutable reference to a CloudManagerClient instance
/// * `program_id` - A u32 that holds the program ID
/// * `env_id` - A u32 that holds the environment ID
///
/// # Performed API Request
///
/// ```
/// GET https://cloudmanager.adobe.io/api/program/{program_id}/environment/{env_id}
/// ```
pub async fn get_environment(
client: &mut CloudManagerClient,
program_id: u32,
env_id: u32,
) -> Result<Environment, Error> {
let request_path = format!(
"{}/api/program/{}/environment/{}",
HOST_NAME, program_id, env_id
);
let response = client
.perform_request(Method::GET, request_path, None::<()>, None)
.await?
.text()
.await?;
let environment: Environment = serde_json::from_str(response.as_str()).unwrap_or_else(|_| {
throw_adobe_api_error(response);
process::exit(1);
});
Ok(environment)
}