osdm_sys/apis/
exchange_api.rs

1/*
2 * UIC 90918-10 - OSDM
3 *
4 * Specifications for the OSDM API standard. The OSDM specification supports two modes of operation: Retailer Mode and Distributor Mode. The API works identically in both modes, except that in distributor mode the API also returns fare information.  The following resources are key to get started:    -  [Processes](https://osdm.io/spec/processes/)   -  [Models](https://osdm.io/spec/models/)   -  [Getting started](https://osdm.io/spec/getting-started/) 
5 *
6 * The version of the OpenAPI document: 3.7.0
7 * Contact: osdm@uic.org
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 [`create_bookings_exchange_operations`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateBookingsExchangeOperationsError {
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/// struct for typed errors of method [`create_exchange_offers_collection`]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum CreateExchangeOffersCollectionError {
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/// struct for typed errors of method [`delete_bookings_exchange_operation`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum DeleteBookingsExchangeOperationError {
56    Status400(models::Problem),
57    Status401(models::Problem),
58    Status403(models::Problem),
59    Status404(models::Problem),
60    Status406(models::Problem),
61    Status409(models::Problem),
62    Status415(models::Problem),
63    Status500(models::Problem),
64    Status501(models::Problem),
65    Status503(models::Problem),
66    DefaultResponse(models::Problem),
67    UnknownValue(serde_json::Value),
68}
69
70/// struct for typed errors of method [`get_bookings_exchange_operations`]
71#[derive(Debug, Clone, Serialize, Deserialize)]
72#[serde(untagged)]
73pub enum GetBookingsExchangeOperationsError {
74    Status400(models::Problem),
75    Status401(models::Problem),
76    Status403(models::Problem),
77    Status404(models::Problem),
78    Status406(models::Problem),
79    Status415(models::Problem),
80    Status500(models::Problem),
81    Status501(models::Problem),
82    Status503(models::Problem),
83    DefaultResponse(models::Problem),
84    UnknownValue(serde_json::Value),
85}
86
87/// struct for typed errors of method [`update_bookings_exchange_operations`]
88#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum UpdateBookingsExchangeOperationsError {
91    Status400(models::Problem),
92    Status401(models::Problem),
93    Status403(models::Problem),
94    Status404(models::Problem),
95    Status406(models::Problem),
96    Status409(models::Problem),
97    Status415(models::Problem),
98    Status500(models::Problem),
99    Status501(models::Problem),
100    Status503(models::Problem),
101    DefaultResponse(models::Problem),
102    UnknownValue(serde_json::Value),
103}
104
105
106pub async fn create_bookings_exchange_operations(configuration: &configuration::Configuration, booking_id: &str, exchange_operation_request: models::ExchangeOperationRequest, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, idempotency_key: Option<&str>, x_accept_namespace: Option<&str>) -> Result<models::ExchangeOperationResponse, Error<CreateBookingsExchangeOperationsError>> {
107    // add a prefix to parameters to efficiently prevent name collisions
108    let p_path_booking_id = booking_id;
109    let p_body_exchange_operation_request = exchange_operation_request;
110    let p_header_requestor = requestor;
111    let p_header_accept_language = accept_language;
112    let p_header_traceparent = traceparent;
113    let p_header_tracestate = tracestate;
114    let p_header_idempotency_key = idempotency_key;
115    let p_header_x_accept_namespace = x_accept_namespace;
116
117    let uri_str = format!("{}/bookings/{bookingId}/exchange-operations", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id));
118    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
119
120    if let Some(ref user_agent) = configuration.user_agent {
121        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
122    }
123    if let Some(param_value) = p_header_requestor {
124        req_builder = req_builder.header("Requestor", param_value.to_string());
125    }
126    if let Some(param_value) = p_header_accept_language {
127        req_builder = req_builder.header("Accept-Language", param_value.to_string());
128    }
129    if let Some(param_value) = p_header_traceparent {
130        req_builder = req_builder.header("traceparent", param_value.to_string());
131    }
132    if let Some(param_value) = p_header_tracestate {
133        req_builder = req_builder.header("tracestate", param_value.to_string());
134    }
135    if let Some(param_value) = p_header_idempotency_key {
136        req_builder = req_builder.header("Idempotency-Key", param_value.to_string());
137    }
138    if let Some(param_value) = p_header_x_accept_namespace {
139        req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
140    }
141    if let Some(ref token) = configuration.oauth_access_token {
142        req_builder = req_builder.bearer_auth(token.to_owned());
143    };
144    req_builder = req_builder.json(&p_body_exchange_operation_request);
145
146    let req = req_builder.build()?;
147    let resp = configuration.client.execute(req).await?;
148
149    let status = resp.status();
150    let content_type = resp
151        .headers()
152        .get("content-type")
153        .and_then(|v| v.to_str().ok())
154        .unwrap_or("application/octet-stream");
155    let content_type = super::ContentType::from(content_type);
156
157    if !status.is_client_error() && !status.is_server_error() {
158        let content = resp.text().await?;
159        match content_type {
160            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
161            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ExchangeOperationResponse`"))),
162            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::ExchangeOperationResponse`")))),
163        }
164    } else {
165        let content = resp.text().await?;
166        let entity: Option<CreateBookingsExchangeOperationsError> = serde_json::from_str(&content).ok();
167        Err(Error::ResponseError(ResponseContent { status, content, entity }))
168    }
169}
170
171/// Returns exchange offers for specified fulfillments submitted given requested new trip characteristics. 
172pub async fn create_exchange_offers_collection(configuration: &configuration::Configuration, booking_id: &str, embed: models::ExchangeOfferCollectionResponseContent, exchange_offer_collection_request: models::ExchangeOfferCollectionRequest, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, idempotency_key: Option<&str>) -> Result<models::ExchangeOfferCollectionResponse, Error<CreateExchangeOffersCollectionError>> {
173    // add a prefix to parameters to efficiently prevent name collisions
174    let p_path_booking_id = booking_id;
175    let p_query_embed = embed;
176    let p_body_exchange_offer_collection_request = exchange_offer_collection_request;
177    let p_header_requestor = requestor;
178    let p_header_accept_language = accept_language;
179    let p_header_traceparent = traceparent;
180    let p_header_tracestate = tracestate;
181    let p_header_idempotency_key = idempotency_key;
182
183    let uri_str = format!("{}/bookings/{bookingId}/exchange-offers", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id));
184    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
185
186    req_builder = req_builder.query(&[("embed", &p_query_embed.to_string())]);
187    if let Some(ref user_agent) = configuration.user_agent {
188        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
189    }
190    if let Some(param_value) = p_header_requestor {
191        req_builder = req_builder.header("Requestor", param_value.to_string());
192    }
193    if let Some(param_value) = p_header_accept_language {
194        req_builder = req_builder.header("Accept-Language", param_value.to_string());
195    }
196    if let Some(param_value) = p_header_traceparent {
197        req_builder = req_builder.header("traceparent", param_value.to_string());
198    }
199    if let Some(param_value) = p_header_tracestate {
200        req_builder = req_builder.header("tracestate", param_value.to_string());
201    }
202    if let Some(param_value) = p_header_idempotency_key {
203        req_builder = req_builder.header("Idempotency-Key", param_value.to_string());
204    }
205    if let Some(ref token) = configuration.oauth_access_token {
206        req_builder = req_builder.bearer_auth(token.to_owned());
207    };
208    req_builder = req_builder.json(&p_body_exchange_offer_collection_request);
209
210    let req = req_builder.build()?;
211    let resp = configuration.client.execute(req).await?;
212
213    let status = resp.status();
214    let content_type = resp
215        .headers()
216        .get("content-type")
217        .and_then(|v| v.to_str().ok())
218        .unwrap_or("application/octet-stream");
219    let content_type = super::ContentType::from(content_type);
220
221    if !status.is_client_error() && !status.is_server_error() {
222        let content = resp.text().await?;
223        match content_type {
224            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
225            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ExchangeOfferCollectionResponse`"))),
226            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::ExchangeOfferCollectionResponse`")))),
227        }
228    } else {
229        let content = resp.text().await?;
230        let entity: Option<CreateExchangeOffersCollectionError> = serde_json::from_str(&content).ok();
231        Err(Error::ResponseError(ResponseContent { status, content, entity }))
232    }
233}
234
235pub async fn delete_bookings_exchange_operation(configuration: &configuration::Configuration, booking_id: &str, exchange_operation_id: &str, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>) -> Result<(), Error<DeleteBookingsExchangeOperationError>> {
236    // add a prefix to parameters to efficiently prevent name collisions
237    let p_path_booking_id = booking_id;
238    let p_path_exchange_operation_id = exchange_operation_id;
239    let p_header_requestor = requestor;
240    let p_header_accept_language = accept_language;
241    let p_header_traceparent = traceparent;
242    let p_header_tracestate = tracestate;
243
244    let uri_str = format!("{}/bookings/{bookingId}/exchange-operations/{exchangeOperationId}", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id), exchangeOperationId=crate::apis::urlencode(p_path_exchange_operation_id));
245    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
246
247    if let Some(ref user_agent) = configuration.user_agent {
248        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
249    }
250    if let Some(param_value) = p_header_requestor {
251        req_builder = req_builder.header("Requestor", param_value.to_string());
252    }
253    if let Some(param_value) = p_header_accept_language {
254        req_builder = req_builder.header("Accept-Language", param_value.to_string());
255    }
256    if let Some(param_value) = p_header_traceparent {
257        req_builder = req_builder.header("traceparent", param_value.to_string());
258    }
259    if let Some(param_value) = p_header_tracestate {
260        req_builder = req_builder.header("tracestate", param_value.to_string());
261    }
262    if let Some(ref token) = configuration.oauth_access_token {
263        req_builder = req_builder.bearer_auth(token.to_owned());
264    };
265
266    let req = req_builder.build()?;
267    let resp = configuration.client.execute(req).await?;
268
269    let status = resp.status();
270
271    if !status.is_client_error() && !status.is_server_error() {
272        Ok(())
273    } else {
274        let content = resp.text().await?;
275        let entity: Option<DeleteBookingsExchangeOperationError> = serde_json::from_str(&content).ok();
276        Err(Error::ResponseError(ResponseContent { status, content, entity }))
277    }
278}
279
280/// Returns the exchange operation with the id provided. It may be a provisional or a confirmed exchange. 
281pub async fn get_bookings_exchange_operations(configuration: &configuration::Configuration, booking_id: &str, exchange_operation_id: &str, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, x_accept_namespace: Option<&str>, embed: Option<Vec<models::ExchangeOperationResponseContent>>) -> Result<models::ExchangeOperationResponse, Error<GetBookingsExchangeOperationsError>> {
282    // add a prefix to parameters to efficiently prevent name collisions
283    let p_path_booking_id = booking_id;
284    let p_path_exchange_operation_id = exchange_operation_id;
285    let p_header_requestor = requestor;
286    let p_header_accept_language = accept_language;
287    let p_header_traceparent = traceparent;
288    let p_header_tracestate = tracestate;
289    let p_header_x_accept_namespace = x_accept_namespace;
290    let p_query_embed = embed;
291
292    let uri_str = format!("{}/bookings/{bookingId}/exchange-operations/{exchangeOperationId}", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id), exchangeOperationId=crate::apis::urlencode(p_path_exchange_operation_id));
293    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
294
295    if let Some(ref param_value) = p_query_embed {
296        req_builder = match "multi" {
297            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("embed".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
298            _ => req_builder.query(&[("embed", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
299        };
300    }
301    if let Some(ref user_agent) = configuration.user_agent {
302        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
303    }
304    if let Some(param_value) = p_header_requestor {
305        req_builder = req_builder.header("Requestor", param_value.to_string());
306    }
307    if let Some(param_value) = p_header_accept_language {
308        req_builder = req_builder.header("Accept-Language", param_value.to_string());
309    }
310    if let Some(param_value) = p_header_traceparent {
311        req_builder = req_builder.header("traceparent", param_value.to_string());
312    }
313    if let Some(param_value) = p_header_tracestate {
314        req_builder = req_builder.header("tracestate", param_value.to_string());
315    }
316    if let Some(param_value) = p_header_x_accept_namespace {
317        req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
318    }
319    if let Some(ref token) = configuration.oauth_access_token {
320        req_builder = req_builder.bearer_auth(token.to_owned());
321    };
322
323    let req = req_builder.build()?;
324    let resp = configuration.client.execute(req).await?;
325
326    let status = resp.status();
327    let content_type = resp
328        .headers()
329        .get("content-type")
330        .and_then(|v| v.to_str().ok())
331        .unwrap_or("application/octet-stream");
332    let content_type = super::ContentType::from(content_type);
333
334    if !status.is_client_error() && !status.is_server_error() {
335        let content = resp.text().await?;
336        match content_type {
337            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
338            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ExchangeOperationResponse`"))),
339            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::ExchangeOperationResponse`")))),
340        }
341    } else {
342        let content = resp.text().await?;
343        let entity: Option<GetBookingsExchangeOperationsError> = serde_json::from_str(&content).ok();
344        Err(Error::ResponseError(ResponseContent { status, content, entity }))
345    }
346}
347
348pub async fn update_bookings_exchange_operations(configuration: &configuration::Configuration, booking_id: &str, exchange_operation_id: &str, exchange_operation_patch_request: models::ExchangeOperationPatchRequest, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, idempotency_key: Option<&str>, x_accept_namespace: Option<&str>) -> Result<models::ExchangeOperationResponse, Error<UpdateBookingsExchangeOperationsError>> {
349    // add a prefix to parameters to efficiently prevent name collisions
350    let p_path_booking_id = booking_id;
351    let p_path_exchange_operation_id = exchange_operation_id;
352    let p_body_exchange_operation_patch_request = exchange_operation_patch_request;
353    let p_header_requestor = requestor;
354    let p_header_accept_language = accept_language;
355    let p_header_traceparent = traceparent;
356    let p_header_tracestate = tracestate;
357    let p_header_idempotency_key = idempotency_key;
358    let p_header_x_accept_namespace = x_accept_namespace;
359
360    let uri_str = format!("{}/bookings/{bookingId}/exchange-operations/{exchangeOperationId}", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id), exchangeOperationId=crate::apis::urlencode(p_path_exchange_operation_id));
361    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
362
363    if let Some(ref user_agent) = configuration.user_agent {
364        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
365    }
366    if let Some(param_value) = p_header_requestor {
367        req_builder = req_builder.header("Requestor", param_value.to_string());
368    }
369    if let Some(param_value) = p_header_accept_language {
370        req_builder = req_builder.header("Accept-Language", param_value.to_string());
371    }
372    if let Some(param_value) = p_header_traceparent {
373        req_builder = req_builder.header("traceparent", param_value.to_string());
374    }
375    if let Some(param_value) = p_header_tracestate {
376        req_builder = req_builder.header("tracestate", param_value.to_string());
377    }
378    if let Some(param_value) = p_header_idempotency_key {
379        req_builder = req_builder.header("Idempotency-Key", param_value.to_string());
380    }
381    if let Some(param_value) = p_header_x_accept_namespace {
382        req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
383    }
384    if let Some(ref token) = configuration.oauth_access_token {
385        req_builder = req_builder.bearer_auth(token.to_owned());
386    };
387    req_builder = req_builder.json(&p_body_exchange_operation_patch_request);
388
389    let req = req_builder.build()?;
390    let resp = configuration.client.execute(req).await?;
391
392    let status = resp.status();
393    let content_type = resp
394        .headers()
395        .get("content-type")
396        .and_then(|v| v.to_str().ok())
397        .unwrap_or("application/octet-stream");
398    let content_type = super::ContentType::from(content_type);
399
400    if !status.is_client_error() && !status.is_server_error() {
401        let content = resp.text().await?;
402        match content_type {
403            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
404            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ExchangeOperationResponse`"))),
405            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::ExchangeOperationResponse`")))),
406        }
407    } else {
408        let content = resp.text().await?;
409        let entity: Option<UpdateBookingsExchangeOperationsError> = serde_json::from_str(&content).ok();
410        Err(Error::ResponseError(ResponseContent { status, content, entity }))
411    }
412}
413