use super::{ContentType, Error, configuration};
use crate::clients::rest::{apis::ResponseContent, models};
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum V1WorkflowRunCreateError {
Status400(models::V1TaskGet400Response),
Status403(models::V1TaskGet400Response),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum V1WorkflowRunDisplayNamesListError {
Status400(models::V1TaskGet400Response),
Status403(models::V1TaskGet400Response),
Status501(models::V1TaskGet400Response),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum V1WorkflowRunGetError {
Status400(models::V1TaskGet400Response),
Status403(models::V1TaskGet400Response),
Status501(models::V1TaskGet400Response),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum V1WorkflowRunGetStatusError {
Status400(models::V1TaskGet400Response),
Status403(models::V1TaskGet400Response),
Status404(models::V1TaskGet400Response),
Status501(models::V1TaskGet400Response),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum V1WorkflowRunGetTimingsError {
Status400(models::V1TaskGet400Response),
Status403(models::V1TaskGet400Response),
Status501(models::V1TaskGet400Response),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum V1WorkflowRunListError {
Status400(models::V1TaskGet400Response),
Status403(models::V1TaskGet400Response),
Status501(models::V1TaskGet400Response),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum V1WorkflowRunTaskEventsListError {
Status400(models::V1TaskGet400Response),
Status403(models::V1TaskGet400Response),
Status501(models::V1TaskGet400Response),
UnknownValue(serde_json::Value),
}
pub async fn v1_workflow_run_create(
configuration: &configuration::Configuration,
tenant: &str,
v1_workflow_run_create_request: models::V1WorkflowRunCreateRequest,
) -> Result<models::V1WorkflowRunCreate200Response, Error<V1WorkflowRunCreateError>> {
let p_tenant = tenant;
let p_v1_workflow_run_create_request = v1_workflow_run_create_request;
let uri_str = format!(
"{}/api/v1/stable/tenants/{tenant}/workflow-runs/trigger",
configuration.base_path,
tenant = crate::clients::rest::apis::urlencode(p_tenant)
);
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.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_v1_workflow_run_create_request);
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::V1WorkflowRunCreate200Response`",
)));
}
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::V1WorkflowRunCreate200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<V1WorkflowRunCreateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn v1_workflow_run_display_names_list(
configuration: &configuration::Configuration,
tenant: &str,
external_ids: Vec<uuid::Uuid>,
) -> Result<
models::V1WorkflowRunDisplayNamesList200Response,
Error<V1WorkflowRunDisplayNamesListError>,
> {
let p_tenant = tenant;
let p_external_ids = external_ids;
let uri_str = format!(
"{}/api/v1/stable/tenants/{tenant}/workflow-runs/display-names",
configuration.base_path,
tenant = crate::clients::rest::apis::urlencode(p_tenant)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = match "multi" {
"multi" => req_builder.query(
&p_external_ids
.into_iter()
.map(|p| ("external_ids".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"external_ids",
&p_external_ids
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.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.bearer_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::V1WorkflowRunDisplayNamesList200Response`",
)));
}
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::V1WorkflowRunDisplayNamesList200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<V1WorkflowRunDisplayNamesListError> =
serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn v1_workflow_run_get(
configuration: &configuration::Configuration,
v1_workflow_run: &str,
) -> Result<models::V1WorkflowRunCreate200Response, Error<V1WorkflowRunGetError>> {
let p_v1_workflow_run = v1_workflow_run;
let uri_str = format!(
"{}/api/v1/stable/workflow-runs/{v1_workflow_run}",
configuration.base_path,
v1_workflow_run = crate::clients::rest::apis::urlencode(p_v1_workflow_run)
);
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.bearer_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::V1WorkflowRunCreate200Response`",
)));
}
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::V1WorkflowRunCreate200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<V1WorkflowRunGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn v1_workflow_run_get_status(
configuration: &configuration::Configuration,
v1_workflow_run: &str,
) -> Result<String, Error<V1WorkflowRunGetStatusError>> {
let p_v1_workflow_run = v1_workflow_run;
let uri_str = format!(
"{}/api/v1/stable/workflow-runs/{v1_workflow_run}/status",
configuration.base_path,
v1_workflow_run = crate::clients::rest::apis::urlencode(p_v1_workflow_run)
);
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.bearer_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 `String`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `String`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<V1WorkflowRunGetStatusError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn v1_workflow_run_get_timings(
configuration: &configuration::Configuration,
v1_workflow_run: &str,
depth: Option<i64>,
) -> Result<models::V1WorkflowRunGetTimings200Response, Error<V1WorkflowRunGetTimingsError>> {
let p_v1_workflow_run = v1_workflow_run;
let p_depth = depth;
let uri_str = format!(
"{}/api/v1/stable/workflow-runs/{v1_workflow_run}/task-timings",
configuration.base_path,
v1_workflow_run = crate::clients::rest::apis::urlencode(p_v1_workflow_run)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_depth {
req_builder = req_builder.query(&[("depth", ¶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.bearer_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::V1WorkflowRunGetTimings200Response`",
)));
}
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::V1WorkflowRunGetTimings200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<V1WorkflowRunGetTimingsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn v1_workflow_run_list(
configuration: &configuration::Configuration,
tenant: &str,
since: String,
only_tasks: bool,
offset: Option<i64>,
limit: Option<i64>,
statuses: Option<Vec<String>>,
until: Option<String>,
additional_metadata: Option<Vec<String>>,
workflow_ids: Option<Vec<uuid::Uuid>>,
worker_id: Option<&str>,
parent_task_external_id: Option<&str>,
triggering_event_external_id: Option<&str>,
include_payloads: Option<bool>,
) -> Result<models::V1WorkflowRunList200Response, Error<V1WorkflowRunListError>> {
let p_tenant = tenant;
let p_since = since;
let p_only_tasks = only_tasks;
let p_offset = offset;
let p_limit = limit;
let p_statuses = statuses;
let p_until = until;
let p_additional_metadata = additional_metadata;
let p_workflow_ids = workflow_ids;
let p_worker_id = worker_id;
let p_parent_task_external_id = parent_task_external_id;
let p_triggering_event_external_id = triggering_event_external_id;
let p_include_payloads = include_payloads;
let uri_str = format!(
"{}/api/v1/stable/tenants/{tenant}/workflow-runs",
configuration.base_path,
tenant = crate::clients::rest::apis::urlencode(p_tenant)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_offset {
req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_statuses {
req_builder = match "multi" {
"multi" => req_builder.query(
¶m_value
.into_iter()
.map(|p| ("statuses".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"statuses",
¶m_value
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
req_builder = req_builder.query(&[("since", &p_since.to_string())]);
if let Some(ref param_value) = p_until {
req_builder = req_builder.query(&[("until", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_additional_metadata {
req_builder = match "multi" {
"multi" => req_builder.query(
¶m_value
.into_iter()
.map(|p| ("additional_metadata".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"additional_metadata",
¶m_value
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
if let Some(ref param_value) = p_workflow_ids {
req_builder = match "multi" {
"multi" => req_builder.query(
¶m_value
.into_iter()
.map(|p| ("workflow_ids".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"workflow_ids",
¶m_value
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
if let Some(ref param_value) = p_worker_id {
req_builder = req_builder.query(&[("worker_id", ¶m_value.to_string())]);
}
req_builder = req_builder.query(&[("only_tasks", &p_only_tasks.to_string())]);
if let Some(ref param_value) = p_parent_task_external_id {
req_builder = req_builder.query(&[("parent_task_external_id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_triggering_event_external_id {
req_builder =
req_builder.query(&[("triggering_event_external_id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_include_payloads {
req_builder = req_builder.query(&[("include_payloads", ¶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.bearer_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::V1WorkflowRunList200Response`",
)));
}
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::V1WorkflowRunList200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<V1WorkflowRunListError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn v1_workflow_run_task_events_list(
configuration: &configuration::Configuration,
v1_workflow_run: &str,
offset: Option<i64>,
limit: Option<i64>,
) -> Result<models::V1TaskEventList200Response, Error<V1WorkflowRunTaskEventsListError>> {
let p_v1_workflow_run = v1_workflow_run;
let p_offset = offset;
let p_limit = limit;
let uri_str = format!(
"{}/api/v1/stable/workflow-runs/{v1_workflow_run}/task-events",
configuration.base_path,
v1_workflow_run = crate::clients::rest::apis::urlencode(p_v1_workflow_run)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_offset {
req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_limit {
req_builder = req_builder.query(&[("limit", ¶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.bearer_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::V1TaskEventList200Response`",
)));
}
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::V1TaskEventList200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<V1WorkflowRunTaskEventsListError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}