radarr_api_rs/apis/
release_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 super::{Error, configuration};
16
17
18/// struct for typed errors of method [`api_v3_release_get`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ApiV3ReleaseGetError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`api_v3_release_id_get`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum ApiV3ReleaseIdGetError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`api_v3_release_post`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum ApiV3ReleasePostError {
36    UnknownValue(serde_json::Value),
37}
38
39
40pub async fn api_v3_release_get(configuration: &configuration::Configuration, movie_id: Option<i32>) -> Result<Vec<crate::models::ReleaseResource>, Error<ApiV3ReleaseGetError>> {
41    let local_var_configuration = configuration;
42
43    let local_var_client = &local_var_configuration.client;
44
45    let local_var_uri_str = format!("{}/api/v3/release", local_var_configuration.base_path);
46    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
47
48    if let Some(ref local_var_str) = movie_id {
49        local_var_req_builder = local_var_req_builder.query(&[("movieId", &local_var_str.to_string())]);
50    }
51    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
52        let local_var_key = local_var_apikey.key.clone();
53        let local_var_value = match local_var_apikey.prefix {
54            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
55            None => local_var_key,
56        };
57        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
58    }
59    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
60        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
61    }
62    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
63        let local_var_key = local_var_apikey.key.clone();
64        let local_var_value = match local_var_apikey.prefix {
65            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
66            None => local_var_key,
67        };
68        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
69    };
70
71    let local_var_req = local_var_req_builder.build()?;
72    let local_var_resp = local_var_client.execute(local_var_req).await?;
73
74    let local_var_status = local_var_resp.status();
75    let local_var_content = local_var_resp.text().await?;
76
77    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
78        serde_json::from_str(&local_var_content).map_err(Error::from)
79    } else {
80        let local_var_entity: Option<ApiV3ReleaseGetError> = serde_json::from_str(&local_var_content).ok();
81        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
82        Err(Error::ResponseError(local_var_error))
83    }
84}
85
86pub async fn api_v3_release_id_get(configuration: &configuration::Configuration, id: i32) -> Result<crate::models::ReleaseResource, Error<ApiV3ReleaseIdGetError>> {
87    let local_var_configuration = configuration;
88
89    let local_var_client = &local_var_configuration.client;
90
91    let local_var_uri_str = format!("{}/api/v3/release/{id}", local_var_configuration.base_path, id=id);
92    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
93
94    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
95        let local_var_key = local_var_apikey.key.clone();
96        let local_var_value = match local_var_apikey.prefix {
97            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
98            None => local_var_key,
99        };
100        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
101    }
102    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
103        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
104    }
105    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
106        let local_var_key = local_var_apikey.key.clone();
107        let local_var_value = match local_var_apikey.prefix {
108            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
109            None => local_var_key,
110        };
111        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
112    };
113
114    let local_var_req = local_var_req_builder.build()?;
115    let local_var_resp = local_var_client.execute(local_var_req).await?;
116
117    let local_var_status = local_var_resp.status();
118    let local_var_content = local_var_resp.text().await?;
119
120    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
121        serde_json::from_str(&local_var_content).map_err(Error::from)
122    } else {
123        let local_var_entity: Option<ApiV3ReleaseIdGetError> = serde_json::from_str(&local_var_content).ok();
124        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
125        Err(Error::ResponseError(local_var_error))
126    }
127}
128
129pub async fn api_v3_release_post(configuration: &configuration::Configuration, release_resource: Option<crate::models::ReleaseResource>) -> Result<(), Error<ApiV3ReleasePostError>> {
130    let local_var_configuration = configuration;
131
132    let local_var_client = &local_var_configuration.client;
133
134    let local_var_uri_str = format!("{}/api/v3/release", local_var_configuration.base_path);
135    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
136
137    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
138        let local_var_key = local_var_apikey.key.clone();
139        let local_var_value = match local_var_apikey.prefix {
140            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
141            None => local_var_key,
142        };
143        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
144    }
145    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
146        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
147    }
148    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
149        let local_var_key = local_var_apikey.key.clone();
150        let local_var_value = match local_var_apikey.prefix {
151            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
152            None => local_var_key,
153        };
154        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
155    };
156    local_var_req_builder = local_var_req_builder.json(&release_resource);
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        Ok(())
166    } else {
167        let local_var_entity: Option<ApiV3ReleasePostError> = 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