Skip to main content

geoengine_api_client/apis/
plots_api.rs

1/*
2 * Geo Engine API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 0.9.0
7 * Contact: dev@geoengine.de
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`get_plot_handler`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetPlotHandlerError {
22    UnknownValue(serde_json::Value),
23}
24
25
26/// # Example  1. Upload the file `plain_data.csv` with the following content:  ```csv a 1 2 ``` 2. Create a dataset from it using the \"Plain Data\" example at `/dataset`. 3. Create a statistics workflow using the \"Statistics Plot\" example at `/workflow`. 4. Generate the plot with this handler.
27pub 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    // add a prefix to parameters to efficiently prevent name collisions
29    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", &param_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