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