naurt_api/apis/
rendezvous_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 RendezvousOptionsError {
22 UnknownValue(serde_json::Value),
23}
24
25#[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
36pub 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
79pub async fn rendezvous_post(configuration: &configuration::Configuration, rendezvous_request: models::RendezvousRequest) -> Result<models::RendezvousResponse, Error<RendezvousPostError>> {
81 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