use super::{configuration, ContentType, Error};
use crate::gen::manager::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateLocalAutomationError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteLocalAutomationError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetLocalAutomationError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListAllLocalAutomationsError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListLocalAutomationsError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateLocalAutomationError {
UnknownValue(serde_json::Value),
}
pub async fn create_local_automation(
configuration: &configuration::Configuration,
application_id: &str,
rest_create_local_automation: models::RestCreateLocalAutomation,
) -> Result<models::LocalAutomationItemResponse, Error<CreateLocalAutomationError>> {
let p_path_application_id = application_id;
let p_body_rest_create_local_automation = rest_create_local_automation;
let uri_str = format!(
"{}/api/v2/applications/{applicationId}/actions",
configuration.base_path,
applicationId = crate::gen::manager::apis::urlencode(p_path_application_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_rest_create_local_automation);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LocalAutomationItemResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::LocalAutomationItemResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CreateLocalAutomationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn delete_local_automation(
configuration: &configuration::Configuration,
application_id: &str,
id: &str,
) -> Result<serde_json::Value, Error<DeleteLocalAutomationError>> {
let p_path_application_id = application_id;
let p_path_id = id;
let uri_str = format!(
"{}/api/v2/applications/{applicationId}/actions/{id}",
configuration.base_path,
applicationId = crate::gen::manager::apis::urlencode(p_path_application_id),
id = crate::gen::manager::apis::urlencode(p_path_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<DeleteLocalAutomationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn get_local_automation(
configuration: &configuration::Configuration,
application_id: &str,
id: &str,
) -> Result<models::LocalAutomationItemResponse, Error<GetLocalAutomationError>> {
let p_path_application_id = application_id;
let p_path_id = id;
let uri_str = format!(
"{}/api/v2/applications/{applicationId}/actions/{id}",
configuration.base_path,
applicationId = crate::gen::manager::apis::urlencode(p_path_application_id),
id = crate::gen::manager::apis::urlencode(p_path_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LocalAutomationItemResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::LocalAutomationItemResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetLocalAutomationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn list_all_local_automations(
configuration: &configuration::Configuration,
page: Option<i32>,
max: Option<i32>,
) -> Result<models::PaginatedLocalAutomationResponse, Error<ListAllLocalAutomationsError>> {
let p_query_page = page;
let p_query_max = max;
let uri_str = format!("{}/api/v2/automations/local", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_page {
req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_max {
req_builder = req_builder.query(&[("max", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedLocalAutomationResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::PaginatedLocalAutomationResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListAllLocalAutomationsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn list_local_automations(
configuration: &configuration::Configuration,
application_id: &str,
page: Option<i32>,
max: Option<i32>,
) -> Result<models::PaginatedLocalAutomationResponse, Error<ListLocalAutomationsError>> {
let p_path_application_id = application_id;
let p_query_page = page;
let p_query_max = max;
let uri_str = format!(
"{}/api/v2/applications/{applicationId}/actions",
configuration.base_path,
applicationId = crate::gen::manager::apis::urlencode(p_path_application_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_page {
req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_max {
req_builder = req_builder.query(&[("max", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedLocalAutomationResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::PaginatedLocalAutomationResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListLocalAutomationsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn update_local_automation(
configuration: &configuration::Configuration,
application_id: &str,
id: &str,
rest_update_local_automation: models::RestUpdateLocalAutomation,
) -> Result<models::LocalAutomationItemResponse, Error<UpdateLocalAutomationError>> {
let p_path_application_id = application_id;
let p_path_id = id;
let p_body_rest_update_local_automation = rest_update_local_automation;
let uri_str = format!(
"{}/api/v2/applications/{applicationId}/actions/{id}",
configuration.base_path,
applicationId = crate::gen::manager::apis::urlencode(p_path_application_id),
id = crate::gen::manager::apis::urlencode(p_path_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_rest_update_local_automation);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LocalAutomationItemResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::LocalAutomationItemResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<UpdateLocalAutomationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}