Skip to main content

nautobot_openapi/apis/
status_api.rs

1/*
2 * API Documentation
3 *
4 * Source of truth and network automation platform
5 *
6 * The version of the OpenAPI document: 3.1.0 (3.1)
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 the current operational status.
24pub async fn status_retrieve(
25    configuration: &configuration::Configuration,
26    format: Option<&str>,
27    depth: Option<i32>,
28    exclude_m2m: Option<bool>,
29) -> Result<crate::models::StatusRetrieve200Response, Error<StatusRetrieveError>> {
30    let local_var_configuration = configuration;
31
32    let local_var_client = &local_var_configuration.client;
33
34    let local_var_uri_str = format!("{}/status/", local_var_configuration.base_path);
35    let mut local_var_req_builder =
36        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
37
38    if let Some(ref local_var_str) = format {
39        local_var_req_builder =
40            local_var_req_builder.query(&[("format", &local_var_str.to_string())]);
41    }
42    if let Some(ref local_var_str) = depth {
43        local_var_req_builder =
44            local_var_req_builder.query(&[("depth", &local_var_str.to_string())]);
45    }
46    if let Some(ref local_var_str) = exclude_m2m {
47        local_var_req_builder =
48            local_var_req_builder.query(&[("exclude_m2m", &local_var_str.to_string())]);
49    }
50    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
51        local_var_req_builder =
52            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
53    }
54    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
55        let local_var_key = local_var_apikey.key.clone();
56        let local_var_value = match local_var_apikey.prefix {
57            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
58            None => local_var_key,
59        };
60        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
61    };
62
63    let local_var_req = local_var_req_builder.build()?;
64    let local_var_resp = local_var_client.execute(local_var_req).await?;
65
66    let local_var_status = local_var_resp.status();
67    let local_var_content = local_var_resp.text().await?;
68
69    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
70        serde_json::from_str(&local_var_content).map_err(Error::from)
71    } else {
72        let local_var_entity: Option<StatusRetrieveError> =
73            serde_json::from_str(&local_var_content).ok();
74        let local_var_error = ResponseContent {
75            status: local_var_status,
76            content: local_var_content,
77            entity: local_var_entity,
78        };
79        Err(Error::ResponseError(local_var_error))
80    }
81}