Skip to main content

naurt_api/apis/
rendezvous_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 [`rendezvous_options`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum RendezvousOptionsError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`rendezvous_post`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum RendezvousPostError {
29    Status400(),
30    Status401(),
31    Status500(),
32    UnknownValue(serde_json::Value),
33}
34
35
36/// Returns the current API version and any deprecated versions. 
37pub async fn rendezvous_options(configuration: &configuration::Configuration, ) -> Result<models::OptionsResponse, Error<RendezvousOptionsError>> {
38
39    let uri_str = format!("{}/rendezvous/v1", configuration.base_path);
40    let mut req_builder = configuration.client.request(reqwest::Method::OPTIONS, &uri_str);
41
42    if let Some(ref user_agent) = configuration.user_agent {
43        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
44    }
45    if let Some(ref apikey) = configuration.api_key {
46        let key = apikey.key.clone();
47        let value = match apikey.prefix {
48            Some(ref prefix) => format!("{} {}", prefix, key),
49            None => key,
50        };
51        req_builder = req_builder.header("Authorization", value);
52    };
53
54    let req = req_builder.build()?;
55    let resp = configuration.client.execute(req).await?;
56
57    let status = resp.status();
58    let content_type = resp
59        .headers()
60        .get("content-type")
61        .and_then(|v| v.to_str().ok())
62        .unwrap_or("application/octet-stream");
63    let content_type = super::ContentType::from(content_type);
64
65    if !status.is_client_error() && !status.is_server_error() {
66        let content = resp.text().await?;
67        match content_type {
68            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
69            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OptionsResponse`"))),
70            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`")))),
71        }
72    } else {
73        let content = resp.text().await?;
74        let entity: Option<RendezvousOptionsError> = serde_json::from_str(&content).ok();
75        Err(Error::ResponseError(ResponseContent { status, content, entity }))
76    }
77}
78
79/// Rendezvous takes a list of queries, finds delivery clusters, and returns cluster centres plus the covered addresses for each cluster.  This is not a routing tool. It does not provide delivery order or route optimisation. 
80pub async fn rendezvous_post(configuration: &configuration::Configuration, rendezvous_request: models::RendezvousRequest) -> Result<models::RendezvousResponse, Error<RendezvousPostError>> {
81    // add a prefix to parameters to efficiently prevent name collisions
82    let p_body_rendezvous_request = rendezvous_request;
83
84    let uri_str = format!("{}/rendezvous/v1", configuration.base_path);
85    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
86
87    if let Some(ref user_agent) = configuration.user_agent {
88        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
89    }
90    if let Some(ref apikey) = configuration.api_key {
91        let key = apikey.key.clone();
92        let value = match apikey.prefix {
93            Some(ref prefix) => format!("{} {}", prefix, key),
94            None => key,
95        };
96        req_builder = req_builder.header("Authorization", value);
97    };
98    req_builder = req_builder.json(&p_body_rendezvous_request);
99
100    let req = req_builder.build()?;
101    let resp = configuration.client.execute(req).await?;
102
103    let status = resp.status();
104    let content_type = resp
105        .headers()
106        .get("content-type")
107        .and_then(|v| v.to_str().ok())
108        .unwrap_or("application/octet-stream");
109    let content_type = super::ContentType::from(content_type);
110
111    if !status.is_client_error() && !status.is_server_error() {
112        let content = resp.text().await?;
113        match content_type {
114            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
115            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RendezvousResponse`"))),
116            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::RendezvousResponse`")))),
117        }
118    } else {
119        let content = resp.text().await?;
120        let entity: Option<RendezvousPostError> = serde_json::from_str(&content).ok();
121        Err(Error::ResponseError(ResponseContent { status, content, entity }))
122    }
123}
124