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