radarr/apis/
history_api.rs

1/*
2 * Radarr
3 *
4 * Radarr API docs
5 *
6 * The version of the OpenAPI document: v5.27.5.10198
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 [`create_history_failed_by_id`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateHistoryFailedByIdError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_history`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetHistoryError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`list_history_movie`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum ListHistoryMovieError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`list_history_since`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum ListHistorySinceError {
43    UnknownValue(serde_json::Value),
44}
45
46
47pub async fn create_history_failed_by_id(configuration: &configuration::Configuration, id: i32) -> Result<(), Error<CreateHistoryFailedByIdError>> {
48    // add a prefix to parameters to efficiently prevent name collisions
49    let p_path_id = id;
50
51    let uri_str = format!("{}/api/v3/history/failed/{id}", configuration.base_path, id=p_path_id);
52    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
53
54    if let Some(ref apikey) = configuration.api_key {
55        let key = apikey.key.clone();
56        let value = match apikey.prefix {
57            Some(ref prefix) => format!("{} {}", prefix, key),
58            None => key,
59        };
60        req_builder = req_builder.query(&[("apikey", value)]);
61    }
62    if let Some(ref user_agent) = configuration.user_agent {
63        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
64    }
65    if let Some(ref apikey) = configuration.api_key {
66        let key = apikey.key.clone();
67        let value = match apikey.prefix {
68            Some(ref prefix) => format!("{} {}", prefix, key),
69            None => key,
70        };
71        req_builder = req_builder.header("X-Api-Key", value);
72    };
73
74    let req = req_builder.build()?;
75    let resp = configuration.client.execute(req).await?;
76
77    let status = resp.status();
78
79    if !status.is_client_error() && !status.is_server_error() {
80        Ok(())
81    } else {
82        let content = resp.text().await?;
83        let entity: Option<CreateHistoryFailedByIdError> = serde_json::from_str(&content).ok();
84        Err(Error::ResponseError(ResponseContent { status, content, entity }))
85    }
86}
87
88pub async fn get_history(configuration: &configuration::Configuration, page: Option<i32>, page_size: Option<i32>, sort_key: Option<&str>, sort_direction: Option<models::SortDirection>, include_movie: Option<bool>, event_type: Option<Vec<i32>>, download_id: Option<&str>, movie_ids: Option<Vec<i32>>, languages: Option<Vec<i32>>, quality: Option<Vec<i32>>) -> Result<models::HistoryResourcePagingResource, Error<GetHistoryError>> {
89    // add a prefix to parameters to efficiently prevent name collisions
90    let p_query_page = page;
91    let p_query_page_size = page_size;
92    let p_query_sort_key = sort_key;
93    let p_query_sort_direction = sort_direction;
94    let p_query_include_movie = include_movie;
95    let p_query_event_type = event_type;
96    let p_query_download_id = download_id;
97    let p_query_movie_ids = movie_ids;
98    let p_query_languages = languages;
99    let p_query_quality = quality;
100
101    let uri_str = format!("{}/api/v3/history", configuration.base_path);
102    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
103
104    if let Some(ref param_value) = p_query_page {
105        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
106    }
107    if let Some(ref param_value) = p_query_page_size {
108        req_builder = req_builder.query(&[("pageSize", &param_value.to_string())]);
109    }
110    if let Some(ref param_value) = p_query_sort_key {
111        req_builder = req_builder.query(&[("sortKey", &param_value.to_string())]);
112    }
113    if let Some(ref param_value) = p_query_sort_direction {
114        req_builder = req_builder.query(&[("sortDirection", &param_value.to_string())]);
115    }
116    if let Some(ref param_value) = p_query_include_movie {
117        req_builder = req_builder.query(&[("includeMovie", &param_value.to_string())]);
118    }
119    if let Some(ref param_value) = p_query_event_type {
120        req_builder = match "multi" {
121            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("eventType".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
122            _ => req_builder.query(&[("eventType", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
123        };
124    }
125    if let Some(ref param_value) = p_query_download_id {
126        req_builder = req_builder.query(&[("downloadId", &param_value.to_string())]);
127    }
128    if let Some(ref param_value) = p_query_movie_ids {
129        req_builder = match "multi" {
130            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("movieIds".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
131            _ => req_builder.query(&[("movieIds", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
132        };
133    }
134    if let Some(ref param_value) = p_query_languages {
135        req_builder = match "multi" {
136            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("languages".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
137            _ => req_builder.query(&[("languages", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
138        };
139    }
140    if let Some(ref param_value) = p_query_quality {
141        req_builder = match "multi" {
142            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("quality".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
143            _ => req_builder.query(&[("quality", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
144        };
145    }
146    if let Some(ref apikey) = configuration.api_key {
147        let key = apikey.key.clone();
148        let value = match apikey.prefix {
149            Some(ref prefix) => format!("{} {}", prefix, key),
150            None => key,
151        };
152        req_builder = req_builder.query(&[("apikey", value)]);
153    }
154    if let Some(ref user_agent) = configuration.user_agent {
155        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
156    }
157    if let Some(ref apikey) = configuration.api_key {
158        let key = apikey.key.clone();
159        let value = match apikey.prefix {
160            Some(ref prefix) => format!("{} {}", prefix, key),
161            None => key,
162        };
163        req_builder = req_builder.header("X-Api-Key", value);
164    };
165
166    let req = req_builder.build()?;
167    let resp = configuration.client.execute(req).await?;
168
169    let status = resp.status();
170    let content_type = resp
171        .headers()
172        .get("content-type")
173        .and_then(|v| v.to_str().ok())
174        .unwrap_or("application/octet-stream");
175    let content_type = super::ContentType::from(content_type);
176
177    if !status.is_client_error() && !status.is_server_error() {
178        let content = resp.text().await?;
179        match content_type {
180            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
181            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::HistoryResourcePagingResource`"))),
182            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::HistoryResourcePagingResource`")))),
183        }
184    } else {
185        let content = resp.text().await?;
186        let entity: Option<GetHistoryError> = serde_json::from_str(&content).ok();
187        Err(Error::ResponseError(ResponseContent { status, content, entity }))
188    }
189}
190
191pub async fn list_history_movie(configuration: &configuration::Configuration, movie_id: Option<i32>, event_type: Option<models::MovieHistoryEventType>, include_movie: Option<bool>) -> Result<Vec<models::HistoryResource>, Error<ListHistoryMovieError>> {
192    // add a prefix to parameters to efficiently prevent name collisions
193    let p_query_movie_id = movie_id;
194    let p_query_event_type = event_type;
195    let p_query_include_movie = include_movie;
196
197    let uri_str = format!("{}/api/v3/history/movie", configuration.base_path);
198    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
199
200    if let Some(ref param_value) = p_query_movie_id {
201        req_builder = req_builder.query(&[("movieId", &param_value.to_string())]);
202    }
203    if let Some(ref param_value) = p_query_event_type {
204        req_builder = req_builder.query(&[("eventType", &param_value.to_string())]);
205    }
206    if let Some(ref param_value) = p_query_include_movie {
207        req_builder = req_builder.query(&[("includeMovie", &param_value.to_string())]);
208    }
209    if let Some(ref apikey) = configuration.api_key {
210        let key = apikey.key.clone();
211        let value = match apikey.prefix {
212            Some(ref prefix) => format!("{} {}", prefix, key),
213            None => key,
214        };
215        req_builder = req_builder.query(&[("apikey", value)]);
216    }
217    if let Some(ref user_agent) = configuration.user_agent {
218        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
219    }
220    if let Some(ref apikey) = configuration.api_key {
221        let key = apikey.key.clone();
222        let value = match apikey.prefix {
223            Some(ref prefix) => format!("{} {}", prefix, key),
224            None => key,
225        };
226        req_builder = req_builder.header("X-Api-Key", value);
227    };
228
229    let req = req_builder.build()?;
230    let resp = configuration.client.execute(req).await?;
231
232    let status = resp.status();
233    let content_type = resp
234        .headers()
235        .get("content-type")
236        .and_then(|v| v.to_str().ok())
237        .unwrap_or("application/octet-stream");
238    let content_type = super::ContentType::from(content_type);
239
240    if !status.is_client_error() && !status.is_server_error() {
241        let content = resp.text().await?;
242        match content_type {
243            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
244            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::HistoryResource&gt;`"))),
245            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::HistoryResource&gt;`")))),
246        }
247    } else {
248        let content = resp.text().await?;
249        let entity: Option<ListHistoryMovieError> = serde_json::from_str(&content).ok();
250        Err(Error::ResponseError(ResponseContent { status, content, entity }))
251    }
252}
253
254pub async fn list_history_since(configuration: &configuration::Configuration, date: Option<String>, event_type: Option<models::MovieHistoryEventType>, include_movie: Option<bool>) -> Result<Vec<models::HistoryResource>, Error<ListHistorySinceError>> {
255    // add a prefix to parameters to efficiently prevent name collisions
256    let p_query_date = date;
257    let p_query_event_type = event_type;
258    let p_query_include_movie = include_movie;
259
260    let uri_str = format!("{}/api/v3/history/since", configuration.base_path);
261    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
262
263    if let Some(ref param_value) = p_query_date {
264        req_builder = req_builder.query(&[("date", &param_value.to_string())]);
265    }
266    if let Some(ref param_value) = p_query_event_type {
267        req_builder = req_builder.query(&[("eventType", &param_value.to_string())]);
268    }
269    if let Some(ref param_value) = p_query_include_movie {
270        req_builder = req_builder.query(&[("includeMovie", &param_value.to_string())]);
271    }
272    if let Some(ref apikey) = configuration.api_key {
273        let key = apikey.key.clone();
274        let value = match apikey.prefix {
275            Some(ref prefix) => format!("{} {}", prefix, key),
276            None => key,
277        };
278        req_builder = req_builder.query(&[("apikey", value)]);
279    }
280    if let Some(ref user_agent) = configuration.user_agent {
281        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
282    }
283    if let Some(ref apikey) = configuration.api_key {
284        let key = apikey.key.clone();
285        let value = match apikey.prefix {
286            Some(ref prefix) => format!("{} {}", prefix, key),
287            None => key,
288        };
289        req_builder = req_builder.header("X-Api-Key", value);
290    };
291
292    let req = req_builder.build()?;
293    let resp = configuration.client.execute(req).await?;
294
295    let status = resp.status();
296    let content_type = resp
297        .headers()
298        .get("content-type")
299        .and_then(|v| v.to_str().ok())
300        .unwrap_or("application/octet-stream");
301    let content_type = super::ContentType::from(content_type);
302
303    if !status.is_client_error() && !status.is_server_error() {
304        let content = resp.text().await?;
305        match content_type {
306            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
307            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::HistoryResource&gt;`"))),
308            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::HistoryResource&gt;`")))),
309        }
310    } else {
311        let content = resp.text().await?;
312        let entity: Option<ListHistorySinceError> = serde_json::from_str(&content).ok();
313        Err(Error::ResponseError(ResponseContent { status, content, entity }))
314    }
315}
316