sonarr_api_rs/apis/
ui_config_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_config_ui_get`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ApiV3ConfigUiGetError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`api_v3_config_ui_id_get`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum ApiV3ConfigUiIdGetError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`api_v3_config_ui_id_put`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum ApiV3ConfigUiIdPutError {
36    UnknownValue(serde_json::Value),
37}
38
39
40pub async fn api_v3_config_ui_get(configuration: &configuration::Configuration, ) -> Result<models::UiConfigResource, Error<ApiV3ConfigUiGetError>> {
41    let local_var_configuration = configuration;
42
43    let local_var_client = &local_var_configuration.client;
44
45    let local_var_uri_str = format!("{}/api/v3/config/ui", local_var_configuration.base_path);
46    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
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.query(&[("apikey", local_var_value)]);
55    }
56    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
57        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
58    }
59    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
60        let local_var_key = local_var_apikey.key.clone();
61        let local_var_value = match local_var_apikey.prefix {
62            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
63            None => local_var_key,
64        };
65        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
66    };
67
68    let local_var_req = local_var_req_builder.build()?;
69    let local_var_resp = local_var_client.execute(local_var_req).await?;
70
71    let local_var_status = local_var_resp.status();
72    let local_var_content = local_var_resp.text().await?;
73
74    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
75        serde_json::from_str(&local_var_content).map_err(Error::from)
76    } else {
77        let local_var_entity: Option<ApiV3ConfigUiGetError> = serde_json::from_str(&local_var_content).ok();
78        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
79        Err(Error::ResponseError(local_var_error))
80    }
81}
82
83pub async fn api_v3_config_ui_id_get(configuration: &configuration::Configuration, id: i32) -> Result<models::UiConfigResource, Error<ApiV3ConfigUiIdGetError>> {
84    let local_var_configuration = configuration;
85
86    let local_var_client = &local_var_configuration.client;
87
88    let local_var_uri_str = format!("{}/api/v3/config/ui/{id}", local_var_configuration.base_path, id=id);
89    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
90
91    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
92        let local_var_key = local_var_apikey.key.clone();
93        let local_var_value = match local_var_apikey.prefix {
94            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
95            None => local_var_key,
96        };
97        local_var_req_builder = local_var_req_builder.query(&[("apikey", local_var_value)]);
98    }
99    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
100        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
101    }
102    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
103        let local_var_key = local_var_apikey.key.clone();
104        let local_var_value = match local_var_apikey.prefix {
105            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
106            None => local_var_key,
107        };
108        local_var_req_builder = local_var_req_builder.header("X-Api-Key", local_var_value);
109    };
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        serde_json::from_str(&local_var_content).map_err(Error::from)
119    } else {
120        let local_var_entity: Option<ApiV3ConfigUiIdGetError> = 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_config_ui_id_put(configuration: &configuration::Configuration, id: &str, ui_config_resource: Option<models::UiConfigResource>) -> Result<models::UiConfigResource, Error<ApiV3ConfigUiIdPutError>> {
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/config/ui/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
132    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, 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    local_var_req_builder = local_var_req_builder.json(&ui_config_resource);
154
155    let local_var_req = local_var_req_builder.build()?;
156    let local_var_resp = local_var_client.execute(local_var_req).await?;
157
158    let local_var_status = local_var_resp.status();
159    let local_var_content = local_var_resp.text().await?;
160
161    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
162        serde_json::from_str(&local_var_content).map_err(Error::from)
163    } else {
164        let local_var_entity: Option<ApiV3ConfigUiIdPutError> = serde_json::from_str(&local_var_content).ok();
165        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
166        Err(Error::ResponseError(local_var_error))
167    }
168}
169