radarr/apis/
update_api.rs

1/*
2 * Radarr
3 *
4 * Radarr API docs
5 *
6 * The version of the OpenAPI document: v5.27.5.10198
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 [`list_update`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ListUpdateError {
22    UnknownValue(serde_json::Value),
23}
24
25
26pub async fn list_update(configuration: &configuration::Configuration, ) -> Result<Vec<models::UpdateResource>, Error<ListUpdateError>> {
27
28    let uri_str = format!("{}/api/v3/update", configuration.base_path);
29    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
30
31    if let Some(ref apikey) = configuration.api_key {
32        let key = apikey.key.clone();
33        let value = match apikey.prefix {
34            Some(ref prefix) => format!("{} {}", prefix, key),
35            None => key,
36        };
37        req_builder = req_builder.query(&[("apikey", value)]);
38    }
39    if let Some(ref user_agent) = configuration.user_agent {
40        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
41    }
42    if let Some(ref apikey) = configuration.api_key {
43        let key = apikey.key.clone();
44        let value = match apikey.prefix {
45            Some(ref prefix) => format!("{} {}", prefix, key),
46            None => key,
47        };
48        req_builder = req_builder.header("X-Api-Key", value);
49    };
50
51    let req = req_builder.build()?;
52    let resp = configuration.client.execute(req).await?;
53
54    let status = resp.status();
55    let content_type = resp
56        .headers()
57        .get("content-type")
58        .and_then(|v| v.to_str().ok())
59        .unwrap_or("application/octet-stream");
60    let content_type = super::ContentType::from(content_type);
61
62    if !status.is_client_error() && !status.is_server_error() {
63        let content = resp.text().await?;
64        match content_type {
65            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
66            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::UpdateResource&gt;`"))),
67            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::UpdateResource&gt;`")))),
68        }
69    } else {
70        let content = resp.text().await?;
71        let entity: Option<ListUpdateError> = serde_json::from_str(&content).ok();
72        Err(Error::ResponseError(ResponseContent { status, content, entity }))
73    }
74}
75