Skip to main content

naurt_api/apis/
feedback_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 [`feedback_options`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum FeedbackOptionsError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`feedback_post`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum FeedbackPostError {
29    Status400(),
30    Status401(),
31    Status500(),
32    UnknownValue(serde_json::Value),
33}
34
35
36pub async fn feedback_options(configuration: &configuration::Configuration, ) -> Result<models::OptionsResponse, Error<FeedbackOptionsError>> {
37
38    let uri_str = format!("{}/feedback/v2", configuration.base_path);
39    let mut req_builder = configuration.client.request(reqwest::Method::OPTIONS, &uri_str);
40
41    if let Some(ref user_agent) = configuration.user_agent {
42        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
43    }
44    if let Some(ref apikey) = configuration.api_key {
45        let key = apikey.key.clone();
46        let value = match apikey.prefix {
47            Some(ref prefix) => format!("{} {}", prefix, key),
48            None => key,
49        };
50        req_builder = req_builder.header("Authorization", value);
51    };
52
53    let req = req_builder.build()?;
54    let resp = configuration.client.execute(req).await?;
55
56    let status = resp.status();
57    let content_type = resp
58        .headers()
59        .get("content-type")
60        .and_then(|v| v.to_str().ok())
61        .unwrap_or("application/octet-stream");
62    let content_type = super::ContentType::from(content_type);
63
64    if !status.is_client_error() && !status.is_server_error() {
65        let content = resp.text().await?;
66        match content_type {
67            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
68            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OptionsResponse`"))),
69            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`")))),
70        }
71    } else {
72        let content = resp.text().await?;
73        let entity: Option<FeedbackOptionsError> = serde_json::from_str(&content).ok();
74        Err(Error::ResponseError(ResponseContent { status, content, entity }))
75    }
76}
77
78/// Submit feedback to Naurt for address, parking location, or door location data.  This endpoint can be used to: - suggest corrections to existing Naurt address data - suggest improved parking locations - suggest improved door locations - provide new address records where parking or door data is not yet available  A valid API key is required. Feedback submissions do not count against API usage. 
79pub async fn feedback_post(configuration: &configuration::Configuration, feedback_request: models::FeedbackRequest) -> Result<models::FeedbackResponse, Error<FeedbackPostError>> {
80    // add a prefix to parameters to efficiently prevent name collisions
81    let p_body_feedback_request = feedback_request;
82
83    let uri_str = format!("{}/feedback/v2", configuration.base_path);
84    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
85
86    if let Some(ref user_agent) = configuration.user_agent {
87        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
88    }
89    if let Some(ref apikey) = configuration.api_key {
90        let key = apikey.key.clone();
91        let value = match apikey.prefix {
92            Some(ref prefix) => format!("{} {}", prefix, key),
93            None => key,
94        };
95        req_builder = req_builder.header("Authorization", value);
96    };
97    req_builder = req_builder.json(&p_body_feedback_request);
98
99    let req = req_builder.build()?;
100    let resp = configuration.client.execute(req).await?;
101
102    let status = resp.status();
103    let content_type = resp
104        .headers()
105        .get("content-type")
106        .and_then(|v| v.to_str().ok())
107        .unwrap_or("application/octet-stream");
108    let content_type = super::ContentType::from(content_type);
109
110    if !status.is_client_error() && !status.is_server_error() {
111        let content = resp.text().await?;
112        match content_type {
113            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
114            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FeedbackResponse`"))),
115            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::FeedbackResponse`")))),
116        }
117    } else {
118        let content = resp.text().await?;
119        let entity: Option<FeedbackPostError> = serde_json::from_str(&content).ok();
120        Err(Error::ResponseError(ResponseContent { status, content, entity }))
121    }
122}
123