osdm_sys/apis/
bookings_split_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 [`split_bookings`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum SplitBookingsError {
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
36/// Splits a booking into a set of bookings according to the defined groups of a passenger(s). Only possible if allowed by the underlying tariff, if the bookedOffers are sufficiently partitioned and no pricing is needed. 
37pub async fn split_bookings(configuration: &configuration::Configuration, booking_id: &str, booking_split_request: models::BookingSplitRequest, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, idempotency_key: Option<&str>) -> Result<models::BookingSplitResponse, Error<SplitBookingsError>> {
38    // add a prefix to parameters to efficiently prevent name collisions
39    let p_path_booking_id = booking_id;
40    let p_body_booking_split_request = booking_split_request;
41    let p_header_requestor = requestor;
42    let p_header_accept_language = accept_language;
43    let p_header_traceparent = traceparent;
44    let p_header_tracestate = tracestate;
45    let p_header_idempotency_key = idempotency_key;
46
47    let uri_str = format!("{}/bookings/{bookingId}/split", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id));
48    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
49
50    if let Some(ref user_agent) = configuration.user_agent {
51        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
52    }
53    if let Some(param_value) = p_header_requestor {
54        req_builder = req_builder.header("Requestor", param_value.to_string());
55    }
56    if let Some(param_value) = p_header_accept_language {
57        req_builder = req_builder.header("Accept-Language", param_value.to_string());
58    }
59    if let Some(param_value) = p_header_traceparent {
60        req_builder = req_builder.header("traceparent", param_value.to_string());
61    }
62    if let Some(param_value) = p_header_tracestate {
63        req_builder = req_builder.header("tracestate", param_value.to_string());
64    }
65    if let Some(param_value) = p_header_idempotency_key {
66        req_builder = req_builder.header("Idempotency-Key", param_value.to_string());
67    }
68    if let Some(ref token) = configuration.oauth_access_token {
69        req_builder = req_builder.bearer_auth(token.to_owned());
70    };
71    req_builder = req_builder.json(&p_body_booking_split_request);
72
73    let req = req_builder.build()?;
74    let resp = configuration.client.execute(req).await?;
75
76    let status = resp.status();
77    let content_type = resp
78        .headers()
79        .get("content-type")
80        .and_then(|v| v.to_str().ok())
81        .unwrap_or("application/octet-stream");
82    let content_type = super::ContentType::from(content_type);
83
84    if !status.is_client_error() && !status.is_server_error() {
85        let content = resp.text().await?;
86        match content_type {
87            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
88            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BookingSplitResponse`"))),
89            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::BookingSplitResponse`")))),
90        }
91    } else {
92        let content = resp.text().await?;
93        let entity: Option<SplitBookingsError> = serde_json::from_str(&content).ok();
94        Err(Error::ResponseError(ResponseContent { status, content, entity }))
95    }
96}
97