sonarr_api_rs/apis/
release_push_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_release_push_post`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ApiV3ReleasePushPostError {
22    UnknownValue(serde_json::Value),
23}
24
25
26pub async fn api_v3_release_push_post(configuration: &configuration::Configuration, release_resource: Option<models::ReleaseResource>) -> Result<Vec<models::ReleaseResource>, Error<ApiV3ReleasePushPostError>> {
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/release/push", local_var_configuration.base_path);
32    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, 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    local_var_req_builder = local_var_req_builder.json(&release_resource);
54
55    let local_var_req = local_var_req_builder.build()?;
56    let local_var_resp = local_var_client.execute(local_var_req).await?;
57
58    let local_var_status = local_var_resp.status();
59    let local_var_content = local_var_resp.text().await?;
60
61    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
62        serde_json::from_str(&local_var_content).map_err(Error::from)
63    } else {
64        let local_var_entity: Option<ApiV3ReleasePushPostError> = serde_json::from_str(&local_var_content).ok();
65        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
66        Err(Error::ResponseError(local_var_error))
67    }
68}
69