sonarr_api_rs/apis/
cutoff_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_wanted_cutoff_get`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ApiV3WantedCutoffGetError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`api_v3_wanted_cutoff_id_get`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum ApiV3WantedCutoffIdGetError {
29    UnknownValue(serde_json::Value),
30}
31
32
33pub async fn api_v3_wanted_cutoff_get(configuration: &configuration::Configuration, page: Option<i32>, page_size: Option<i32>, sort_key: Option<&str>, sort_direction: Option<models::SortDirection>, include_series: Option<bool>, include_episode_file: Option<bool>, include_images: Option<bool>, monitored: Option<bool>) -> Result<models::EpisodeResourcePagingResource, Error<ApiV3WantedCutoffGetError>> {
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/wanted/cutoff", 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) = page {
42        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
43    }
44    if let Some(ref local_var_str) = page_size {
45        local_var_req_builder = local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
46    }
47    if let Some(ref local_var_str) = sort_key {
48        local_var_req_builder = local_var_req_builder.query(&[("sortKey", &local_var_str.to_string())]);
49    }
50    if let Some(ref local_var_str) = sort_direction {
51        local_var_req_builder = local_var_req_builder.query(&[("sortDirection", &local_var_str.to_string())]);
52    }
53    if let Some(ref local_var_str) = include_series {
54        local_var_req_builder = local_var_req_builder.query(&[("includeSeries", &local_var_str.to_string())]);
55    }
56    if let Some(ref local_var_str) = include_episode_file {
57        local_var_req_builder = local_var_req_builder.query(&[("includeEpisodeFile", &local_var_str.to_string())]);
58    }
59    if let Some(ref local_var_str) = include_images {
60        local_var_req_builder = local_var_req_builder.query(&[("includeImages", &local_var_str.to_string())]);
61    }
62    if let Some(ref local_var_str) = monitored {
63        local_var_req_builder = local_var_req_builder.query(&[("monitored", &local_var_str.to_string())]);
64    }
65    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
66        let local_var_key = local_var_apikey.key.clone();
67        let local_var_value = match local_var_apikey.prefix {
68            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
69            None => local_var_key,
70        };
71        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
72    }
73    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
74        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
75    }
76    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
77        let local_var_key = local_var_apikey.key.clone();
78        let local_var_value = match local_var_apikey.prefix {
79            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
80            None => local_var_key,
81        };
82        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
83    };
84
85    let local_var_req = local_var_req_builder.build()?;
86    let local_var_resp = local_var_client.execute(local_var_req).await?;
87
88    let local_var_status = local_var_resp.status();
89    let local_var_content = local_var_resp.text().await?;
90
91    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
92        serde_json::from_str(&local_var_content).map_err(Error::from)
93    } else {
94        let local_var_entity: Option<ApiV3WantedCutoffGetError> = serde_json::from_str(&local_var_content).ok();
95        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
96        Err(Error::ResponseError(local_var_error))
97    }
98}
99
100pub async fn api_v3_wanted_cutoff_id_get(configuration: &configuration::Configuration, id: i32) -> Result<models::EpisodeResource, Error<ApiV3WantedCutoffIdGetError>> {
101    let local_var_configuration = configuration;
102
103    let local_var_client = &local_var_configuration.client;
104
105    let local_var_uri_str = format!("{}/api/v3/wanted/cutoff/{id}", local_var_configuration.base_path, id=id);
106    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
107
108    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
109        let local_var_key = local_var_apikey.key.clone();
110        let local_var_value = match local_var_apikey.prefix {
111            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
112            None => local_var_key,
113        };
114        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
115    }
116    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
117        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
118    }
119    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
120        let local_var_key = local_var_apikey.key.clone();
121        let local_var_value = match local_var_apikey.prefix {
122            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
123            None => local_var_key,
124        };
125        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
126    };
127
128    let local_var_req = local_var_req_builder.build()?;
129    let local_var_resp = local_var_client.execute(local_var_req).await?;
130
131    let local_var_status = local_var_resp.status();
132    let local_var_content = local_var_resp.text().await?;
133
134    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
135        serde_json::from_str(&local_var_content).map_err(Error::from)
136    } else {
137        let local_var_entity: Option<ApiV3WantedCutoffIdGetError> = serde_json::from_str(&local_var_content).ok();
138        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
139        Err(Error::ResponseError(local_var_error))
140    }
141}
142