Skip to main content

clientapi_pbs/apis/
misc_api.rs

1/*
2 * Proxmox Backup Server API
3 *
4 * Generated from apidoc.js. NOT an official Proxmox specification. See https://pbs.proxmox.com/docs/api-viewer/ for the upstream documentation.
5 *
6 * The version of the OpenAPI document: 9.x
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`misc_get`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum MiscGetError {
22    Status400(models::PbsError),
23    Status401(models::PbsError),
24    Status403(models::PbsError),
25    Status404(models::PbsError),
26    Status500(models::PbsError),
27    Status501(models::PbsError),
28    Status503(models::PbsError),
29    UnknownValue(serde_json::Value),
30}
31
32
33/// Directory index.
34pub async fn misc_get(configuration: &configuration::Configuration, ) -> Result<models::MiscGetResponse, Error<MiscGetError>> {
35
36    let uri_str = format!("{}/", configuration.base_path);
37    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
38
39    if let Some(ref user_agent) = configuration.user_agent {
40        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
41    }
42    if let Some(ref apikey) = configuration.api_key {
43        let key = apikey.key.clone();
44        let value = match apikey.prefix {
45            Some(ref prefix) => format!("{} {}", prefix, key),
46            None => key,
47        };
48        req_builder = req_builder.header("Authorization", value);
49    };
50    if let Some(ref apikey) = configuration.api_key {
51        let key = apikey.key.clone();
52        let value = match apikey.prefix {
53            Some(ref prefix) => format!("{} {}", prefix, key),
54            None => key,
55        };
56        req_builder = req_builder.header("CSRFPreventionToken", value);
57    };
58
59    let req = req_builder.build()?;
60    let resp = configuration.client.execute(req).await?;
61
62    let status = resp.status();
63    let content_type = resp
64        .headers()
65        .get("content-type")
66        .and_then(|v| v.to_str().ok())
67        .unwrap_or("application/octet-stream");
68    let content_type = super::ContentType::from(content_type);
69
70    if !status.is_client_error() && !status.is_server_error() {
71        let content = resp.text().await?;
72        match content_type {
73            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
74            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MiscGetResponse`"))),
75            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MiscGetResponse`")))),
76        }
77    } else {
78        let content = resp.text().await?;
79        let entity: Option<MiscGetError> = serde_json::from_str(&content).ok();
80        Err(Error::ResponseError(ResponseContent { status, content, entity }))
81    }
82}
83