Skip to main content

naurt_api/apis/
final_destination_api.rs

1/*
2 * Naurt API
3 *
4 * OpenAPI specification for Naurt's APIs. 
5 *
6 * The version of the OpenAPI document: 0.1.2
7 * 
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 [`finaldestination_options`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum FinaldestinationOptionsError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`finaldestination_post`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum FinaldestinationPostError {
29    Status4XX(models::ErrorResponse),
30    Status5XX(models::ErrorResponse),
31    UnknownValue(serde_json::Value),
32}
33
34
35pub async fn finaldestination_options(configuration: &configuration::Configuration, ) -> Result<models::OptionsResponse, Error<FinaldestinationOptionsError>> {
36
37    let uri_str = format!("{}/final-destination/v2", configuration.base_path);
38    let mut req_builder = configuration.client.request(reqwest::Method::OPTIONS, &uri_str);
39
40    if let Some(ref user_agent) = configuration.user_agent {
41        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
42    }
43    if let Some(ref apikey) = configuration.api_key {
44        let key = apikey.key.clone();
45        let value = match apikey.prefix {
46            Some(ref prefix) => format!("{} {}", prefix, key),
47            None => key,
48        };
49        req_builder = req_builder.header("Authorization", value);
50    };
51
52    let req = req_builder.build()?;
53    let resp = configuration.client.execute(req).await?;
54
55    let status = resp.status();
56    let content_type = resp
57        .headers()
58        .get("content-type")
59        .and_then(|v| v.to_str().ok())
60        .unwrap_or("application/octet-stream");
61    let content_type = super::ContentType::from(content_type);
62
63    if !status.is_client_error() && !status.is_server_error() {
64        let content = resp.text().await?;
65        match content_type {
66            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
67            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OptionsResponse`"))),
68            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::OptionsResponse`")))),
69        }
70    } else {
71        let content = resp.text().await?;
72        let entity: Option<FinaldestinationOptionsError> = serde_json::from_str(&content).ok();
73        Err(Error::ResponseError(ResponseContent { status, content, entity }))
74    }
75}
76
77/// Query the Naurt Final Destination dataset to retrieve precise destination locations for addresses, buildings, entrances, and parking locations.  Each request contains one or more `queries`. A query can represent several different search types supported by the Final Destination API:  • Forward geocoding — supply an `address_string` or `address_structured`   • Reverse geocoding — supply a `location` with latitude and longitude   • Naurt ID lookup — supply an `id` returned from a previous query   • Source ID lookup — supply identifiers such as `os_uprn`    The API returns a best match for each query along with optional additional matches. Results may include multiple destination geometries such as building entrances, delivery doors, or parking locations depending on available data.  The geometry format returned by the API is controlled by `options.geojson_type`:  • `geojson` (default) — results are returned as standard GeoJSON   FeatureCollections with geometries and properties.  • `key_value` — results are returned as a simplified key/value representation   where each destination type contains latitude and longitude coordinates.  Each query result includes a status, the best match, optional additional matches, and metadata such as distance from the search location when applicable. 
78pub async fn finaldestination_post(configuration: &configuration::Configuration, final_destination_request: models::FinalDestinationRequest) -> Result<models::FinalDestinationResponse, Error<FinaldestinationPostError>> {
79    // add a prefix to parameters to efficiently prevent name collisions
80    let p_body_final_destination_request = final_destination_request;
81
82    let uri_str = format!("{}/final-destination/v2", configuration.base_path);
83    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
84
85    if let Some(ref user_agent) = configuration.user_agent {
86        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
87    }
88    if let Some(ref apikey) = configuration.api_key {
89        let key = apikey.key.clone();
90        let value = match apikey.prefix {
91            Some(ref prefix) => format!("{} {}", prefix, key),
92            None => key,
93        };
94        req_builder = req_builder.header("Authorization", value);
95    };
96    req_builder = req_builder.json(&p_body_final_destination_request);
97
98    let req = req_builder.build()?;
99    let resp = configuration.client.execute(req).await?;
100
101    let status = resp.status();
102    let content_type = resp
103        .headers()
104        .get("content-type")
105        .and_then(|v| v.to_str().ok())
106        .unwrap_or("application/octet-stream");
107    let content_type = super::ContentType::from(content_type);
108
109    if !status.is_client_error() && !status.is_server_error() {
110        let content = resp.text().await?;
111        match content_type {
112            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
113            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FinalDestinationResponse`"))),
114            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::FinalDestinationResponse`")))),
115        }
116    } else {
117        let content = resp.text().await?;
118        let entity: Option<FinaldestinationPostError> = serde_json::from_str(&content).ok();
119        Err(Error::ResponseError(ResponseContent { status, content, entity }))
120    }
121}
122