geoengine_api_client/apis/
plots_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 GetPlotHandlerError {
22 UnknownValue(serde_json::Value),
23}
24
25
26pub async fn get_plot_handler(configuration: &configuration::Configuration, bbox: &str, time: &str, spatial_resolution: &str, id: &str, crs: Option<&str>) -> Result<models::WrappedPlotOutput, Error<GetPlotHandlerError>> {
28 let p_query_bbox = bbox;
30 let p_query_time = time;
31 let p_query_spatial_resolution = spatial_resolution;
32 let p_path_id = id;
33 let p_query_crs = crs;
34
35 let uri_str = format!("{}/plot/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
36 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
37
38 req_builder = req_builder.query(&[("bbox", &p_query_bbox.to_string())]);
39 if let Some(ref param_value) = p_query_crs {
40 req_builder = req_builder.query(&[("crs", ¶m_value.to_string())]);
41 }
42 req_builder = req_builder.query(&[("time", &p_query_time.to_string())]);
43 req_builder = req_builder.query(&[("spatialResolution", &p_query_spatial_resolution.to_string())]);
44 if let Some(ref user_agent) = configuration.user_agent {
45 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
46 }
47 if let Some(ref token) = configuration.bearer_access_token {
48 req_builder = req_builder.bearer_auth(token.to_owned());
49 };
50
51 let req = req_builder.build()?;
52 let resp = configuration.client.execute(req).await?;
53
54 let status = resp.status();
55 let content_type = resp
56 .headers()
57 .get("content-type")
58 .and_then(|v| v.to_str().ok())
59 .unwrap_or("application/octet-stream");
60 let content_type = super::ContentType::from(content_type);
61
62 if !status.is_client_error() && !status.is_server_error() {
63 let content = resp.text().await?;
64 match content_type {
65 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
66 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::WrappedPlotOutput`"))),
67 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::WrappedPlotOutput`")))),
68 }
69 } else {
70 let content = resp.text().await?;
71 let entity: Option<GetPlotHandlerError> = serde_json::from_str(&content).ok();
72 Err(Error::ResponseError(ResponseContent { status, content, entity }))
73 }
74}
75