sonarr/apis/
parse_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.12.2823
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 [`get_parse`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetParseError {
22    UnknownValue(serde_json::Value),
23}
24
25
26pub async fn get_parse(configuration: &configuration::Configuration, title: Option<&str>, path: Option<&str>) -> Result<models::ParseResource, Error<GetParseError>> {
27    // add a prefix to parameters to efficiently prevent name collisions
28    let p_title = title;
29    let p_path = path;
30
31    let uri_str = format!("{}/api/v3/parse", configuration.base_path);
32    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
33
34    if let Some(ref param_value) = p_title {
35        req_builder = req_builder.query(&[("title", &param_value.to_string())]);
36    }
37    if let Some(ref param_value) = p_path {
38        req_builder = req_builder.query(&[("path", &param_value.to_string())]);
39    }
40    if let Some(ref apikey) = configuration.api_key {
41        let key = apikey.key.clone();
42        let value = match apikey.prefix {
43            Some(ref prefix) => format!("{} {}", prefix, key),
44            None => key,
45        };
46        req_builder = req_builder.query(&[("apikey", value)]);
47    }
48    if let Some(ref user_agent) = configuration.user_agent {
49        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
50    }
51    if let Some(ref apikey) = configuration.api_key {
52        let key = apikey.key.clone();
53        let value = match apikey.prefix {
54            Some(ref prefix) => format!("{} {}", prefix, key),
55            None => key,
56        };
57        req_builder = req_builder.header("X-Api-Key", value);
58    };
59
60    let req = req_builder.build()?;
61    let resp = configuration.client.execute(req).await?;
62
63    let status = resp.status();
64
65    if !status.is_client_error() && !status.is_server_error() {
66        let content = resp.text().await?;
67        serde_json::from_str(&content).map_err(Error::from)
68    } else {
69        let content = resp.text().await?;
70        let entity: Option<GetParseError> = serde_json::from_str(&content).ok();
71        Err(Error::ResponseError(ResponseContent { status, content, entity }))
72    }
73}
74