1use 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 ClaimRoutineRunError {
22 Status401(models::ApiError),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum CompleteRoutineRunError {
30 Status401(models::ApiError),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum CreateRoutineError {
38 Status401(models::ApiError),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum DeleteRoutineError {
46 Status401(models::ApiError),
47 UnknownValue(serde_json::Value),
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum GetRoutineError {
54 Status401(models::ApiError),
55 Status404(models::ApiError),
56 UnknownValue(serde_json::Value),
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum ListRoutineRunsError {
63 Status401(models::ApiError),
64 UnknownValue(serde_json::Value),
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum ListRoutinesError {
71 Status401(models::ApiError),
72 UnknownValue(serde_json::Value),
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum RunRoutineNowError {
79 Status401(models::ApiError),
80 UnknownValue(serde_json::Value),
81}
82
83#[derive(Debug, Clone, Serialize, Deserialize)]
85#[serde(untagged)]
86pub enum UpdateRoutineError {
87 Status401(models::ApiError),
88 UnknownValue(serde_json::Value),
89}
90
91#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(untagged)]
94pub enum UpdateRoutineRunProgressError {
95 Status401(models::ApiError),
96 UnknownValue(serde_json::Value),
97}
98
99
100pub async fn claim_routine_run(configuration: &configuration::Configuration, id: &str) -> Result<models::RoutineRun, Error<ClaimRoutineRunError>> {
101 let p_path_id = id;
103
104 let uri_str = format!("{}/v1/routines/runs/{id}/claim", configuration.base_path, id=crate::apis::urlencode(p_path_id));
105 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
106
107 if let Some(ref user_agent) = configuration.user_agent {
108 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
109 }
110 if let Some(ref token) = configuration.bearer_access_token {
111 req_builder = req_builder.bearer_auth(token.to_owned());
112 };
113
114 let req = req_builder.build()?;
115 let resp = configuration.client.execute(req).await?;
116
117 let status = resp.status();
118 let content_type = resp
119 .headers()
120 .get("content-type")
121 .and_then(|v| v.to_str().ok())
122 .unwrap_or("application/octet-stream");
123 let content_type = super::ContentType::from(content_type);
124
125 if !status.is_client_error() && !status.is_server_error() {
126 let content = resp.text().await?;
127 match content_type {
128 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
129 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RoutineRun`"))),
130 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::RoutineRun`")))),
131 }
132 } else {
133 let content = resp.text().await?;
134 let entity: Option<ClaimRoutineRunError> = serde_json::from_str(&content).ok();
135 Err(Error::ResponseError(ResponseContent { status, content, entity }))
136 }
137}
138
139pub async fn complete_routine_run(configuration: &configuration::Configuration, id: &str, routine_run_complete_request: models::RoutineRunCompleteRequest) -> Result<models::RoutineRun, Error<CompleteRoutineRunError>> {
140 let p_path_id = id;
142 let p_body_routine_run_complete_request = routine_run_complete_request;
143
144 let uri_str = format!("{}/v1/routines/runs/{id}/complete", configuration.base_path, id=crate::apis::urlencode(p_path_id));
145 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
146
147 if let Some(ref user_agent) = configuration.user_agent {
148 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
149 }
150 if let Some(ref token) = configuration.bearer_access_token {
151 req_builder = req_builder.bearer_auth(token.to_owned());
152 };
153 req_builder = req_builder.json(&p_body_routine_run_complete_request);
154
155 let req = req_builder.build()?;
156 let resp = configuration.client.execute(req).await?;
157
158 let status = resp.status();
159 let content_type = resp
160 .headers()
161 .get("content-type")
162 .and_then(|v| v.to_str().ok())
163 .unwrap_or("application/octet-stream");
164 let content_type = super::ContentType::from(content_type);
165
166 if !status.is_client_error() && !status.is_server_error() {
167 let content = resp.text().await?;
168 match content_type {
169 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
170 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RoutineRun`"))),
171 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::RoutineRun`")))),
172 }
173 } else {
174 let content = resp.text().await?;
175 let entity: Option<CompleteRoutineRunError> = serde_json::from_str(&content).ok();
176 Err(Error::ResponseError(ResponseContent { status, content, entity }))
177 }
178}
179
180pub async fn create_routine(configuration: &configuration::Configuration, create_routine_request: models::CreateRoutineRequest) -> Result<models::Routine, Error<CreateRoutineError>> {
181 let p_body_create_routine_request = create_routine_request;
183
184 let uri_str = format!("{}/v1/routines", configuration.base_path);
185 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
186
187 if let Some(ref user_agent) = configuration.user_agent {
188 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
189 }
190 if let Some(ref token) = configuration.bearer_access_token {
191 req_builder = req_builder.bearer_auth(token.to_owned());
192 };
193 req_builder = req_builder.json(&p_body_create_routine_request);
194
195 let req = req_builder.build()?;
196 let resp = configuration.client.execute(req).await?;
197
198 let status = resp.status();
199 let content_type = resp
200 .headers()
201 .get("content-type")
202 .and_then(|v| v.to_str().ok())
203 .unwrap_or("application/octet-stream");
204 let content_type = super::ContentType::from(content_type);
205
206 if !status.is_client_error() && !status.is_server_error() {
207 let content = resp.text().await?;
208 match content_type {
209 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
210 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Routine`"))),
211 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::Routine`")))),
212 }
213 } else {
214 let content = resp.text().await?;
215 let entity: Option<CreateRoutineError> = serde_json::from_str(&content).ok();
216 Err(Error::ResponseError(ResponseContent { status, content, entity }))
217 }
218}
219
220pub async fn delete_routine(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteRoutineError>> {
221 let p_path_id = id;
223
224 let uri_str = format!("{}/v1/routines/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
225 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
226
227 if let Some(ref user_agent) = configuration.user_agent {
228 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
229 }
230 if let Some(ref token) = configuration.bearer_access_token {
231 req_builder = req_builder.bearer_auth(token.to_owned());
232 };
233
234 let req = req_builder.build()?;
235 let resp = configuration.client.execute(req).await?;
236
237 let status = resp.status();
238
239 if !status.is_client_error() && !status.is_server_error() {
240 Ok(())
241 } else {
242 let content = resp.text().await?;
243 let entity: Option<DeleteRoutineError> = serde_json::from_str(&content).ok();
244 Err(Error::ResponseError(ResponseContent { status, content, entity }))
245 }
246}
247
248pub async fn get_routine(configuration: &configuration::Configuration, id: &str) -> Result<models::Routine, Error<GetRoutineError>> {
249 let p_path_id = id;
251
252 let uri_str = format!("{}/v1/routines/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
253 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
254
255 if let Some(ref user_agent) = configuration.user_agent {
256 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
257 }
258 if let Some(ref token) = configuration.bearer_access_token {
259 req_builder = req_builder.bearer_auth(token.to_owned());
260 };
261
262 let req = req_builder.build()?;
263 let resp = configuration.client.execute(req).await?;
264
265 let status = resp.status();
266 let content_type = resp
267 .headers()
268 .get("content-type")
269 .and_then(|v| v.to_str().ok())
270 .unwrap_or("application/octet-stream");
271 let content_type = super::ContentType::from(content_type);
272
273 if !status.is_client_error() && !status.is_server_error() {
274 let content = resp.text().await?;
275 match content_type {
276 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
277 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Routine`"))),
278 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::Routine`")))),
279 }
280 } else {
281 let content = resp.text().await?;
282 let entity: Option<GetRoutineError> = serde_json::from_str(&content).ok();
283 Err(Error::ResponseError(ResponseContent { status, content, entity }))
284 }
285}
286
287pub async fn list_routine_runs(configuration: &configuration::Configuration, id: &str) -> Result<models::RoutineRunListResponse, Error<ListRoutineRunsError>> {
288 let p_path_id = id;
290
291 let uri_str = format!("{}/v1/routines/{id}/runs", configuration.base_path, id=crate::apis::urlencode(p_path_id));
292 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
293
294 if let Some(ref user_agent) = configuration.user_agent {
295 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
296 }
297 if let Some(ref token) = configuration.bearer_access_token {
298 req_builder = req_builder.bearer_auth(token.to_owned());
299 };
300
301 let req = req_builder.build()?;
302 let resp = configuration.client.execute(req).await?;
303
304 let status = resp.status();
305 let content_type = resp
306 .headers()
307 .get("content-type")
308 .and_then(|v| v.to_str().ok())
309 .unwrap_or("application/octet-stream");
310 let content_type = super::ContentType::from(content_type);
311
312 if !status.is_client_error() && !status.is_server_error() {
313 let content = resp.text().await?;
314 match content_type {
315 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
316 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RoutineRunListResponse`"))),
317 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::RoutineRunListResponse`")))),
318 }
319 } else {
320 let content = resp.text().await?;
321 let entity: Option<ListRoutineRunsError> = serde_json::from_str(&content).ok();
322 Err(Error::ResponseError(ResponseContent { status, content, entity }))
323 }
324}
325
326pub async fn list_routines(configuration: &configuration::Configuration, workspace_id: Option<&str>, status: Option<&str>) -> Result<models::RoutineListResponse, Error<ListRoutinesError>> {
327 let p_query_workspace_id = workspace_id;
329 let p_query_status = status;
330
331 let uri_str = format!("{}/v1/routines", configuration.base_path);
332 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
333
334 if let Some(ref param_value) = p_query_workspace_id {
335 req_builder = req_builder.query(&[("workspaceId", ¶m_value.to_string())]);
336 }
337 if let Some(ref param_value) = p_query_status {
338 req_builder = req_builder.query(&[("status", ¶m_value.to_string())]);
339 }
340 if let Some(ref user_agent) = configuration.user_agent {
341 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
342 }
343 if let Some(ref token) = configuration.bearer_access_token {
344 req_builder = req_builder.bearer_auth(token.to_owned());
345 };
346
347 let req = req_builder.build()?;
348 let resp = configuration.client.execute(req).await?;
349
350 let status = resp.status();
351 let content_type = resp
352 .headers()
353 .get("content-type")
354 .and_then(|v| v.to_str().ok())
355 .unwrap_or("application/octet-stream");
356 let content_type = super::ContentType::from(content_type);
357
358 if !status.is_client_error() && !status.is_server_error() {
359 let content = resp.text().await?;
360 match content_type {
361 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
362 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RoutineListResponse`"))),
363 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::RoutineListResponse`")))),
364 }
365 } else {
366 let content = resp.text().await?;
367 let entity: Option<ListRoutinesError> = serde_json::from_str(&content).ok();
368 Err(Error::ResponseError(ResponseContent { status, content, entity }))
369 }
370}
371
372pub async fn run_routine_now(configuration: &configuration::Configuration, id: &str) -> Result<models::RoutineRun, Error<RunRoutineNowError>> {
373 let p_path_id = id;
375
376 let uri_str = format!("{}/v1/routines/{id}/run-now", configuration.base_path, id=crate::apis::urlencode(p_path_id));
377 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
378
379 if let Some(ref user_agent) = configuration.user_agent {
380 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
381 }
382 if let Some(ref token) = configuration.bearer_access_token {
383 req_builder = req_builder.bearer_auth(token.to_owned());
384 };
385
386 let req = req_builder.build()?;
387 let resp = configuration.client.execute(req).await?;
388
389 let status = resp.status();
390 let content_type = resp
391 .headers()
392 .get("content-type")
393 .and_then(|v| v.to_str().ok())
394 .unwrap_or("application/octet-stream");
395 let content_type = super::ContentType::from(content_type);
396
397 if !status.is_client_error() && !status.is_server_error() {
398 let content = resp.text().await?;
399 match content_type {
400 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
401 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RoutineRun`"))),
402 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::RoutineRun`")))),
403 }
404 } else {
405 let content = resp.text().await?;
406 let entity: Option<RunRoutineNowError> = serde_json::from_str(&content).ok();
407 Err(Error::ResponseError(ResponseContent { status, content, entity }))
408 }
409}
410
411pub async fn update_routine(configuration: &configuration::Configuration, id: &str, update_routine_request: models::UpdateRoutineRequest) -> Result<models::Routine, Error<UpdateRoutineError>> {
412 let p_path_id = id;
414 let p_body_update_routine_request = update_routine_request;
415
416 let uri_str = format!("{}/v1/routines/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
417 let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
418
419 if let Some(ref user_agent) = configuration.user_agent {
420 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
421 }
422 if let Some(ref token) = configuration.bearer_access_token {
423 req_builder = req_builder.bearer_auth(token.to_owned());
424 };
425 req_builder = req_builder.json(&p_body_update_routine_request);
426
427 let req = req_builder.build()?;
428 let resp = configuration.client.execute(req).await?;
429
430 let status = resp.status();
431 let content_type = resp
432 .headers()
433 .get("content-type")
434 .and_then(|v| v.to_str().ok())
435 .unwrap_or("application/octet-stream");
436 let content_type = super::ContentType::from(content_type);
437
438 if !status.is_client_error() && !status.is_server_error() {
439 let content = resp.text().await?;
440 match content_type {
441 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
442 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Routine`"))),
443 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::Routine`")))),
444 }
445 } else {
446 let content = resp.text().await?;
447 let entity: Option<UpdateRoutineError> = serde_json::from_str(&content).ok();
448 Err(Error::ResponseError(ResponseContent { status, content, entity }))
449 }
450}
451
452pub async fn update_routine_run_progress(configuration: &configuration::Configuration, id: &str, routine_run_progress_request: models::RoutineRunProgressRequest) -> Result<models::RoutineRun, Error<UpdateRoutineRunProgressError>> {
453 let p_path_id = id;
455 let p_body_routine_run_progress_request = routine_run_progress_request;
456
457 let uri_str = format!("{}/v1/routines/runs/{id}/progress", configuration.base_path, id=crate::apis::urlencode(p_path_id));
458 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
459
460 if let Some(ref user_agent) = configuration.user_agent {
461 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
462 }
463 if let Some(ref token) = configuration.bearer_access_token {
464 req_builder = req_builder.bearer_auth(token.to_owned());
465 };
466 req_builder = req_builder.json(&p_body_routine_run_progress_request);
467
468 let req = req_builder.build()?;
469 let resp = configuration.client.execute(req).await?;
470
471 let status = resp.status();
472 let content_type = resp
473 .headers()
474 .get("content-type")
475 .and_then(|v| v.to_str().ok())
476 .unwrap_or("application/octet-stream");
477 let content_type = super::ContentType::from(content_type);
478
479 if !status.is_client_error() && !status.is_server_error() {
480 let content = resp.text().await?;
481 match content_type {
482 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
483 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RoutineRun`"))),
484 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::RoutineRun`")))),
485 }
486 } else {
487 let content = resp.text().await?;
488 let entity: Option<UpdateRoutineRunProgressError> = serde_json::from_str(&content).ok();
489 Err(Error::ResponseError(ResponseContent { status, content, entity }))
490 }
491}
492