naurt_api/apis/
final_destination_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 FinaldestinationOptionsError {
22 UnknownValue(serde_json::Value),
23}
24
25#[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
77pub async fn finaldestination_post(configuration: &configuration::Configuration, final_destination_request: models::FinalDestinationRequest) -> Result<models::FinalDestinationResponse, Error<FinaldestinationPostError>> {
79 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