lidarr/apis/
task_api.rs

1/*
2 * Lidarr
3 *
4 * Lidarr API docs
5 *
6 * The version of the OpenAPI document: v2.13.3.4711
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`get_system_task_by_id`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetSystemTaskByIdError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`list_system_task`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum ListSystemTaskError {
29    UnknownValue(serde_json::Value),
30}
31
32
33pub async fn get_system_task_by_id(configuration: &configuration::Configuration, id: i32) -> Result<models::TaskResource, Error<GetSystemTaskByIdError>> {
34    // add a prefix to parameters to efficiently prevent name collisions
35    let p_path_id = id;
36
37    let uri_str = format!("{}/api/v1/system/task/{id}", configuration.base_path, id=p_path_id);
38    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
39
40    if let Some(ref apikey) = configuration.api_key {
41        let key = apikey.key.clone();
42        let value = match apikey.prefix {
43            Some(ref prefix) => format!("{} {}", prefix, key),
44            None => key,
45        };
46        req_builder = req_builder.query(&[("apikey", value)]);
47    }
48    if let Some(ref user_agent) = configuration.user_agent {
49        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
50    }
51    if let Some(ref apikey) = configuration.api_key {
52        let key = apikey.key.clone();
53        let value = match apikey.prefix {
54            Some(ref prefix) => format!("{} {}", prefix, key),
55            None => key,
56        };
57        req_builder = req_builder.header("X-Api-Key", value);
58    };
59
60    let req = req_builder.build()?;
61    let resp = configuration.client.execute(req).await?;
62
63    let status = resp.status();
64    let content_type = resp
65        .headers()
66        .get("content-type")
67        .and_then(|v| v.to_str().ok())
68        .unwrap_or("application/octet-stream");
69    let content_type = super::ContentType::from(content_type);
70
71    if !status.is_client_error() && !status.is_server_error() {
72        let content = resp.text().await?;
73        match content_type {
74            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
75            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TaskResource`"))),
76            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::TaskResource`")))),
77        }
78    } else {
79        let content = resp.text().await?;
80        let entity: Option<GetSystemTaskByIdError> = serde_json::from_str(&content).ok();
81        Err(Error::ResponseError(ResponseContent { status, content, entity }))
82    }
83}
84
85pub async fn list_system_task(configuration: &configuration::Configuration, ) -> Result<Vec<models::TaskResource>, Error<ListSystemTaskError>> {
86
87    let uri_str = format!("{}/api/v1/system/task", configuration.base_path);
88    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
89
90    if let Some(ref apikey) = configuration.api_key {
91        let key = apikey.key.clone();
92        let value = match apikey.prefix {
93            Some(ref prefix) => format!("{} {}", prefix, key),
94            None => key,
95        };
96        req_builder = req_builder.query(&[("apikey", value)]);
97    }
98    if let Some(ref user_agent) = configuration.user_agent {
99        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
100    }
101    if let Some(ref apikey) = configuration.api_key {
102        let key = apikey.key.clone();
103        let value = match apikey.prefix {
104            Some(ref prefix) => format!("{} {}", prefix, key),
105            None => key,
106        };
107        req_builder = req_builder.header("X-Api-Key", value);
108    };
109
110    let req = req_builder.build()?;
111    let resp = configuration.client.execute(req).await?;
112
113    let status = resp.status();
114    let content_type = resp
115        .headers()
116        .get("content-type")
117        .and_then(|v| v.to_str().ok())
118        .unwrap_or("application/octet-stream");
119    let content_type = super::ContentType::from(content_type);
120
121    if !status.is_client_error() && !status.is_server_error() {
122        let content = resp.text().await?;
123        match content_type {
124            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
125            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::TaskResource&gt;`"))),
126            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::TaskResource&gt;`")))),
127        }
128    } else {
129        let content = resp.text().await?;
130        let entity: Option<ListSystemTaskError> = serde_json::from_str(&content).ok();
131        Err(Error::ResponseError(ResponseContent { status, content, entity }))
132    }
133}
134