lidarr/apis/
notification_api.rs

1/*
2 * Lidarr
3 *
4 * Lidarr API docs
5 *
6 * The version of the OpenAPI document: v2.13.3.4711
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_notification`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateNotificationError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`create_notification_action_by_name`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum CreateNotificationActionByNameError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`delete_notification`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum DeleteNotificationError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_notification_by_id`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetNotificationByIdError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`list_notification`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum ListNotificationError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`list_notification_schema`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum ListNotificationSchemaError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`test_notification`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum TestNotificationError {
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`testall_notification`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum TestallNotificationError {
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`update_notification`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum UpdateNotificationError {
78    UnknownValue(serde_json::Value),
79}
80
81
82pub async fn create_notification(configuration: &configuration::Configuration, force_save: Option<bool>, notification_resource: Option<models::NotificationResource>) -> Result<models::NotificationResource, Error<CreateNotificationError>> {
83    // add a prefix to parameters to efficiently prevent name collisions
84    let p_query_force_save = force_save;
85    let p_body_notification_resource = notification_resource;
86
87    let uri_str = format!("{}/api/v1/notification", configuration.base_path);
88    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
89
90    if let Some(ref param_value) = p_query_force_save {
91        req_builder = req_builder.query(&[("forceSave", &param_value.to_string())]);
92    }
93    if let Some(ref apikey) = configuration.api_key {
94        let key = apikey.key.clone();
95        let value = match apikey.prefix {
96            Some(ref prefix) => format!("{} {}", prefix, key),
97            None => key,
98        };
99        req_builder = req_builder.query(&[("apikey", value)]);
100    }
101    if let Some(ref user_agent) = configuration.user_agent {
102        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
103    }
104    if let Some(ref apikey) = configuration.api_key {
105        let key = apikey.key.clone();
106        let value = match apikey.prefix {
107            Some(ref prefix) => format!("{} {}", prefix, key),
108            None => key,
109        };
110        req_builder = req_builder.header("X-Api-Key", value);
111    };
112    req_builder = req_builder.json(&p_body_notification_resource);
113
114    let req = req_builder.build()?;
115    let resp = configuration.client.execute(req).await?;
116
117    let status = resp.status();
118    let content_type = resp
119        .headers()
120        .get("content-type")
121        .and_then(|v| v.to_str().ok())
122        .unwrap_or("application/octet-stream");
123    let content_type = super::ContentType::from(content_type);
124
125    if !status.is_client_error() && !status.is_server_error() {
126        let content = resp.text().await?;
127        match content_type {
128            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
129            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NotificationResource`"))),
130            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::NotificationResource`")))),
131        }
132    } else {
133        let content = resp.text().await?;
134        let entity: Option<CreateNotificationError> = serde_json::from_str(&content).ok();
135        Err(Error::ResponseError(ResponseContent { status, content, entity }))
136    }
137}
138
139pub async fn create_notification_action_by_name(configuration: &configuration::Configuration, name: &str, notification_resource: Option<models::NotificationResource>) -> Result<(), Error<CreateNotificationActionByNameError>> {
140    // add a prefix to parameters to efficiently prevent name collisions
141    let p_path_name = name;
142    let p_body_notification_resource = notification_resource;
143
144    let uri_str = format!("{}/api/v1/notification/action/{name}", configuration.base_path, name=crate::apis::urlencode(p_path_name));
145    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
146
147    if let Some(ref apikey) = configuration.api_key {
148        let key = apikey.key.clone();
149        let value = match apikey.prefix {
150            Some(ref prefix) => format!("{} {}", prefix, key),
151            None => key,
152        };
153        req_builder = req_builder.query(&[("apikey", value)]);
154    }
155    if let Some(ref user_agent) = configuration.user_agent {
156        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
157    }
158    if let Some(ref apikey) = configuration.api_key {
159        let key = apikey.key.clone();
160        let value = match apikey.prefix {
161            Some(ref prefix) => format!("{} {}", prefix, key),
162            None => key,
163        };
164        req_builder = req_builder.header("X-Api-Key", value);
165    };
166    req_builder = req_builder.json(&p_body_notification_resource);
167
168    let req = req_builder.build()?;
169    let resp = configuration.client.execute(req).await?;
170
171    let status = resp.status();
172
173    if !status.is_client_error() && !status.is_server_error() {
174        Ok(())
175    } else {
176        let content = resp.text().await?;
177        let entity: Option<CreateNotificationActionByNameError> = serde_json::from_str(&content).ok();
178        Err(Error::ResponseError(ResponseContent { status, content, entity }))
179    }
180}
181
182pub async fn delete_notification(configuration: &configuration::Configuration, id: i32) -> Result<(), Error<DeleteNotificationError>> {
183    // add a prefix to parameters to efficiently prevent name collisions
184    let p_path_id = id;
185
186    let uri_str = format!("{}/api/v1/notification/{id}", configuration.base_path, id=p_path_id);
187    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
188
189    if let Some(ref apikey) = configuration.api_key {
190        let key = apikey.key.clone();
191        let value = match apikey.prefix {
192            Some(ref prefix) => format!("{} {}", prefix, key),
193            None => key,
194        };
195        req_builder = req_builder.query(&[("apikey", value)]);
196    }
197    if let Some(ref user_agent) = configuration.user_agent {
198        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
199    }
200    if let Some(ref apikey) = configuration.api_key {
201        let key = apikey.key.clone();
202        let value = match apikey.prefix {
203            Some(ref prefix) => format!("{} {}", prefix, key),
204            None => key,
205        };
206        req_builder = req_builder.header("X-Api-Key", value);
207    };
208
209    let req = req_builder.build()?;
210    let resp = configuration.client.execute(req).await?;
211
212    let status = resp.status();
213
214    if !status.is_client_error() && !status.is_server_error() {
215        Ok(())
216    } else {
217        let content = resp.text().await?;
218        let entity: Option<DeleteNotificationError> = serde_json::from_str(&content).ok();
219        Err(Error::ResponseError(ResponseContent { status, content, entity }))
220    }
221}
222
223pub async fn get_notification_by_id(configuration: &configuration::Configuration, id: i32) -> Result<models::NotificationResource, Error<GetNotificationByIdError>> {
224    // add a prefix to parameters to efficiently prevent name collisions
225    let p_path_id = id;
226
227    let uri_str = format!("{}/api/v1/notification/{id}", configuration.base_path, id=p_path_id);
228    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
229
230    if let Some(ref apikey) = configuration.api_key {
231        let key = apikey.key.clone();
232        let value = match apikey.prefix {
233            Some(ref prefix) => format!("{} {}", prefix, key),
234            None => key,
235        };
236        req_builder = req_builder.query(&[("apikey", value)]);
237    }
238    if let Some(ref user_agent) = configuration.user_agent {
239        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
240    }
241    if let Some(ref apikey) = configuration.api_key {
242        let key = apikey.key.clone();
243        let value = match apikey.prefix {
244            Some(ref prefix) => format!("{} {}", prefix, key),
245            None => key,
246        };
247        req_builder = req_builder.header("X-Api-Key", value);
248    };
249
250    let req = req_builder.build()?;
251    let resp = configuration.client.execute(req).await?;
252
253    let status = resp.status();
254    let content_type = resp
255        .headers()
256        .get("content-type")
257        .and_then(|v| v.to_str().ok())
258        .unwrap_or("application/octet-stream");
259    let content_type = super::ContentType::from(content_type);
260
261    if !status.is_client_error() && !status.is_server_error() {
262        let content = resp.text().await?;
263        match content_type {
264            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
265            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NotificationResource`"))),
266            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::NotificationResource`")))),
267        }
268    } else {
269        let content = resp.text().await?;
270        let entity: Option<GetNotificationByIdError> = serde_json::from_str(&content).ok();
271        Err(Error::ResponseError(ResponseContent { status, content, entity }))
272    }
273}
274
275pub async fn list_notification(configuration: &configuration::Configuration, ) -> Result<Vec<models::NotificationResource>, Error<ListNotificationError>> {
276
277    let uri_str = format!("{}/api/v1/notification", configuration.base_path);
278    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
279
280    if let Some(ref apikey) = configuration.api_key {
281        let key = apikey.key.clone();
282        let value = match apikey.prefix {
283            Some(ref prefix) => format!("{} {}", prefix, key),
284            None => key,
285        };
286        req_builder = req_builder.query(&[("apikey", value)]);
287    }
288    if let Some(ref user_agent) = configuration.user_agent {
289        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
290    }
291    if let Some(ref apikey) = configuration.api_key {
292        let key = apikey.key.clone();
293        let value = match apikey.prefix {
294            Some(ref prefix) => format!("{} {}", prefix, key),
295            None => key,
296        };
297        req_builder = req_builder.header("X-Api-Key", value);
298    };
299
300    let req = req_builder.build()?;
301    let resp = configuration.client.execute(req).await?;
302
303    let status = resp.status();
304    let content_type = resp
305        .headers()
306        .get("content-type")
307        .and_then(|v| v.to_str().ok())
308        .unwrap_or("application/octet-stream");
309    let content_type = super::ContentType::from(content_type);
310
311    if !status.is_client_error() && !status.is_server_error() {
312        let content = resp.text().await?;
313        match content_type {
314            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
315            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::NotificationResource&gt;`"))),
316            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::NotificationResource&gt;`")))),
317        }
318    } else {
319        let content = resp.text().await?;
320        let entity: Option<ListNotificationError> = serde_json::from_str(&content).ok();
321        Err(Error::ResponseError(ResponseContent { status, content, entity }))
322    }
323}
324
325pub async fn list_notification_schema(configuration: &configuration::Configuration, ) -> Result<Vec<models::NotificationResource>, Error<ListNotificationSchemaError>> {
326
327    let uri_str = format!("{}/api/v1/notification/schema", configuration.base_path);
328    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
329
330    if let Some(ref apikey) = configuration.api_key {
331        let key = apikey.key.clone();
332        let value = match apikey.prefix {
333            Some(ref prefix) => format!("{} {}", prefix, key),
334            None => key,
335        };
336        req_builder = req_builder.query(&[("apikey", value)]);
337    }
338    if let Some(ref user_agent) = configuration.user_agent {
339        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
340    }
341    if let Some(ref apikey) = configuration.api_key {
342        let key = apikey.key.clone();
343        let value = match apikey.prefix {
344            Some(ref prefix) => format!("{} {}", prefix, key),
345            None => key,
346        };
347        req_builder = req_builder.header("X-Api-Key", value);
348    };
349
350    let req = req_builder.build()?;
351    let resp = configuration.client.execute(req).await?;
352
353    let status = resp.status();
354    let content_type = resp
355        .headers()
356        .get("content-type")
357        .and_then(|v| v.to_str().ok())
358        .unwrap_or("application/octet-stream");
359    let content_type = super::ContentType::from(content_type);
360
361    if !status.is_client_error() && !status.is_server_error() {
362        let content = resp.text().await?;
363        match content_type {
364            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
365            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::NotificationResource&gt;`"))),
366            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::NotificationResource&gt;`")))),
367        }
368    } else {
369        let content = resp.text().await?;
370        let entity: Option<ListNotificationSchemaError> = serde_json::from_str(&content).ok();
371        Err(Error::ResponseError(ResponseContent { status, content, entity }))
372    }
373}
374
375pub async fn test_notification(configuration: &configuration::Configuration, force_test: Option<bool>, notification_resource: Option<models::NotificationResource>) -> Result<(), Error<TestNotificationError>> {
376    // add a prefix to parameters to efficiently prevent name collisions
377    let p_query_force_test = force_test;
378    let p_body_notification_resource = notification_resource;
379
380    let uri_str = format!("{}/api/v1/notification/test", configuration.base_path);
381    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
382
383    if let Some(ref param_value) = p_query_force_test {
384        req_builder = req_builder.query(&[("forceTest", &param_value.to_string())]);
385    }
386    if let Some(ref apikey) = configuration.api_key {
387        let key = apikey.key.clone();
388        let value = match apikey.prefix {
389            Some(ref prefix) => format!("{} {}", prefix, key),
390            None => key,
391        };
392        req_builder = req_builder.query(&[("apikey", value)]);
393    }
394    if let Some(ref user_agent) = configuration.user_agent {
395        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
396    }
397    if let Some(ref apikey) = configuration.api_key {
398        let key = apikey.key.clone();
399        let value = match apikey.prefix {
400            Some(ref prefix) => format!("{} {}", prefix, key),
401            None => key,
402        };
403        req_builder = req_builder.header("X-Api-Key", value);
404    };
405    req_builder = req_builder.json(&p_body_notification_resource);
406
407    let req = req_builder.build()?;
408    let resp = configuration.client.execute(req).await?;
409
410    let status = resp.status();
411
412    if !status.is_client_error() && !status.is_server_error() {
413        Ok(())
414    } else {
415        let content = resp.text().await?;
416        let entity: Option<TestNotificationError> = serde_json::from_str(&content).ok();
417        Err(Error::ResponseError(ResponseContent { status, content, entity }))
418    }
419}
420
421pub async fn testall_notification(configuration: &configuration::Configuration, ) -> Result<(), Error<TestallNotificationError>> {
422
423    let uri_str = format!("{}/api/v1/notification/testall", configuration.base_path);
424    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
425
426    if let Some(ref apikey) = configuration.api_key {
427        let key = apikey.key.clone();
428        let value = match apikey.prefix {
429            Some(ref prefix) => format!("{} {}", prefix, key),
430            None => key,
431        };
432        req_builder = req_builder.query(&[("apikey", value)]);
433    }
434    if let Some(ref user_agent) = configuration.user_agent {
435        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
436    }
437    if let Some(ref apikey) = configuration.api_key {
438        let key = apikey.key.clone();
439        let value = match apikey.prefix {
440            Some(ref prefix) => format!("{} {}", prefix, key),
441            None => key,
442        };
443        req_builder = req_builder.header("X-Api-Key", value);
444    };
445
446    let req = req_builder.build()?;
447    let resp = configuration.client.execute(req).await?;
448
449    let status = resp.status();
450
451    if !status.is_client_error() && !status.is_server_error() {
452        Ok(())
453    } else {
454        let content = resp.text().await?;
455        let entity: Option<TestallNotificationError> = serde_json::from_str(&content).ok();
456        Err(Error::ResponseError(ResponseContent { status, content, entity }))
457    }
458}
459
460pub async fn update_notification(configuration: &configuration::Configuration, id: i32, force_save: Option<bool>, notification_resource: Option<models::NotificationResource>) -> Result<models::NotificationResource, Error<UpdateNotificationError>> {
461    // add a prefix to parameters to efficiently prevent name collisions
462    let p_path_id = id;
463    let p_query_force_save = force_save;
464    let p_body_notification_resource = notification_resource;
465
466    let uri_str = format!("{}/api/v1/notification/{id}", configuration.base_path, id=p_path_id);
467    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
468
469    if let Some(ref param_value) = p_query_force_save {
470        req_builder = req_builder.query(&[("forceSave", &param_value.to_string())]);
471    }
472    if let Some(ref apikey) = configuration.api_key {
473        let key = apikey.key.clone();
474        let value = match apikey.prefix {
475            Some(ref prefix) => format!("{} {}", prefix, key),
476            None => key,
477        };
478        req_builder = req_builder.query(&[("apikey", value)]);
479    }
480    if let Some(ref user_agent) = configuration.user_agent {
481        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
482    }
483    if let Some(ref apikey) = configuration.api_key {
484        let key = apikey.key.clone();
485        let value = match apikey.prefix {
486            Some(ref prefix) => format!("{} {}", prefix, key),
487            None => key,
488        };
489        req_builder = req_builder.header("X-Api-Key", value);
490    };
491    req_builder = req_builder.json(&p_body_notification_resource);
492
493    let req = req_builder.build()?;
494    let resp = configuration.client.execute(req).await?;
495
496    let status = resp.status();
497    let content_type = resp
498        .headers()
499        .get("content-type")
500        .and_then(|v| v.to_str().ok())
501        .unwrap_or("application/octet-stream");
502    let content_type = super::ContentType::from(content_type);
503
504    if !status.is_client_error() && !status.is_server_error() {
505        let content = resp.text().await?;
506        match content_type {
507            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
508            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NotificationResource`"))),
509            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::NotificationResource`")))),
510        }
511    } else {
512        let content = resp.text().await?;
513        let entity: Option<UpdateNotificationError> = serde_json::from_str(&content).ok();
514        Err(Error::ResponseError(ResponseContent { status, content, entity }))
515    }
516}
517