osdm_sys/apis/
offers_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_offers`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateOffersError {
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 [`get_booking_booked_offers_additional_offers`]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum GetBookingBookedOffersAdditionalOffersError {
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 create_offers(configuration: &configuration::Configuration, offer_collection_request: models::OfferCollectionRequest, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>) -> Result<models::OfferCollectionResponse, Error<CreateOffersError>> {
54    // add a prefix to parameters to efficiently prevent name collisions
55    let p_body_offer_collection_request = offer_collection_request;
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
61    let uri_str = format!("{}/offers", configuration.base_path);
62    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
63
64    if let Some(ref user_agent) = configuration.user_agent {
65        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
66    }
67    if let Some(param_value) = p_header_requestor {
68        req_builder = req_builder.header("Requestor", param_value.to_string());
69    }
70    if let Some(param_value) = p_header_accept_language {
71        req_builder = req_builder.header("Accept-Language", param_value.to_string());
72    }
73    if let Some(param_value) = p_header_traceparent {
74        req_builder = req_builder.header("traceparent", param_value.to_string());
75    }
76    if let Some(param_value) = p_header_tracestate {
77        req_builder = req_builder.header("tracestate", param_value.to_string());
78    }
79    if let Some(ref token) = configuration.oauth_access_token {
80        req_builder = req_builder.bearer_auth(token.to_owned());
81    };
82    req_builder = req_builder.json(&p_body_offer_collection_request);
83
84    let req = req_builder.build()?;
85    let resp = configuration.client.execute(req).await?;
86
87    let status = resp.status();
88    let content_type = resp
89        .headers()
90        .get("content-type")
91        .and_then(|v| v.to_str().ok())
92        .unwrap_or("application/octet-stream");
93    let content_type = super::ContentType::from(content_type);
94
95    if !status.is_client_error() && !status.is_server_error() {
96        let content = resp.text().await?;
97        match content_type {
98            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
99            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OfferCollectionResponse`"))),
100            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::OfferCollectionResponse`")))),
101        }
102    } else {
103        let content = resp.text().await?;
104        let entity: Option<CreateOffersError> = serde_json::from_str(&content).ok();
105        Err(Error::ResponseError(ResponseContent { status, content, entity }))
106    }
107}
108
109pub async fn get_booking_booked_offers_additional_offers(configuration: &configuration::Configuration, booking_id: &str, booked_offer_id: &str, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, x_accept_namespace: Option<&str>) -> Result<models::AdditionalOfferCollectionResponse, Error<GetBookingBookedOffersAdditionalOffersError>> {
110    // add a prefix to parameters to efficiently prevent name collisions
111    let p_path_booking_id = booking_id;
112    let p_path_booked_offer_id = booked_offer_id;
113    let p_header_requestor = requestor;
114    let p_header_accept_language = accept_language;
115    let p_header_traceparent = traceparent;
116    let p_header_tracestate = tracestate;
117    let p_header_x_accept_namespace = x_accept_namespace;
118
119    let uri_str = format!("{}/bookings/{bookingId}/booked-offers/{bookedOfferId}/additional-offers", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id), bookedOfferId=crate::apis::urlencode(p_path_booked_offer_id));
120    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
121
122    if let Some(ref user_agent) = configuration.user_agent {
123        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
124    }
125    if let Some(param_value) = p_header_requestor {
126        req_builder = req_builder.header("Requestor", param_value.to_string());
127    }
128    if let Some(param_value) = p_header_accept_language {
129        req_builder = req_builder.header("Accept-Language", param_value.to_string());
130    }
131    if let Some(param_value) = p_header_traceparent {
132        req_builder = req_builder.header("traceparent", param_value.to_string());
133    }
134    if let Some(param_value) = p_header_tracestate {
135        req_builder = req_builder.header("tracestate", param_value.to_string());
136    }
137    if let Some(param_value) = p_header_x_accept_namespace {
138        req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
139    }
140    if let Some(ref token) = configuration.oauth_access_token {
141        req_builder = req_builder.bearer_auth(token.to_owned());
142    };
143
144    let req = req_builder.build()?;
145    let resp = configuration.client.execute(req).await?;
146
147    let status = resp.status();
148    let content_type = resp
149        .headers()
150        .get("content-type")
151        .and_then(|v| v.to_str().ok())
152        .unwrap_or("application/octet-stream");
153    let content_type = super::ContentType::from(content_type);
154
155    if !status.is_client_error() && !status.is_server_error() {
156        let content = resp.text().await?;
157        match content_type {
158            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
159            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AdditionalOfferCollectionResponse`"))),
160            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::AdditionalOfferCollectionResponse`")))),
161        }
162    } else {
163        let content = resp.text().await?;
164        let entity: Option<GetBookingBookedOffersAdditionalOffersError> = serde_json::from_str(&content).ok();
165        Err(Error::ResponseError(ResponseContent { status, content, entity }))
166    }
167}
168