lidarr/apis/
system_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 [`create_system_restart`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateSystemRestartError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`create_system_shutdown`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum CreateSystemShutdownError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_system_routes`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetSystemRoutesError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_system_routes_duplicate`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetSystemRoutesDuplicateError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`get_system_status`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetSystemStatusError {
50    UnknownValue(serde_json::Value),
51}
52
53
54pub async fn create_system_restart(configuration: &configuration::Configuration, ) -> Result<(), Error<CreateSystemRestartError>> {
55
56    let uri_str = format!("{}/api/v1/system/restart", configuration.base_path);
57    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
58
59    if let Some(ref apikey) = configuration.api_key {
60        let key = apikey.key.clone();
61        let value = match apikey.prefix {
62            Some(ref prefix) => format!("{} {}", prefix, key),
63            None => key,
64        };
65        req_builder = req_builder.query(&[("apikey", value)]);
66    }
67    if let Some(ref user_agent) = configuration.user_agent {
68        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
69    }
70    if let Some(ref apikey) = configuration.api_key {
71        let key = apikey.key.clone();
72        let value = match apikey.prefix {
73            Some(ref prefix) => format!("{} {}", prefix, key),
74            None => key,
75        };
76        req_builder = req_builder.header("X-Api-Key", value);
77    };
78
79    let req = req_builder.build()?;
80    let resp = configuration.client.execute(req).await?;
81
82    let status = resp.status();
83
84    if !status.is_client_error() && !status.is_server_error() {
85        Ok(())
86    } else {
87        let content = resp.text().await?;
88        let entity: Option<CreateSystemRestartError> = serde_json::from_str(&content).ok();
89        Err(Error::ResponseError(ResponseContent { status, content, entity }))
90    }
91}
92
93pub async fn create_system_shutdown(configuration: &configuration::Configuration, ) -> Result<(), Error<CreateSystemShutdownError>> {
94
95    let uri_str = format!("{}/api/v1/system/shutdown", configuration.base_path);
96    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
97
98    if let Some(ref apikey) = configuration.api_key {
99        let key = apikey.key.clone();
100        let value = match apikey.prefix {
101            Some(ref prefix) => format!("{} {}", prefix, key),
102            None => key,
103        };
104        req_builder = req_builder.query(&[("apikey", value)]);
105    }
106    if let Some(ref user_agent) = configuration.user_agent {
107        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
108    }
109    if let Some(ref apikey) = configuration.api_key {
110        let key = apikey.key.clone();
111        let value = match apikey.prefix {
112            Some(ref prefix) => format!("{} {}", prefix, key),
113            None => key,
114        };
115        req_builder = req_builder.header("X-Api-Key", value);
116    };
117
118    let req = req_builder.build()?;
119    let resp = configuration.client.execute(req).await?;
120
121    let status = resp.status();
122
123    if !status.is_client_error() && !status.is_server_error() {
124        Ok(())
125    } else {
126        let content = resp.text().await?;
127        let entity: Option<CreateSystemShutdownError> = serde_json::from_str(&content).ok();
128        Err(Error::ResponseError(ResponseContent { status, content, entity }))
129    }
130}
131
132pub async fn get_system_routes(configuration: &configuration::Configuration, ) -> Result<(), Error<GetSystemRoutesError>> {
133
134    let uri_str = format!("{}/api/v1/system/routes", configuration.base_path);
135    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
136
137    if let Some(ref apikey) = configuration.api_key {
138        let key = apikey.key.clone();
139        let value = match apikey.prefix {
140            Some(ref prefix) => format!("{} {}", prefix, key),
141            None => key,
142        };
143        req_builder = req_builder.query(&[("apikey", value)]);
144    }
145    if let Some(ref user_agent) = configuration.user_agent {
146        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
147    }
148    if let Some(ref apikey) = configuration.api_key {
149        let key = apikey.key.clone();
150        let value = match apikey.prefix {
151            Some(ref prefix) => format!("{} {}", prefix, key),
152            None => key,
153        };
154        req_builder = req_builder.header("X-Api-Key", value);
155    };
156
157    let req = req_builder.build()?;
158    let resp = configuration.client.execute(req).await?;
159
160    let status = resp.status();
161
162    if !status.is_client_error() && !status.is_server_error() {
163        Ok(())
164    } else {
165        let content = resp.text().await?;
166        let entity: Option<GetSystemRoutesError> = serde_json::from_str(&content).ok();
167        Err(Error::ResponseError(ResponseContent { status, content, entity }))
168    }
169}
170
171pub async fn get_system_routes_duplicate(configuration: &configuration::Configuration, ) -> Result<(), Error<GetSystemRoutesDuplicateError>> {
172
173    let uri_str = format!("{}/api/v1/system/routes/duplicate", configuration.base_path);
174    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
175
176    if let Some(ref apikey) = configuration.api_key {
177        let key = apikey.key.clone();
178        let value = match apikey.prefix {
179            Some(ref prefix) => format!("{} {}", prefix, key),
180            None => key,
181        };
182        req_builder = req_builder.query(&[("apikey", value)]);
183    }
184    if let Some(ref user_agent) = configuration.user_agent {
185        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
186    }
187    if let Some(ref apikey) = configuration.api_key {
188        let key = apikey.key.clone();
189        let value = match apikey.prefix {
190            Some(ref prefix) => format!("{} {}", prefix, key),
191            None => key,
192        };
193        req_builder = req_builder.header("X-Api-Key", value);
194    };
195
196    let req = req_builder.build()?;
197    let resp = configuration.client.execute(req).await?;
198
199    let status = resp.status();
200
201    if !status.is_client_error() && !status.is_server_error() {
202        Ok(())
203    } else {
204        let content = resp.text().await?;
205        let entity: Option<GetSystemRoutesDuplicateError> = serde_json::from_str(&content).ok();
206        Err(Error::ResponseError(ResponseContent { status, content, entity }))
207    }
208}
209
210pub async fn get_system_status(configuration: &configuration::Configuration, ) -> Result<models::SystemResource, Error<GetSystemStatusError>> {
211
212    let uri_str = format!("{}/api/v1/system/status", configuration.base_path);
213    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
214
215    if let Some(ref apikey) = configuration.api_key {
216        let key = apikey.key.clone();
217        let value = match apikey.prefix {
218            Some(ref prefix) => format!("{} {}", prefix, key),
219            None => key,
220        };
221        req_builder = req_builder.query(&[("apikey", value)]);
222    }
223    if let Some(ref user_agent) = configuration.user_agent {
224        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
225    }
226    if let Some(ref apikey) = configuration.api_key {
227        let key = apikey.key.clone();
228        let value = match apikey.prefix {
229            Some(ref prefix) => format!("{} {}", prefix, key),
230            None => key,
231        };
232        req_builder = req_builder.header("X-Api-Key", value);
233    };
234
235    let req = req_builder.build()?;
236    let resp = configuration.client.execute(req).await?;
237
238    let status = resp.status();
239    let content_type = resp
240        .headers()
241        .get("content-type")
242        .and_then(|v| v.to_str().ok())
243        .unwrap_or("application/octet-stream");
244    let content_type = super::ContentType::from(content_type);
245
246    if !status.is_client_error() && !status.is_server_error() {
247        let content = resp.text().await?;
248        match content_type {
249            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
250            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SystemResource`"))),
251            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::SystemResource`")))),
252        }
253    } else {
254        let content = resp.text().await?;
255        let entity: Option<GetSystemStatusError> = serde_json::from_str(&content).ok();
256        Err(Error::ResponseError(ResponseContent { status, content, entity }))
257    }
258}
259