Skip to main content

geoengine_api_client/apis/
general_api.rs

1/*
2 * Geo Engine API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * Contact: dev@geoengine.de
7 * Generated by: https://openapi-generator.tech
8 */
9
10
11use reqwest;
12use serde::{Deserialize, Serialize, de::Error as _};
13use crate::{apis::ResponseContent, models};
14use super::{Error, configuration, ContentType};
15
16
17/// struct for typed errors of method [`available_handler`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum AvailableHandlerError {
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`server_info_handler`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum ServerInfoHandlerError {
28    UnknownValue(serde_json::Value),
29}
30
31
32pub async fn available_handler(configuration: &configuration::Configuration, ) -> Result<(), Error<AvailableHandlerError>> {
33
34    let uri_str = format!("{}/available", configuration.base_path);
35    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
36
37    if let Some(ref user_agent) = configuration.user_agent {
38        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
39    }
40
41    let req = req_builder.build()?;
42    let resp = configuration.client.execute(req).await?;
43
44    let status = resp.status();
45
46    if !status.is_client_error() && !status.is_server_error() {
47        Ok(())
48    } else {
49        let content = resp.text().await?;
50        let entity: Option<AvailableHandlerError> = serde_json::from_str(&content).ok();
51        Err(Error::ResponseError(ResponseContent { status, content, entity }))
52    }
53}
54
55pub async fn server_info_handler(configuration: &configuration::Configuration, ) -> Result<models::ServerInfo, Error<ServerInfoHandlerError>> {
56
57    let uri_str = format!("{}/info", configuration.base_path);
58    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
59
60    if let Some(ref user_agent) = configuration.user_agent {
61        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
62    }
63
64    let req = req_builder.build()?;
65    let resp = configuration.client.execute(req).await?;
66
67    let status = resp.status();
68    let content_type = resp
69        .headers()
70        .get("content-type")
71        .and_then(|v| v.to_str().ok())
72        .unwrap_or("application/octet-stream");
73    let content_type = super::ContentType::from(content_type);
74
75    if !status.is_client_error() && !status.is_server_error() {
76        let content = resp.text().await?;
77        match content_type {
78            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
79            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ServerInfo`"))),
80            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::ServerInfo`")))),
81        }
82    } else {
83        let content = resp.text().await?;
84        let entity: Option<ServerInfoHandlerError> = serde_json::from_str(&content).ok();
85        Err(Error::ResponseError(ResponseContent { status, content, entity }))
86    }
87}
88