sonarr/apis/
remote_path_mapping_api.rs

1/*
2 * Sonarr
3 *
4 * Sonarr API docs - The v3 API docs apply to both v3 and v4 versions of Sonarr. Some functionality may only be available in v4 of the Sonarr application.
5 *
6 * The version of the OpenAPI document: v4.0.15.2941
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_remote_path_mapping`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateRemotePathMappingError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`delete_remote_path_mapping`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DeleteRemotePathMappingError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_remote_path_mapping_by_id`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetRemotePathMappingByIdError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`list_remote_path_mapping`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum ListRemotePathMappingError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`update_remote_path_mapping`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum UpdateRemotePathMappingError {
50    UnknownValue(serde_json::Value),
51}
52
53
54pub async fn create_remote_path_mapping(configuration: &configuration::Configuration, remote_path_mapping_resource: Option<models::RemotePathMappingResource>) -> Result<models::RemotePathMappingResource, Error<CreateRemotePathMappingError>> {
55    // add a prefix to parameters to efficiently prevent name collisions
56    let p_body_remote_path_mapping_resource = remote_path_mapping_resource;
57
58    let uri_str = format!("{}/api/v3/remotepathmapping", configuration.base_path);
59    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
60
61    if let Some(ref apikey) = configuration.api_key {
62        let key = apikey.key.clone();
63        let value = match apikey.prefix {
64            Some(ref prefix) => format!("{} {}", prefix, key),
65            None => key,
66        };
67        req_builder = req_builder.query(&[("apikey", value)]);
68    }
69    if let Some(ref user_agent) = configuration.user_agent {
70        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
71    }
72    if let Some(ref apikey) = configuration.api_key {
73        let key = apikey.key.clone();
74        let value = match apikey.prefix {
75            Some(ref prefix) => format!("{} {}", prefix, key),
76            None => key,
77        };
78        req_builder = req_builder.header("X-Api-Key", value);
79    };
80    req_builder = req_builder.json(&p_body_remote_path_mapping_resource);
81
82    let req = req_builder.build()?;
83    let resp = configuration.client.execute(req).await?;
84
85    let status = resp.status();
86    let content_type = resp
87        .headers()
88        .get("content-type")
89        .and_then(|v| v.to_str().ok())
90        .unwrap_or("application/octet-stream");
91    let content_type = super::ContentType::from(content_type);
92
93    if !status.is_client_error() && !status.is_server_error() {
94        let content = resp.text().await?;
95        match content_type {
96            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
97            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RemotePathMappingResource`"))),
98            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::RemotePathMappingResource`")))),
99        }
100    } else {
101        let content = resp.text().await?;
102        let entity: Option<CreateRemotePathMappingError> = serde_json::from_str(&content).ok();
103        Err(Error::ResponseError(ResponseContent { status, content, entity }))
104    }
105}
106
107pub async fn delete_remote_path_mapping(configuration: &configuration::Configuration, id: i32) -> Result<(), Error<DeleteRemotePathMappingError>> {
108    // add a prefix to parameters to efficiently prevent name collisions
109    let p_path_id = id;
110
111    let uri_str = format!("{}/api/v3/remotepathmapping/{id}", configuration.base_path, id=p_path_id);
112    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
113
114    if let Some(ref apikey) = configuration.api_key {
115        let key = apikey.key.clone();
116        let value = match apikey.prefix {
117            Some(ref prefix) => format!("{} {}", prefix, key),
118            None => key,
119        };
120        req_builder = req_builder.query(&[("apikey", value)]);
121    }
122    if let Some(ref user_agent) = configuration.user_agent {
123        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
124    }
125    if let Some(ref apikey) = configuration.api_key {
126        let key = apikey.key.clone();
127        let value = match apikey.prefix {
128            Some(ref prefix) => format!("{} {}", prefix, key),
129            None => key,
130        };
131        req_builder = req_builder.header("X-Api-Key", value);
132    };
133
134    let req = req_builder.build()?;
135    let resp = configuration.client.execute(req).await?;
136
137    let status = resp.status();
138
139    if !status.is_client_error() && !status.is_server_error() {
140        Ok(())
141    } else {
142        let content = resp.text().await?;
143        let entity: Option<DeleteRemotePathMappingError> = serde_json::from_str(&content).ok();
144        Err(Error::ResponseError(ResponseContent { status, content, entity }))
145    }
146}
147
148pub async fn get_remote_path_mapping_by_id(configuration: &configuration::Configuration, id: i32) -> Result<models::RemotePathMappingResource, Error<GetRemotePathMappingByIdError>> {
149    // add a prefix to parameters to efficiently prevent name collisions
150    let p_path_id = id;
151
152    let uri_str = format!("{}/api/v3/remotepathmapping/{id}", configuration.base_path, id=p_path_id);
153    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
154
155    if let Some(ref apikey) = configuration.api_key {
156        let key = apikey.key.clone();
157        let value = match apikey.prefix {
158            Some(ref prefix) => format!("{} {}", prefix, key),
159            None => key,
160        };
161        req_builder = req_builder.query(&[("apikey", value)]);
162    }
163    if let Some(ref user_agent) = configuration.user_agent {
164        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
165    }
166    if let Some(ref apikey) = configuration.api_key {
167        let key = apikey.key.clone();
168        let value = match apikey.prefix {
169            Some(ref prefix) => format!("{} {}", prefix, key),
170            None => key,
171        };
172        req_builder = req_builder.header("X-Api-Key", value);
173    };
174
175    let req = req_builder.build()?;
176    let resp = configuration.client.execute(req).await?;
177
178    let status = resp.status();
179    let content_type = resp
180        .headers()
181        .get("content-type")
182        .and_then(|v| v.to_str().ok())
183        .unwrap_or("application/octet-stream");
184    let content_type = super::ContentType::from(content_type);
185
186    if !status.is_client_error() && !status.is_server_error() {
187        let content = resp.text().await?;
188        match content_type {
189            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
190            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RemotePathMappingResource`"))),
191            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::RemotePathMappingResource`")))),
192        }
193    } else {
194        let content = resp.text().await?;
195        let entity: Option<GetRemotePathMappingByIdError> = serde_json::from_str(&content).ok();
196        Err(Error::ResponseError(ResponseContent { status, content, entity }))
197    }
198}
199
200pub async fn list_remote_path_mapping(configuration: &configuration::Configuration, ) -> Result<Vec<models::RemotePathMappingResource>, Error<ListRemotePathMappingError>> {
201
202    let uri_str = format!("{}/api/v3/remotepathmapping", configuration.base_path);
203    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
204
205    if let Some(ref apikey) = configuration.api_key {
206        let key = apikey.key.clone();
207        let value = match apikey.prefix {
208            Some(ref prefix) => format!("{} {}", prefix, key),
209            None => key,
210        };
211        req_builder = req_builder.query(&[("apikey", value)]);
212    }
213    if let Some(ref user_agent) = configuration.user_agent {
214        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
215    }
216    if let Some(ref apikey) = configuration.api_key {
217        let key = apikey.key.clone();
218        let value = match apikey.prefix {
219            Some(ref prefix) => format!("{} {}", prefix, key),
220            None => key,
221        };
222        req_builder = req_builder.header("X-Api-Key", value);
223    };
224
225    let req = req_builder.build()?;
226    let resp = configuration.client.execute(req).await?;
227
228    let status = resp.status();
229    let content_type = resp
230        .headers()
231        .get("content-type")
232        .and_then(|v| v.to_str().ok())
233        .unwrap_or("application/octet-stream");
234    let content_type = super::ContentType::from(content_type);
235
236    if !status.is_client_error() && !status.is_server_error() {
237        let content = resp.text().await?;
238        match content_type {
239            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
240            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::RemotePathMappingResource&gt;`"))),
241            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::RemotePathMappingResource&gt;`")))),
242        }
243    } else {
244        let content = resp.text().await?;
245        let entity: Option<ListRemotePathMappingError> = serde_json::from_str(&content).ok();
246        Err(Error::ResponseError(ResponseContent { status, content, entity }))
247    }
248}
249
250pub async fn update_remote_path_mapping(configuration: &configuration::Configuration, id: &str, remote_path_mapping_resource: Option<models::RemotePathMappingResource>) -> Result<models::RemotePathMappingResource, Error<UpdateRemotePathMappingError>> {
251    // add a prefix to parameters to efficiently prevent name collisions
252    let p_path_id = id;
253    let p_body_remote_path_mapping_resource = remote_path_mapping_resource;
254
255    let uri_str = format!("{}/api/v3/remotepathmapping/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
256    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
257
258    if let Some(ref apikey) = configuration.api_key {
259        let key = apikey.key.clone();
260        let value = match apikey.prefix {
261            Some(ref prefix) => format!("{} {}", prefix, key),
262            None => key,
263        };
264        req_builder = req_builder.query(&[("apikey", value)]);
265    }
266    if let Some(ref user_agent) = configuration.user_agent {
267        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
268    }
269    if let Some(ref apikey) = configuration.api_key {
270        let key = apikey.key.clone();
271        let value = match apikey.prefix {
272            Some(ref prefix) => format!("{} {}", prefix, key),
273            None => key,
274        };
275        req_builder = req_builder.header("X-Api-Key", value);
276    };
277    req_builder = req_builder.json(&p_body_remote_path_mapping_resource);
278
279    let req = req_builder.build()?;
280    let resp = configuration.client.execute(req).await?;
281
282    let status = resp.status();
283    let content_type = resp
284        .headers()
285        .get("content-type")
286        .and_then(|v| v.to_str().ok())
287        .unwrap_or("application/octet-stream");
288    let content_type = super::ContentType::from(content_type);
289
290    if !status.is_client_error() && !status.is_server_error() {
291        let content = resp.text().await?;
292        match content_type {
293            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
294            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RemotePathMappingResource`"))),
295            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::RemotePathMappingResource`")))),
296        }
297    } else {
298        let content = resp.text().await?;
299        let entity: Option<UpdateRemotePathMappingError> = serde_json::from_str(&content).ok();
300        Err(Error::ResponseError(ResponseContent { status, content, entity }))
301    }
302}
303