sonarr_api_rs/apis/
metadata_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: 3.0.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`api_v3_metadata_action_name_post`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ApiV3MetadataActionNamePostError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`api_v3_metadata_get`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum ApiV3MetadataGetError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`api_v3_metadata_id_delete`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum ApiV3MetadataIdDeleteError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`api_v3_metadata_id_get`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum ApiV3MetadataIdGetError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`api_v3_metadata_id_put`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum ApiV3MetadataIdPutError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`api_v3_metadata_post`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum ApiV3MetadataPostError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`api_v3_metadata_schema_get`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum ApiV3MetadataSchemaGetError {
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`api_v3_metadata_test_post`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum ApiV3MetadataTestPostError {
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`api_v3_metadata_testall_post`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum ApiV3MetadataTestallPostError {
78    UnknownValue(serde_json::Value),
79}
80
81
82pub async fn api_v3_metadata_action_name_post(configuration: &configuration::Configuration, name: &str, metadata_resource: Option<models::MetadataResource>) -> Result<(), Error<ApiV3MetadataActionNamePostError>> {
83    let local_var_configuration = configuration;
84
85    let local_var_client = &local_var_configuration.client;
86
87    let local_var_uri_str = format!("{}/api/v3/metadata/action/{name}", local_var_configuration.base_path, name=crate::apis::urlencode(name));
88    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
89
90    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
91        let local_var_key = local_var_apikey.key.clone();
92        let local_var_value = match local_var_apikey.prefix {
93            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
94            None => local_var_key,
95        };
96        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
97    }
98    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
99        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
100    }
101    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
102        let local_var_key = local_var_apikey.key.clone();
103        let local_var_value = match local_var_apikey.prefix {
104            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
105            None => local_var_key,
106        };
107        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
108    };
109    local_var_req_builder = local_var_req_builder.json(&metadata_resource);
110
111    let local_var_req = local_var_req_builder.build()?;
112    let local_var_resp = local_var_client.execute(local_var_req).await?;
113
114    let local_var_status = local_var_resp.status();
115    let local_var_content = local_var_resp.text().await?;
116
117    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
118        Ok(())
119    } else {
120        let local_var_entity: Option<ApiV3MetadataActionNamePostError> = serde_json::from_str(&local_var_content).ok();
121        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
122        Err(Error::ResponseError(local_var_error))
123    }
124}
125
126pub async fn api_v3_metadata_get(configuration: &configuration::Configuration, ) -> Result<Vec<models::MetadataResource>, Error<ApiV3MetadataGetError>> {
127    let local_var_configuration = configuration;
128
129    let local_var_client = &local_var_configuration.client;
130
131    let local_var_uri_str = format!("{}/api/v3/metadata", local_var_configuration.base_path);
132    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
133
134    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
135        let local_var_key = local_var_apikey.key.clone();
136        let local_var_value = match local_var_apikey.prefix {
137            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
138            None => local_var_key,
139        };
140        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
141    }
142    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
143        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
144    }
145    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
146        let local_var_key = local_var_apikey.key.clone();
147        let local_var_value = match local_var_apikey.prefix {
148            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
149            None => local_var_key,
150        };
151        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
152    };
153
154    let local_var_req = local_var_req_builder.build()?;
155    let local_var_resp = local_var_client.execute(local_var_req).await?;
156
157    let local_var_status = local_var_resp.status();
158    let local_var_content = local_var_resp.text().await?;
159
160    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
161        serde_json::from_str(&local_var_content).map_err(Error::from)
162    } else {
163        let local_var_entity: Option<ApiV3MetadataGetError> = serde_json::from_str(&local_var_content).ok();
164        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
165        Err(Error::ResponseError(local_var_error))
166    }
167}
168
169pub async fn api_v3_metadata_id_delete(configuration: &configuration::Configuration, id: i32) -> Result<(), Error<ApiV3MetadataIdDeleteError>> {
170    let local_var_configuration = configuration;
171
172    let local_var_client = &local_var_configuration.client;
173
174    let local_var_uri_str = format!("{}/api/v3/metadata/{id}", local_var_configuration.base_path, id=id);
175    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
176
177    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
178        let local_var_key = local_var_apikey.key.clone();
179        let local_var_value = match local_var_apikey.prefix {
180            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
181            None => local_var_key,
182        };
183        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
184    }
185    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
186        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
187    }
188    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
189        let local_var_key = local_var_apikey.key.clone();
190        let local_var_value = match local_var_apikey.prefix {
191            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
192            None => local_var_key,
193        };
194        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
195    };
196
197    let local_var_req = local_var_req_builder.build()?;
198    let local_var_resp = local_var_client.execute(local_var_req).await?;
199
200    let local_var_status = local_var_resp.status();
201    let local_var_content = local_var_resp.text().await?;
202
203    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
204        Ok(())
205    } else {
206        let local_var_entity: Option<ApiV3MetadataIdDeleteError> = serde_json::from_str(&local_var_content).ok();
207        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
208        Err(Error::ResponseError(local_var_error))
209    }
210}
211
212pub async fn api_v3_metadata_id_get(configuration: &configuration::Configuration, id: i32) -> Result<models::MetadataResource, Error<ApiV3MetadataIdGetError>> {
213    let local_var_configuration = configuration;
214
215    let local_var_client = &local_var_configuration.client;
216
217    let local_var_uri_str = format!("{}/api/v3/metadata/{id}", local_var_configuration.base_path, id=id);
218    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
219
220    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
221        let local_var_key = local_var_apikey.key.clone();
222        let local_var_value = match local_var_apikey.prefix {
223            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
224            None => local_var_key,
225        };
226        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
227    }
228    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
229        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
230    }
231    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
232        let local_var_key = local_var_apikey.key.clone();
233        let local_var_value = match local_var_apikey.prefix {
234            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
235            None => local_var_key,
236        };
237        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
238    };
239
240    let local_var_req = local_var_req_builder.build()?;
241    let local_var_resp = local_var_client.execute(local_var_req).await?;
242
243    let local_var_status = local_var_resp.status();
244    let local_var_content = local_var_resp.text().await?;
245
246    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
247        serde_json::from_str(&local_var_content).map_err(Error::from)
248    } else {
249        let local_var_entity: Option<ApiV3MetadataIdGetError> = serde_json::from_str(&local_var_content).ok();
250        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
251        Err(Error::ResponseError(local_var_error))
252    }
253}
254
255pub async fn api_v3_metadata_id_put(configuration: &configuration::Configuration, id: &str, force_save: Option<bool>, metadata_resource: Option<models::MetadataResource>) -> Result<models::MetadataResource, Error<ApiV3MetadataIdPutError>> {
256    let local_var_configuration = configuration;
257
258    let local_var_client = &local_var_configuration.client;
259
260    let local_var_uri_str = format!("{}/api/v3/metadata/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
261    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
262
263    if let Some(ref local_var_str) = force_save {
264        local_var_req_builder = local_var_req_builder.query(&[("forceSave", &local_var_str.to_string())]);
265    }
266    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
267        let local_var_key = local_var_apikey.key.clone();
268        let local_var_value = match local_var_apikey.prefix {
269            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
270            None => local_var_key,
271        };
272        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
273    }
274    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
275        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
276    }
277    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
278        let local_var_key = local_var_apikey.key.clone();
279        let local_var_value = match local_var_apikey.prefix {
280            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
281            None => local_var_key,
282        };
283        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
284    };
285    local_var_req_builder = local_var_req_builder.json(&metadata_resource);
286
287    let local_var_req = local_var_req_builder.build()?;
288    let local_var_resp = local_var_client.execute(local_var_req).await?;
289
290    let local_var_status = local_var_resp.status();
291    let local_var_content = local_var_resp.text().await?;
292
293    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
294        serde_json::from_str(&local_var_content).map_err(Error::from)
295    } else {
296        let local_var_entity: Option<ApiV3MetadataIdPutError> = serde_json::from_str(&local_var_content).ok();
297        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
298        Err(Error::ResponseError(local_var_error))
299    }
300}
301
302pub async fn api_v3_metadata_post(configuration: &configuration::Configuration, force_save: Option<bool>, metadata_resource: Option<models::MetadataResource>) -> Result<models::MetadataResource, Error<ApiV3MetadataPostError>> {
303    let local_var_configuration = configuration;
304
305    let local_var_client = &local_var_configuration.client;
306
307    let local_var_uri_str = format!("{}/api/v3/metadata", local_var_configuration.base_path);
308    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
309
310    if let Some(ref local_var_str) = force_save {
311        local_var_req_builder = local_var_req_builder.query(&[("forceSave", &local_var_str.to_string())]);
312    }
313    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
314        let local_var_key = local_var_apikey.key.clone();
315        let local_var_value = match local_var_apikey.prefix {
316            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
317            None => local_var_key,
318        };
319        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
320    }
321    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
322        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
323    }
324    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
325        let local_var_key = local_var_apikey.key.clone();
326        let local_var_value = match local_var_apikey.prefix {
327            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
328            None => local_var_key,
329        };
330        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
331    };
332    local_var_req_builder = local_var_req_builder.json(&metadata_resource);
333
334    let local_var_req = local_var_req_builder.build()?;
335    let local_var_resp = local_var_client.execute(local_var_req).await?;
336
337    let local_var_status = local_var_resp.status();
338    let local_var_content = local_var_resp.text().await?;
339
340    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
341        serde_json::from_str(&local_var_content).map_err(Error::from)
342    } else {
343        let local_var_entity: Option<ApiV3MetadataPostError> = serde_json::from_str(&local_var_content).ok();
344        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
345        Err(Error::ResponseError(local_var_error))
346    }
347}
348
349pub async fn api_v3_metadata_schema_get(configuration: &configuration::Configuration, ) -> Result<Vec<models::MetadataResource>, Error<ApiV3MetadataSchemaGetError>> {
350    let local_var_configuration = configuration;
351
352    let local_var_client = &local_var_configuration.client;
353
354    let local_var_uri_str = format!("{}/api/v3/metadata/schema", local_var_configuration.base_path);
355    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
356
357    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
358        let local_var_key = local_var_apikey.key.clone();
359        let local_var_value = match local_var_apikey.prefix {
360            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
361            None => local_var_key,
362        };
363        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
364    }
365    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
366        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
367    }
368    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
369        let local_var_key = local_var_apikey.key.clone();
370        let local_var_value = match local_var_apikey.prefix {
371            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
372            None => local_var_key,
373        };
374        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
375    };
376
377    let local_var_req = local_var_req_builder.build()?;
378    let local_var_resp = local_var_client.execute(local_var_req).await?;
379
380    let local_var_status = local_var_resp.status();
381    let local_var_content = local_var_resp.text().await?;
382
383    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
384        serde_json::from_str(&local_var_content).map_err(Error::from)
385    } else {
386        let local_var_entity: Option<ApiV3MetadataSchemaGetError> = serde_json::from_str(&local_var_content).ok();
387        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
388        Err(Error::ResponseError(local_var_error))
389    }
390}
391
392pub async fn api_v3_metadata_test_post(configuration: &configuration::Configuration, force_test: Option<bool>, metadata_resource: Option<models::MetadataResource>) -> Result<(), Error<ApiV3MetadataTestPostError>> {
393    let local_var_configuration = configuration;
394
395    let local_var_client = &local_var_configuration.client;
396
397    let local_var_uri_str = format!("{}/api/v3/metadata/test", local_var_configuration.base_path);
398    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
399
400    if let Some(ref local_var_str) = force_test {
401        local_var_req_builder = local_var_req_builder.query(&[("forceTest", &local_var_str.to_string())]);
402    }
403    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
404        let local_var_key = local_var_apikey.key.clone();
405        let local_var_value = match local_var_apikey.prefix {
406            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
407            None => local_var_key,
408        };
409        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
410    }
411    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
412        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
413    }
414    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
415        let local_var_key = local_var_apikey.key.clone();
416        let local_var_value = match local_var_apikey.prefix {
417            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
418            None => local_var_key,
419        };
420        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
421    };
422    local_var_req_builder = local_var_req_builder.json(&metadata_resource);
423
424    let local_var_req = local_var_req_builder.build()?;
425    let local_var_resp = local_var_client.execute(local_var_req).await?;
426
427    let local_var_status = local_var_resp.status();
428    let local_var_content = local_var_resp.text().await?;
429
430    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
431        Ok(())
432    } else {
433        let local_var_entity: Option<ApiV3MetadataTestPostError> = serde_json::from_str(&local_var_content).ok();
434        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
435        Err(Error::ResponseError(local_var_error))
436    }
437}
438
439pub async fn api_v3_metadata_testall_post(configuration: &configuration::Configuration, ) -> Result<(), Error<ApiV3MetadataTestallPostError>> {
440    let local_var_configuration = configuration;
441
442    let local_var_client = &local_var_configuration.client;
443
444    let local_var_uri_str = format!("{}/api/v3/metadata/testall", local_var_configuration.base_path);
445    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
446
447    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
448        let local_var_key = local_var_apikey.key.clone();
449        let local_var_value = match local_var_apikey.prefix {
450            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
451            None => local_var_key,
452        };
453        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
454    }
455    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
456        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
457    }
458    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
459        let local_var_key = local_var_apikey.key.clone();
460        let local_var_value = match local_var_apikey.prefix {
461            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
462            None => local_var_key,
463        };
464        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
465    };
466
467    let local_var_req = local_var_req_builder.build()?;
468    let local_var_resp = local_var_client.execute(local_var_req).await?;
469
470    let local_var_status = local_var_resp.status();
471    let local_var_content = local_var_resp.text().await?;
472
473    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
474        Ok(())
475    } else {
476        let local_var_entity: Option<ApiV3MetadataTestallPostError> = serde_json::from_str(&local_var_content).ok();
477        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
478        Err(Error::ResponseError(local_var_error))
479    }
480}
481