netbox_openapi/apis/
status_api.rs

1/*
2 * NetBox REST API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 4.4.2-Docker-3.4.1 (4.4)
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12
13use super::{Error, configuration};
14use crate::apis::ResponseContent;
15
16/// struct for typed errors of method [`status_retrieve`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum StatusRetrieveError {
20    UnknownValue(serde_json::Value),
21}
22
23/// A lightweight read-only endpoint for conveying NetBox's current operational status.
24pub async fn status_retrieve(
25    configuration: &configuration::Configuration,
26) -> Result<::std::collections::HashMap<String, serde_json::Value>, Error<StatusRetrieveError>> {
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/status/", local_var_configuration.base_path);
32    let mut local_var_req_builder =
33        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
34
35    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
36        local_var_req_builder =
37            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
38    }
39    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
40        let local_var_key = local_var_apikey.key.clone();
41        let local_var_value = match local_var_apikey.prefix {
42            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
43            None => local_var_key,
44        };
45        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
46    };
47
48    let local_var_req = local_var_req_builder.build()?;
49    let local_var_resp = local_var_client.execute(local_var_req).await?;
50
51    let local_var_status = local_var_resp.status();
52    let local_var_content = local_var_resp.text().await?;
53
54    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
55        serde_json::from_str(&local_var_content).map_err(Error::from)
56    } else {
57        let local_var_entity: Option<StatusRetrieveError> =
58            serde_json::from_str(&local_var_content).ok();
59        let local_var_error = ResponseContent {
60            status: local_var_status,
61            content: local_var_content,
62            entity: local_var_entity,
63        };
64        Err(Error::ResponseError(local_var_error))
65    }
66}