radarr_api_rs/apis/
api_info_api.rs

1/*
2 * Radarr
3 *
4 * Radarr API docs
5 *
6 * The version of the OpenAPI document: 3.0.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`api_get`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ApiGetError {
22    UnknownValue(serde_json::Value),
23}
24
25
26pub async fn api_get(configuration: &configuration::Configuration, ) -> Result<crate::models::ApiInfoResource, Error<ApiGetError>> {
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", 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_apikey) = local_var_configuration.api_key {
35        let local_var_key = local_var_apikey.key.clone();
36        let local_var_value = match local_var_apikey.prefix {
37            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
38            None => local_var_key,
39        };
40        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
41    }
42    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
43        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
44    }
45    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
46        let local_var_key = local_var_apikey.key.clone();
47        let local_var_value = match local_var_apikey.prefix {
48            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
49            None => local_var_key,
50        };
51        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
52    };
53
54    let local_var_req = local_var_req_builder.build()?;
55    let local_var_resp = local_var_client.execute(local_var_req).await?;
56
57    let local_var_status = local_var_resp.status();
58    let local_var_content = local_var_resp.text().await?;
59
60    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
61        serde_json::from_str(&local_var_content).map_err(Error::from)
62    } else {
63        let local_var_entity: Option<ApiGetError> = serde_json::from_str(&local_var_content).ok();
64        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
65        Err(Error::ResponseError(local_var_error))
66    }
67}
68