sonarr_api_rs/apis/
series_lookup_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_series_lookup_get`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ApiV3SeriesLookupGetError {
22    UnknownValue(serde_json::Value),
23}
24
25
26pub async fn api_v3_series_lookup_get(configuration: &configuration::Configuration, term: Option<&str>) -> Result<(), Error<ApiV3SeriesLookupGetError>> {
27    let local_var_configuration = configuration;
28
29    let local_var_client = &local_var_configuration.client;
30
31    let local_var_uri_str = format!("{}/api/v3/series/lookup", local_var_configuration.base_path);
32    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
33
34    if let Some(ref local_var_str) = term {
35        local_var_req_builder = local_var_req_builder.query(&[("term", &local_var_str.to_string())]);
36    }
37    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
38        let local_var_key = local_var_apikey.key.clone();
39        let local_var_value = match local_var_apikey.prefix {
40            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
41            None => local_var_key,
42        };
43        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
44    }
45    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
46        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
47    }
48    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
49        let local_var_key = local_var_apikey.key.clone();
50        let local_var_value = match local_var_apikey.prefix {
51            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
52            None => local_var_key,
53        };
54        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
55    };
56
57    let local_var_req = local_var_req_builder.build()?;
58    let local_var_resp = local_var_client.execute(local_var_req).await?;
59
60    let local_var_status = local_var_resp.status();
61    let local_var_content = local_var_resp.text().await?;
62
63    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
64        Ok(())
65    } else {
66        let local_var_entity: Option<ApiV3SeriesLookupGetError> = serde_json::from_str(&local_var_content).ok();
67        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
68        Err(Error::ResponseError(local_var_error))
69    }
70}
71