radarr/apis/
extra_file_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ListExtraFileError {
22 UnknownValue(serde_json::Value),
23}
24
25
26pub async fn list_extra_file(configuration: &configuration::Configuration, movie_id: Option<i32>) -> Result<Vec<models::ExtraFileResource>, Error<ListExtraFileError>> {
27 let p_query_movie_id = movie_id;
29
30 let uri_str = format!("{}/api/v3/extrafile", configuration.base_path);
31 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
32
33 if let Some(ref param_value) = p_query_movie_id {
34 req_builder = req_builder.query(&[("movieId", ¶m_value.to_string())]);
35 }
36 if let Some(ref apikey) = configuration.api_key {
37 let key = apikey.key.clone();
38 let value = match apikey.prefix {
39 Some(ref prefix) => format!("{} {}", prefix, key),
40 None => key,
41 };
42 req_builder = req_builder.query(&[("apikey", value)]);
43 }
44 if let Some(ref user_agent) = configuration.user_agent {
45 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
46 }
47 if let Some(ref apikey) = configuration.api_key {
48 let key = apikey.key.clone();
49 let value = match apikey.prefix {
50 Some(ref prefix) => format!("{} {}", prefix, key),
51 None => key,
52 };
53 req_builder = req_builder.header("X-Api-Key", value);
54 };
55
56 let req = req_builder.build()?;
57 let resp = configuration.client.execute(req).await?;
58
59 let status = resp.status();
60 let content_type = resp
61 .headers()
62 .get("content-type")
63 .and_then(|v| v.to_str().ok())
64 .unwrap_or("application/octet-stream");
65 let content_type = super::ContentType::from(content_type);
66
67 if !status.is_client_error() && !status.is_server_error() {
68 let content = resp.text().await?;
69 match content_type {
70 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
71 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::ExtraFileResource>`"))),
72 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<models::ExtraFileResource>`")))),
73 }
74 } else {
75 let content = resp.text().await?;
76 let entity: Option<ListExtraFileError> = serde_json::from_str(&content).ok();
77 Err(Error::ResponseError(ResponseContent { status, content, entity }))
78 }
79}
80