artcoded_api/apis/
script_controller_api.rs1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum GetScriptsError {
20 UnknownValue(serde_json::Value),
21}
22
23pub async fn get_scripts(
24 configuration: &configuration::Configuration,
25) -> Result<Vec<models::Script>, Error<GetScriptsError>> {
26 let uri_str = format!("{}/api/script", configuration.base_path);
27 let mut req_builder = configuration
28 .client
29 .request(reqwest::Method::POST, &uri_str);
30
31 if let Some(ref user_agent) = configuration.user_agent {
32 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
33 }
34 if let Some(ref token) = configuration.bearer_access_token {
35 req_builder = req_builder.bearer_auth(token.to_owned());
36 };
37
38 let req = req_builder.build()?;
39 let resp = configuration.client.execute(req).await?;
40
41 let status = resp.status();
42 let content_type = resp
43 .headers()
44 .get("content-type")
45 .and_then(|v| v.to_str().ok())
46 .unwrap_or("application/octet-stream");
47 let content_type = super::ContentType::from(content_type);
48
49 if !status.is_client_error() && !status.is_server_error() {
50 let content = resp.text().await?;
51 match content_type {
52 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
53 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Script>`"))),
54 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Script>`")))),
55 }
56 } else {
57 let content = resp.text().await?;
58 let entity: Option<GetScriptsError> = serde_json::from_str(&content).ok();
59 Err(Error::ResponseError(ResponseContent {
60 status,
61 content,
62 entity,
63 }))
64 }
65}