radarr_api_rs/apis/
history_api.rs

1/*
2 * Radarr
3 *
4 * Radarr API docs
5 *
6 * The version of the OpenAPI document: 3.0.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use crate::models::{MovieHistoryEventType, SortDirection};
16use super::{Error, configuration};
17
18
19/// struct for typed errors of method [`api_v3_history_failed_id_post`]
20#[derive(Debug, Clone, Serialize, Deserialize)]
21#[serde(untagged)]
22pub enum ApiV3HistoryFailedIdPostError {
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`api_v3_history_get`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum ApiV3HistoryGetError {
30    UnknownValue(serde_json::Value),
31}
32
33/// struct for typed errors of method [`api_v3_history_movie_get`]
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum ApiV3HistoryMovieGetError {
37    UnknownValue(serde_json::Value),
38}
39
40/// struct for typed errors of method [`api_v3_history_since_get`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum ApiV3HistorySinceGetError {
44    UnknownValue(serde_json::Value),
45}
46
47
48pub async fn api_v3_history_failed_id_post(configuration: &configuration::Configuration, id: i32) -> Result<(), Error<ApiV3HistoryFailedIdPostError>> {
49    let local_var_configuration = configuration;
50
51    let local_var_client = &local_var_configuration.client;
52
53    let local_var_uri_str = format!("{}/api/v3/history/failed/{id}", local_var_configuration.base_path, id=id);
54    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
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        Ok(())
84    } else {
85        let local_var_entity: Option<ApiV3HistoryFailedIdPostError> = 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_history_get(configuration: &configuration::Configuration, page: Option<i32>, page_size: Option<i32>, sort_key: Option<&str>, sort_direction: Option<SortDirection>, include_movie: Option<bool>, event_type: Option<i32>, download_id: Option<&str>, movie_ids: Option<Vec<i32>>, languages: Option<Vec<i32>>, quality: Option<Vec<i32>>) -> Result<crate::models::HistoryResourcePagingResource, Error<ApiV3HistoryGetError>> {
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/history", local_var_configuration.base_path);
97    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
98
99    if let Some(ref local_var_str) = page {
100        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
101    }
102    if let Some(ref local_var_str) = page_size {
103        local_var_req_builder = local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
104    }
105    if let Some(ref local_var_str) = sort_key {
106        local_var_req_builder = local_var_req_builder.query(&[("sortKey", &local_var_str.to_string())]);
107    }
108    if let Some(ref local_var_str) = sort_direction {
109        local_var_req_builder = local_var_req_builder.query(&[("sortDirection", &local_var_str.to_string())]);
110    }
111    if let Some(ref local_var_str) = include_movie {
112        local_var_req_builder = local_var_req_builder.query(&[("includeMovie", &local_var_str.to_string())]);
113    }
114    if let Some(ref local_var_str) = event_type {
115        local_var_req_builder = local_var_req_builder.query(&[("eventType", &local_var_str.to_string())]);
116    }
117    if let Some(ref local_var_str) = download_id {
118        local_var_req_builder = local_var_req_builder.query(&[("downloadId", &local_var_str.to_string())]);
119    }
120    if let Some(ref local_var_str) = movie_ids {
121        local_var_req_builder = match "multi" {
122            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("movieIds".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
123            _ => local_var_req_builder.query(&[("movieIds", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
124        };
125    }
126    if let Some(ref local_var_str) = languages {
127        local_var_req_builder = match "multi" {
128            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("languages".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
129            _ => local_var_req_builder.query(&[("languages", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
130        };
131    }
132    if let Some(ref local_var_str) = quality {
133        local_var_req_builder = match "multi" {
134            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("quality".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
135            _ => local_var_req_builder.query(&[("quality", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
136        };
137    }
138    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
139        let local_var_key = local_var_apikey.key.clone();
140        let local_var_value = match local_var_apikey.prefix {
141            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
142            None => local_var_key,
143        };
144        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
145    }
146    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
147        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
148    }
149    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
150        let local_var_key = local_var_apikey.key.clone();
151        let local_var_value = match local_var_apikey.prefix {
152            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
153            None => local_var_key,
154        };
155        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
156    };
157
158    let local_var_req = local_var_req_builder.build()?;
159    let local_var_resp = local_var_client.execute(local_var_req).await?;
160
161    let local_var_status = local_var_resp.status();
162    let local_var_content = local_var_resp.text().await?;
163
164    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
165        serde_json::from_str(&local_var_content).map_err(Error::from)
166    } else {
167        let local_var_entity: Option<ApiV3HistoryGetError> = serde_json::from_str(&local_var_content).ok();
168        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
169        Err(Error::ResponseError(local_var_error))
170    }
171}
172
173pub async fn api_v3_history_movie_get(configuration: &configuration::Configuration, movie_id: Option<i32>, event_type: Option<MovieHistoryEventType>, include_movie: Option<bool>) -> Result<Vec<crate::models::HistoryResource>, Error<ApiV3HistoryMovieGetError>> {
174    let local_var_configuration = configuration;
175
176    let local_var_client = &local_var_configuration.client;
177
178    let local_var_uri_str = format!("{}/api/v3/history/movie", local_var_configuration.base_path);
179    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
180
181    if let Some(ref local_var_str) = movie_id {
182        local_var_req_builder = local_var_req_builder.query(&[("movieId", &local_var_str.to_string())]);
183    }
184    if let Some(ref local_var_str) = event_type {
185        local_var_req_builder = local_var_req_builder.query(&[("eventType", &local_var_str.to_string())]);
186    }
187    if let Some(ref local_var_str) = include_movie {
188        local_var_req_builder = local_var_req_builder.query(&[("includeMovie", &local_var_str.to_string())]);
189    }
190    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
191        let local_var_key = local_var_apikey.key.clone();
192        let local_var_value = match local_var_apikey.prefix {
193            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
194            None => local_var_key,
195        };
196        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
197    }
198    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
199        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
200    }
201    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
202        let local_var_key = local_var_apikey.key.clone();
203        let local_var_value = match local_var_apikey.prefix {
204            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
205            None => local_var_key,
206        };
207        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
208    };
209
210    let local_var_req = local_var_req_builder.build()?;
211    let local_var_resp = local_var_client.execute(local_var_req).await?;
212
213    let local_var_status = local_var_resp.status();
214    let local_var_content = local_var_resp.text().await?;
215
216    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
217        serde_json::from_str(&local_var_content).map_err(Error::from)
218    } else {
219        let local_var_entity: Option<ApiV3HistoryMovieGetError> = serde_json::from_str(&local_var_content).ok();
220        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
221        Err(Error::ResponseError(local_var_error))
222    }
223}
224
225pub async fn api_v3_history_since_get(configuration: &configuration::Configuration, date: Option<String>, event_type: Option<MovieHistoryEventType>, include_movie: Option<bool>) -> Result<Vec<crate::models::HistoryResource>, Error<ApiV3HistorySinceGetError>> {
226    let local_var_configuration = configuration;
227
228    let local_var_client = &local_var_configuration.client;
229
230    let local_var_uri_str = format!("{}/api/v3/history/since", local_var_configuration.base_path);
231    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
232
233    if let Some(ref local_var_str) = date {
234        local_var_req_builder = local_var_req_builder.query(&[("date", &local_var_str.to_string())]);
235    }
236    if let Some(ref local_var_str) = event_type {
237        local_var_req_builder = local_var_req_builder.query(&[("eventType", &local_var_str.to_string())]);
238    }
239    if let Some(ref local_var_str) = include_movie {
240        local_var_req_builder = local_var_req_builder.query(&[("includeMovie", &local_var_str.to_string())]);
241    }
242    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
243        let local_var_key = local_var_apikey.key.clone();
244        let local_var_value = match local_var_apikey.prefix {
245            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
246            None => local_var_key,
247        };
248        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
249    }
250    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
251        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
252    }
253    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
254        let local_var_key = local_var_apikey.key.clone();
255        let local_var_value = match local_var_apikey.prefix {
256            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
257            None => local_var_key,
258        };
259        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
260    };
261
262    let local_var_req = local_var_req_builder.build()?;
263    let local_var_resp = local_var_client.execute(local_var_req).await?;
264
265    let local_var_status = local_var_resp.status();
266    let local_var_content = local_var_resp.text().await?;
267
268    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
269        serde_json::from_str(&local_var_content).map_err(Error::from)
270    } else {
271        let local_var_entity: Option<ApiV3HistorySinceGetError> = serde_json::from_str(&local_var_content).ok();
272        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
273        Err(Error::ResponseError(local_var_error))
274    }
275}
276