sonarr_api_rs/apis/
manual_import_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_manualimport_get`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ApiV3ManualimportGetError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`api_v3_manualimport_post`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum ApiV3ManualimportPostError {
29    UnknownValue(serde_json::Value),
30}
31
32
33pub async fn api_v3_manualimport_get(configuration: &configuration::Configuration, folder: Option<&str>, download_id: Option<&str>, series_id: Option<i32>, season_number: Option<i32>, filter_existing_files: Option<bool>) -> Result<Vec<models::ManualImportResource>, Error<ApiV3ManualimportGetError>> {
34    let local_var_configuration = configuration;
35
36    let local_var_client = &local_var_configuration.client;
37
38    let local_var_uri_str = format!("{}/api/v3/manualimport", local_var_configuration.base_path);
39    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
40
41    if let Some(ref local_var_str) = folder {
42        local_var_req_builder = local_var_req_builder.query(&[("folder", &local_var_str.to_string())]);
43    }
44    if let Some(ref local_var_str) = download_id {
45        local_var_req_builder = local_var_req_builder.query(&[("downloadId", &local_var_str.to_string())]);
46    }
47    if let Some(ref local_var_str) = series_id {
48        local_var_req_builder = local_var_req_builder.query(&[("seriesId", &local_var_str.to_string())]);
49    }
50    if let Some(ref local_var_str) = season_number {
51        local_var_req_builder = local_var_req_builder.query(&[("seasonNumber", &local_var_str.to_string())]);
52    }
53    if let Some(ref local_var_str) = filter_existing_files {
54        local_var_req_builder = local_var_req_builder.query(&[("filterExistingFiles", &local_var_str.to_string())]);
55    }
56    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
57        let local_var_key = local_var_apikey.key.clone();
58        let local_var_value = match local_var_apikey.prefix {
59            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
60            None => local_var_key,
61        };
62        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
63    }
64    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
65        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
66    }
67    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
68        let local_var_key = local_var_apikey.key.clone();
69        let local_var_value = match local_var_apikey.prefix {
70            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
71            None => local_var_key,
72        };
73        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
74    };
75
76    let local_var_req = local_var_req_builder.build()?;
77    let local_var_resp = local_var_client.execute(local_var_req).await?;
78
79    let local_var_status = local_var_resp.status();
80    let local_var_content = local_var_resp.text().await?;
81
82    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
83        serde_json::from_str(&local_var_content).map_err(Error::from)
84    } else {
85        let local_var_entity: Option<ApiV3ManualimportGetError> = serde_json::from_str(&local_var_content).ok();
86        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
87        Err(Error::ResponseError(local_var_error))
88    }
89}
90
91pub async fn api_v3_manualimport_post(configuration: &configuration::Configuration, manual_import_reprocess_resource: Option<Vec<models::ManualImportReprocessResource>>) -> Result<(), Error<ApiV3ManualimportPostError>> {
92    let local_var_configuration = configuration;
93
94    let local_var_client = &local_var_configuration.client;
95
96    let local_var_uri_str = format!("{}/api/v3/manualimport", local_var_configuration.base_path);
97    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
98
99    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
100        let local_var_key = local_var_apikey.key.clone();
101        let local_var_value = match local_var_apikey.prefix {
102            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
103            None => local_var_key,
104        };
105        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
106    }
107    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
108        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
109    }
110    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
111        let local_var_key = local_var_apikey.key.clone();
112        let local_var_value = match local_var_apikey.prefix {
113            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
114            None => local_var_key,
115        };
116        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
117    };
118    local_var_req_builder = local_var_req_builder.json(&manual_import_reprocess_resource);
119
120    let local_var_req = local_var_req_builder.build()?;
121    let local_var_resp = local_var_client.execute(local_var_req).await?;
122
123    let local_var_status = local_var_resp.status();
124    let local_var_content = local_var_resp.text().await?;
125
126    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
127        Ok(())
128    } else {
129        let local_var_entity: Option<ApiV3ManualimportPostError> = serde_json::from_str(&local_var_content).ok();
130        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
131        Err(Error::ResponseError(local_var_error))
132    }
133}
134