radarr/apis/
movie_import_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 CreateMovieImportError {
22 UnknownValue(serde_json::Value),
23}
24
25
26pub async fn create_movie_import(configuration: &configuration::Configuration, movie_resource: Option<Vec<models::MovieResource>>) -> Result<Vec<models::MovieResource>, Error<CreateMovieImportError>> {
27 let p_body_movie_resource = movie_resource;
29
30 let uri_str = format!("{}/api/v3/movie/import", configuration.base_path);
31 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
32
33 if let Some(ref apikey) = configuration.api_key {
34 let key = apikey.key.clone();
35 let value = match apikey.prefix {
36 Some(ref prefix) => format!("{} {}", prefix, key),
37 None => key,
38 };
39 req_builder = req_builder.query(&[("apikey", value)]);
40 }
41 if let Some(ref user_agent) = configuration.user_agent {
42 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
43 }
44 if let Some(ref apikey) = configuration.api_key {
45 let key = apikey.key.clone();
46 let value = match apikey.prefix {
47 Some(ref prefix) => format!("{} {}", prefix, key),
48 None => key,
49 };
50 req_builder = req_builder.header("X-Api-Key", value);
51 };
52 req_builder = req_builder.json(&p_body_movie_resource);
53
54 let req = req_builder.build()?;
55 let resp = configuration.client.execute(req).await?;
56
57 let status = resp.status();
58 let content_type = resp
59 .headers()
60 .get("content-type")
61 .and_then(|v| v.to_str().ok())
62 .unwrap_or("application/octet-stream");
63 let content_type = super::ContentType::from(content_type);
64
65 if !status.is_client_error() && !status.is_server_error() {
66 let content = resp.text().await?;
67 match content_type {
68 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
69 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::MovieResource>`"))),
70 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::MovieResource>`")))),
71 }
72 } else {
73 let content = resp.text().await?;
74 let entity: Option<CreateMovieImportError> = serde_json::from_str(&content).ok();
75 Err(Error::ResponseError(ResponseContent { status, content, entity }))
76 }
77}
78