osdm_sys/apis/
places_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 GetPlacesIdError {
22 Status400(models::Problem),
23 Status401(models::Problem),
24 Status403(models::Problem),
25 Status404(models::Problem),
26 Status406(models::Problem),
27 Status415(models::Problem),
28 Status500(models::Problem),
29 Status501(models::Problem),
30 Status503(models::Problem),
31 DefaultResponse(models::Problem),
32 UnknownValue(serde_json::Value),
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum PostPlacesError {
39 Status400(models::Problem),
40 Status401(models::Problem),
41 Status403(models::Problem),
42 Status404(models::Problem),
43 Status406(models::Problem),
44 Status415(models::Problem),
45 Status500(models::Problem),
46 Status501(models::Problem),
47 Status503(models::Problem),
48 DefaultResponse(models::Problem),
49 UnknownValue(serde_json::Value),
50}
51
52
53pub async fn get_places_id(configuration: &configuration::Configuration, place_id: &str, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, x_accept_namespace: Option<&str>) -> Result<models::PlaceResponse, Error<GetPlacesIdError>> {
54 let p_path_place_id = place_id;
56 let p_header_requestor = requestor;
57 let p_header_accept_language = accept_language;
58 let p_header_traceparent = traceparent;
59 let p_header_tracestate = tracestate;
60 let p_header_x_accept_namespace = x_accept_namespace;
61
62 let uri_str = format!("{}/places/{placeId}", configuration.base_path, placeId=crate::apis::urlencode(p_path_place_id));
63 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
64
65 if let Some(ref user_agent) = configuration.user_agent {
66 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
67 }
68 if let Some(param_value) = p_header_requestor {
69 req_builder = req_builder.header("Requestor", param_value.to_string());
70 }
71 if let Some(param_value) = p_header_accept_language {
72 req_builder = req_builder.header("Accept-Language", param_value.to_string());
73 }
74 if let Some(param_value) = p_header_traceparent {
75 req_builder = req_builder.header("traceparent", param_value.to_string());
76 }
77 if let Some(param_value) = p_header_tracestate {
78 req_builder = req_builder.header("tracestate", param_value.to_string());
79 }
80 if let Some(param_value) = p_header_x_accept_namespace {
81 req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
82 }
83 if let Some(ref token) = configuration.oauth_access_token {
84 req_builder = req_builder.bearer_auth(token.to_owned());
85 };
86
87 let req = req_builder.build()?;
88 let resp = configuration.client.execute(req).await?;
89
90 let status = resp.status();
91 let content_type = resp
92 .headers()
93 .get("content-type")
94 .and_then(|v| v.to_str().ok())
95 .unwrap_or("application/octet-stream");
96 let content_type = super::ContentType::from(content_type);
97
98 if !status.is_client_error() && !status.is_server_error() {
99 let content = resp.text().await?;
100 match content_type {
101 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
102 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PlaceResponse`"))),
103 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::PlaceResponse`")))),
104 }
105 } else {
106 let content = resp.text().await?;
107 let entity: Option<GetPlacesIdError> = serde_json::from_str(&content).ok();
108 Err(Error::ResponseError(ResponseContent { status, content, entity }))
109 }
110}
111
112pub async fn post_places(configuration: &configuration::Configuration, place_request: models::PlaceRequest, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, x_accept_namespace: Option<&str>) -> Result<models::PlaceResponse, Error<PostPlacesError>> {
114 let p_body_place_request = place_request;
116 let p_header_requestor = requestor;
117 let p_header_accept_language = accept_language;
118 let p_header_traceparent = traceparent;
119 let p_header_tracestate = tracestate;
120 let p_header_x_accept_namespace = x_accept_namespace;
121
122 let uri_str = format!("{}/places", configuration.base_path);
123 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
124
125 if let Some(ref user_agent) = configuration.user_agent {
126 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
127 }
128 if let Some(param_value) = p_header_requestor {
129 req_builder = req_builder.header("Requestor", param_value.to_string());
130 }
131 if let Some(param_value) = p_header_accept_language {
132 req_builder = req_builder.header("Accept-Language", param_value.to_string());
133 }
134 if let Some(param_value) = p_header_traceparent {
135 req_builder = req_builder.header("traceparent", param_value.to_string());
136 }
137 if let Some(param_value) = p_header_tracestate {
138 req_builder = req_builder.header("tracestate", param_value.to_string());
139 }
140 if let Some(param_value) = p_header_x_accept_namespace {
141 req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
142 }
143 if let Some(ref token) = configuration.oauth_access_token {
144 req_builder = req_builder.bearer_auth(token.to_owned());
145 };
146 req_builder = req_builder.json(&p_body_place_request);
147
148 let req = req_builder.build()?;
149 let resp = configuration.client.execute(req).await?;
150
151 let status = resp.status();
152 let content_type = resp
153 .headers()
154 .get("content-type")
155 .and_then(|v| v.to_str().ok())
156 .unwrap_or("application/octet-stream");
157 let content_type = super::ContentType::from(content_type);
158
159 if !status.is_client_error() && !status.is_server_error() {
160 let content = resp.text().await?;
161 match content_type {
162 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
163 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PlaceResponse`"))),
164 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::PlaceResponse`")))),
165 }
166 } else {
167 let content = resp.text().await?;
168 let entity: Option<PostPlacesError> = serde_json::from_str(&content).ok();
169 Err(Error::ResponseError(ResponseContent { status, content, entity }))
170 }
171}
172