sonarr_api_rs/apis/
queue_details_api.rs

1/*
2 * Sonarr
3 *
4 * Sonarr API docs - The v3 API docs apply to both v3 and v4 versions of Sonarr. Some functionality may only be available in v4 of the Sonarr application.
5 *
6 * The version of the OpenAPI document: 3.0.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`api_v3_queue_details_get`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ApiV3QueueDetailsGetError {
22    UnknownValue(serde_json::Value),
23}
24
25
26pub async fn api_v3_queue_details_get(configuration: &configuration::Configuration, series_id: Option<i32>, episode_ids: Option<Vec<i32>>, include_series: Option<bool>, include_episode: Option<bool>) -> Result<Vec<models::QueueResource>, Error<ApiV3QueueDetailsGetError>> {
27    let local_var_configuration = configuration;
28
29    let local_var_client = &local_var_configuration.client;
30
31    let local_var_uri_str = format!("{}/api/v3/queue/details", local_var_configuration.base_path);
32    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
33
34    if let Some(ref local_var_str) = series_id {
35        local_var_req_builder = local_var_req_builder.query(&[("seriesId", &local_var_str.to_string())]);
36    }
37    if let Some(ref local_var_str) = episode_ids {
38        local_var_req_builder = match "multi" {
39            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("episodeIds".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
40            _ => local_var_req_builder.query(&[("episodeIds", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
41        };
42    }
43    if let Some(ref local_var_str) = include_series {
44        local_var_req_builder = local_var_req_builder.query(&[("includeSeries", &local_var_str.to_string())]);
45    }
46    if let Some(ref local_var_str) = include_episode {
47        local_var_req_builder = local_var_req_builder.query(&[("includeEpisode", &local_var_str.to_string())]);
48    }
49    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
50        let local_var_key = local_var_apikey.key.clone();
51        let local_var_value = match local_var_apikey.prefix {
52            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
53            None => local_var_key,
54        };
55        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
56    }
57    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
58        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
59    }
60    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
61        let local_var_key = local_var_apikey.key.clone();
62        let local_var_value = match local_var_apikey.prefix {
63            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
64            None => local_var_key,
65        };
66        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
67    };
68
69    let local_var_req = local_var_req_builder.build()?;
70    let local_var_resp = local_var_client.execute(local_var_req).await?;
71
72    let local_var_status = local_var_resp.status();
73    let local_var_content = local_var_resp.text().await?;
74
75    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
76        serde_json::from_str(&local_var_content).map_err(Error::from)
77    } else {
78        let local_var_entity: Option<ApiV3QueueDetailsGetError> = serde_json::from_str(&local_var_content).ok();
79        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
80        Err(Error::ResponseError(local_var_error))
81    }
82}
83