readarr/apis/
queue_details_api.rs

1/*
2 * Readarr
3 *
4 * Readarr API docs
5 *
6 * The version of the OpenAPI document: v0.4.10.2734
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_queue_details`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ListQueueDetailsError {
22    UnknownValue(serde_json::Value),
23}
24
25
26pub async fn list_queue_details(configuration: &configuration::Configuration, author_id: Option<i32>, book_ids: Option<Vec<i32>>, include_author: Option<bool>, include_book: Option<bool>) -> Result<Vec<models::QueueResource>, Error<ListQueueDetailsError>> {
27    // add a prefix to parameters to efficiently prevent name collisions
28    let p_query_author_id = author_id;
29    let p_query_book_ids = book_ids;
30    let p_query_include_author = include_author;
31    let p_query_include_book = include_book;
32
33    let uri_str = format!("{}/api/v1/queue/details", configuration.base_path);
34    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
35
36    if let Some(ref param_value) = p_query_author_id {
37        req_builder = req_builder.query(&[("authorId", &param_value.to_string())]);
38    }
39    if let Some(ref param_value) = p_query_book_ids {
40        req_builder = match "multi" {
41            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("bookIds".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
42            _ => req_builder.query(&[("bookIds", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
43        };
44    }
45    if let Some(ref param_value) = p_query_include_author {
46        req_builder = req_builder.query(&[("includeAuthor", &param_value.to_string())]);
47    }
48    if let Some(ref param_value) = p_query_include_book {
49        req_builder = req_builder.query(&[("includeBook", &param_value.to_string())]);
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.query(&[("apikey", value)]);
58    }
59    if let Some(ref user_agent) = configuration.user_agent {
60        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
61    }
62    if let Some(ref apikey) = configuration.api_key {
63        let key = apikey.key.clone();
64        let value = match apikey.prefix {
65            Some(ref prefix) => format!("{} {}", prefix, key),
66            None => key,
67        };
68        req_builder = req_builder.header("X-Api-Key", value);
69    };
70
71    let req = req_builder.build()?;
72    let resp = configuration.client.execute(req).await?;
73
74    let status = resp.status();
75    let content_type = resp
76        .headers()
77        .get("content-type")
78        .and_then(|v| v.to_str().ok())
79        .unwrap_or("application/octet-stream");
80    let content_type = super::ContentType::from(content_type);
81
82    if !status.is_client_error() && !status.is_server_error() {
83        let content = resp.text().await?;
84        match content_type {
85            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
86            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::QueueResource&gt;`"))),
87            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::QueueResource&gt;`")))),
88        }
89    } else {
90        let content = resp.text().await?;
91        let entity: Option<ListQueueDetailsError> = serde_json::from_str(&content).ok();
92        Err(Error::ResponseError(ResponseContent { status, content, entity }))
93    }
94}
95