1use 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 GetTripsCollectionIdError {
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 GetTripsIdError {
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#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum PostTripsError {
56 Status400(models::Problem),
57 Status401(models::Problem),
58 Status403(models::Problem),
59 Status404(models::Problem),
60 Status406(models::Problem),
61 Status415(models::Problem),
62 Status500(models::Problem),
63 Status501(models::Problem),
64 Status503(models::Problem),
65 DefaultResponse(models::Problem),
66 UnknownValue(serde_json::Value),
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum PostTripsChangeError {
73 Status400(models::Problem),
74 Status401(models::Problem),
75 Status403(models::Problem),
76 Status404(models::Problem),
77 Status406(models::Problem),
78 Status415(models::Problem),
79 Status500(models::Problem),
80 Status501(models::Problem),
81 Status503(models::Problem),
82 DefaultResponse(models::Problem),
83 UnknownValue(serde_json::Value),
84}
85
86
87pub async fn get_trips_collection_id(configuration: &configuration::Configuration, trips_collection_id: &str, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, x_accept_namespace: Option<&str>, stop_behavior: Option<models::StopBehavior>, page: Option<&str>, embed: Option<Vec<models::TripsCollectionResponseContent>>) -> Result<models::TripCollectionResponse, Error<GetTripsCollectionIdError>> {
89 let p_path_trips_collection_id = trips_collection_id;
91 let p_header_requestor = requestor;
92 let p_header_accept_language = accept_language;
93 let p_header_traceparent = traceparent;
94 let p_header_tracestate = tracestate;
95 let p_header_x_accept_namespace = x_accept_namespace;
96 let p_query_stop_behavior = stop_behavior;
97 let p_query_page = page;
98 let p_query_embed = embed;
99
100 let uri_str = format!("{}/trips-collections/{tripsCollectionId}", configuration.base_path, tripsCollectionId=crate::apis::urlencode(p_path_trips_collection_id));
101 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
102
103 if let Some(ref param_value) = p_query_stop_behavior {
104 req_builder = req_builder.query(&[("stopBehavior", ¶m_value.to_string())]);
105 }
106 if let Some(ref param_value) = p_query_page {
107 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
108 }
109 if let Some(ref param_value) = p_query_embed {
110 req_builder = match "multi" {
111 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("embed".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
112 _ => req_builder.query(&[("embed", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
113 };
114 }
115 if let Some(ref user_agent) = configuration.user_agent {
116 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
117 }
118 if let Some(param_value) = p_header_requestor {
119 req_builder = req_builder.header("Requestor", param_value.to_string());
120 }
121 if let Some(param_value) = p_header_accept_language {
122 req_builder = req_builder.header("Accept-Language", param_value.to_string());
123 }
124 if let Some(param_value) = p_header_traceparent {
125 req_builder = req_builder.header("traceparent", param_value.to_string());
126 }
127 if let Some(param_value) = p_header_tracestate {
128 req_builder = req_builder.header("tracestate", param_value.to_string());
129 }
130 if let Some(param_value) = p_header_x_accept_namespace {
131 req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
132 }
133 if let Some(ref token) = configuration.oauth_access_token {
134 req_builder = req_builder.bearer_auth(token.to_owned());
135 };
136
137 let req = req_builder.build()?;
138 let resp = configuration.client.execute(req).await?;
139
140 let status = resp.status();
141 let content_type = resp
142 .headers()
143 .get("content-type")
144 .and_then(|v| v.to_str().ok())
145 .unwrap_or("application/octet-stream");
146 let content_type = super::ContentType::from(content_type);
147
148 if !status.is_client_error() && !status.is_server_error() {
149 let content = resp.text().await?;
150 match content_type {
151 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
152 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TripCollectionResponse`"))),
153 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::TripCollectionResponse`")))),
154 }
155 } else {
156 let content = resp.text().await?;
157 let entity: Option<GetTripsCollectionIdError> = serde_json::from_str(&content).ok();
158 Err(Error::ResponseError(ResponseContent { status, content, entity }))
159 }
160}
161
162pub async fn get_trips_id(configuration: &configuration::Configuration, trip_id: &str, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, x_accept_namespace: Option<&str>, stop_behavior: Option<models::StopBehavior>, embed: Option<Vec<models::TripResponseContent>>) -> Result<models::TripResponse, Error<GetTripsIdError>> {
164 let p_path_trip_id = trip_id;
166 let p_header_requestor = requestor;
167 let p_header_accept_language = accept_language;
168 let p_header_traceparent = traceparent;
169 let p_header_tracestate = tracestate;
170 let p_header_x_accept_namespace = x_accept_namespace;
171 let p_query_stop_behavior = stop_behavior;
172 let p_query_embed = embed;
173
174 let uri_str = format!("{}/trips/{tripId}", configuration.base_path, tripId=crate::apis::urlencode(p_path_trip_id));
175 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
176
177 if let Some(ref param_value) = p_query_stop_behavior {
178 req_builder = req_builder.query(&[("stopBehavior", ¶m_value.to_string())]);
179 }
180 if let Some(ref param_value) = p_query_embed {
181 req_builder = match "multi" {
182 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("embed".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
183 _ => req_builder.query(&[("embed", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
184 };
185 }
186 if let Some(ref user_agent) = configuration.user_agent {
187 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
188 }
189 if let Some(param_value) = p_header_requestor {
190 req_builder = req_builder.header("Requestor", param_value.to_string());
191 }
192 if let Some(param_value) = p_header_accept_language {
193 req_builder = req_builder.header("Accept-Language", param_value.to_string());
194 }
195 if let Some(param_value) = p_header_traceparent {
196 req_builder = req_builder.header("traceparent", param_value.to_string());
197 }
198 if let Some(param_value) = p_header_tracestate {
199 req_builder = req_builder.header("tracestate", param_value.to_string());
200 }
201 if let Some(param_value) = p_header_x_accept_namespace {
202 req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
203 }
204 if let Some(ref token) = configuration.oauth_access_token {
205 req_builder = req_builder.bearer_auth(token.to_owned());
206 };
207
208 let req = req_builder.build()?;
209 let resp = configuration.client.execute(req).await?;
210
211 let status = resp.status();
212 let content_type = resp
213 .headers()
214 .get("content-type")
215 .and_then(|v| v.to_str().ok())
216 .unwrap_or("application/octet-stream");
217 let content_type = super::ContentType::from(content_type);
218
219 if !status.is_client_error() && !status.is_server_error() {
220 let content = resp.text().await?;
221 match content_type {
222 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
223 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TripResponse`"))),
224 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::TripResponse`")))),
225 }
226 } else {
227 let content = resp.text().await?;
228 let entity: Option<GetTripsIdError> = serde_json::from_str(&content).ok();
229 Err(Error::ResponseError(ResponseContent { status, content, entity }))
230 }
231}
232
233pub async fn post_trips(configuration: &configuration::Configuration, trip_search_criteria: models::TripSearchCriteria, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, x_accept_namespace: Option<&str>, stop_behavior: Option<models::StopBehavior>) -> Result<models::TripCollectionResponse, Error<PostTripsError>> {
235 let p_body_trip_search_criteria = trip_search_criteria;
237 let p_header_requestor = requestor;
238 let p_header_accept_language = accept_language;
239 let p_header_traceparent = traceparent;
240 let p_header_tracestate = tracestate;
241 let p_header_x_accept_namespace = x_accept_namespace;
242 let p_query_stop_behavior = stop_behavior;
243
244 let uri_str = format!("{}/trips-collection", configuration.base_path);
245 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
246
247 if let Some(ref param_value) = p_query_stop_behavior {
248 req_builder = req_builder.query(&[("stopBehavior", ¶m_value.to_string())]);
249 }
250 if let Some(ref user_agent) = configuration.user_agent {
251 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
252 }
253 if let Some(param_value) = p_header_requestor {
254 req_builder = req_builder.header("Requestor", param_value.to_string());
255 }
256 if let Some(param_value) = p_header_accept_language {
257 req_builder = req_builder.header("Accept-Language", param_value.to_string());
258 }
259 if let Some(param_value) = p_header_traceparent {
260 req_builder = req_builder.header("traceparent", param_value.to_string());
261 }
262 if let Some(param_value) = p_header_tracestate {
263 req_builder = req_builder.header("tracestate", param_value.to_string());
264 }
265 if let Some(param_value) = p_header_x_accept_namespace {
266 req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
267 }
268 if let Some(ref token) = configuration.oauth_access_token {
269 req_builder = req_builder.bearer_auth(token.to_owned());
270 };
271 req_builder = req_builder.json(&p_body_trip_search_criteria);
272
273 let req = req_builder.build()?;
274 let resp = configuration.client.execute(req).await?;
275
276 let status = resp.status();
277 let content_type = resp
278 .headers()
279 .get("content-type")
280 .and_then(|v| v.to_str().ok())
281 .unwrap_or("application/octet-stream");
282 let content_type = super::ContentType::from(content_type);
283
284 if !status.is_client_error() && !status.is_server_error() {
285 let content = resp.text().await?;
286 match content_type {
287 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
288 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TripCollectionResponse`"))),
289 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::TripCollectionResponse`")))),
290 }
291 } else {
292 let content = resp.text().await?;
293 let entity: Option<PostTripsError> = serde_json::from_str(&content).ok();
294 Err(Error::ResponseError(ResponseContent { status, content, entity }))
295 }
296}
297
298pub async fn post_trips_change(configuration: &configuration::Configuration, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, stop_behavior: Option<models::StopBehavior>, trip_change_criteria: Option<models::TripChangeCriteria>) -> Result<models::TripResponse, Error<PostTripsChangeError>> {
300 let p_header_requestor = requestor;
302 let p_header_accept_language = accept_language;
303 let p_header_traceparent = traceparent;
304 let p_header_tracestate = tracestate;
305 let p_query_stop_behavior = stop_behavior;
306 let p_body_trip_change_criteria = trip_change_criteria;
307
308 let uri_str = format!("{}/trips", configuration.base_path);
309 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
310
311 if let Some(ref param_value) = p_query_stop_behavior {
312 req_builder = req_builder.query(&[("stopBehavior", ¶m_value.to_string())]);
313 }
314 if let Some(ref user_agent) = configuration.user_agent {
315 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
316 }
317 if let Some(param_value) = p_header_requestor {
318 req_builder = req_builder.header("Requestor", param_value.to_string());
319 }
320 if let Some(param_value) = p_header_accept_language {
321 req_builder = req_builder.header("Accept-Language", param_value.to_string());
322 }
323 if let Some(param_value) = p_header_traceparent {
324 req_builder = req_builder.header("traceparent", param_value.to_string());
325 }
326 if let Some(param_value) = p_header_tracestate {
327 req_builder = req_builder.header("tracestate", param_value.to_string());
328 }
329 if let Some(ref token) = configuration.oauth_access_token {
330 req_builder = req_builder.bearer_auth(token.to_owned());
331 };
332 req_builder = req_builder.json(&p_body_trip_change_criteria);
333
334 let req = req_builder.build()?;
335 let resp = configuration.client.execute(req).await?;
336
337 let status = resp.status();
338 let content_type = resp
339 .headers()
340 .get("content-type")
341 .and_then(|v| v.to_str().ok())
342 .unwrap_or("application/octet-stream");
343 let content_type = super::ContentType::from(content_type);
344
345 if !status.is_client_error() && !status.is_server_error() {
346 let content = resp.text().await?;
347 match content_type {
348 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
349 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TripResponse`"))),
350 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::TripResponse`")))),
351 }
352 } else {
353 let content = resp.text().await?;
354 let entity: Option<PostTripsChangeError> = serde_json::from_str(&content).ok();
355 Err(Error::ResponseError(ResponseContent { status, content, entity }))
356 }
357}
358