hanzo_client/apis/
bot_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetBotRunsError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum PostBotRunsError {
29 Status501(),
30 UnknownValue(serde_json::Value),
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum PostBotRunsByRunidStopError {
37 UnknownValue(serde_json::Value),
38}
39
40
41pub async fn get_bot_runs(configuration: &configuration::Configuration, ) -> Result<models::BotRuns, Error<GetBotRunsError>> {
43
44 let uri_str = format!("{}/v1/bot/runs", configuration.base_path);
45 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
46
47 if let Some(ref user_agent) = configuration.user_agent {
48 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
49 }
50 if let Some(ref token) = configuration.bearer_access_token {
51 req_builder = req_builder.bearer_auth(token.to_owned());
52 };
53
54 let req = req_builder.build()?;
55 let resp = configuration.client.execute(req).await?;
56
57 let status = resp.status();
58 let content_type = resp
59 .headers()
60 .get("content-type")
61 .and_then(|v| v.to_str().ok())
62 .unwrap_or("application/octet-stream");
63 let content_type = super::ContentType::from(content_type);
64
65 if !status.is_client_error() && !status.is_server_error() {
66 let content = resp.text().await?;
67 match content_type {
68 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
69 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BotRuns`"))),
70 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::BotRuns`")))),
71 }
72 } else {
73 let content = resp.text().await?;
74 let entity: Option<GetBotRunsError> = serde_json::from_str(&content).ok();
75 Err(Error::ResponseError(ResponseContent { status, content, entity }))
76 }
77}
78
79pub async fn post_bot_runs(configuration: &configuration::Configuration, ) -> Result<(), Error<PostBotRunsError>> {
81
82 let uri_str = format!("{}/v1/bot/runs", configuration.base_path);
83 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
84
85 if let Some(ref user_agent) = configuration.user_agent {
86 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
87 }
88 if let Some(ref token) = configuration.bearer_access_token {
89 req_builder = req_builder.bearer_auth(token.to_owned());
90 };
91
92 let req = req_builder.build()?;
93 let resp = configuration.client.execute(req).await?;
94
95 let status = resp.status();
96
97 if !status.is_client_error() && !status.is_server_error() {
98 Ok(())
99 } else {
100 let content = resp.text().await?;
101 let entity: Option<PostBotRunsError> = serde_json::from_str(&content).ok();
102 Err(Error::ResponseError(ResponseContent { status, content, entity }))
103 }
104}
105
106pub async fn post_bot_runs_by_runid_stop(configuration: &configuration::Configuration, run_id: &str) -> Result<models::BotStopped, Error<PostBotRunsByRunidStopError>> {
108 let p_run_id = run_id;
110
111 let uri_str = format!("{}/v1/bot/runs/{runId}/stop", configuration.base_path, runId=crate::apis::urlencode(p_run_id));
112 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
113
114 if let Some(ref user_agent) = configuration.user_agent {
115 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
116 }
117 if let Some(ref token) = configuration.bearer_access_token {
118 req_builder = req_builder.bearer_auth(token.to_owned());
119 };
120
121 let req = req_builder.build()?;
122 let resp = configuration.client.execute(req).await?;
123
124 let status = resp.status();
125 let content_type = resp
126 .headers()
127 .get("content-type")
128 .and_then(|v| v.to_str().ok())
129 .unwrap_or("application/octet-stream");
130 let content_type = super::ContentType::from(content_type);
131
132 if !status.is_client_error() && !status.is_server_error() {
133 let content = resp.text().await?;
134 match content_type {
135 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
136 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BotStopped`"))),
137 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::BotStopped`")))),
138 }
139 } else {
140 let content = resp.text().await?;
141 let entity: Option<PostBotRunsByRunidStopError> = serde_json::from_str(&content).ok();
142 Err(Error::ResponseError(ResponseContent { status, content, entity }))
143 }
144}
145