osdm_sys/apis/
booking_documents_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_documents`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateDocumentsError {
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 [`delete_bookings_documents_id`]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum DeleteBookingsDocumentsIdError {
39    Status400(models::Problem),
40    Status401(models::Problem),
41    Status403(models::Problem),
42    Status404(models::Problem),
43    Status406(models::Problem),
44    Status409(models::Problem),
45    Status415(models::Problem),
46    Status500(models::Problem),
47    Status501(models::Problem),
48    Status503(models::Problem),
49    DefaultResponse(models::Problem),
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`get_document`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetDocumentError {
57    Status400(models::Problem),
58    Status401(models::Problem),
59    Status403(models::Problem),
60    Status404(models::Problem),
61    Status406(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
71pub async fn create_documents(configuration: &configuration::Configuration, booking_id: &str, document_request: models::DocumentRequest, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>) -> Result<models::DocumentCollectionResponse, Error<CreateDocumentsError>> {
72    // add a prefix to parameters to efficiently prevent name collisions
73    let p_path_booking_id = booking_id;
74    let p_body_document_request = document_request;
75    let p_header_requestor = requestor;
76    let p_header_accept_language = accept_language;
77    let p_header_traceparent = traceparent;
78    let p_header_tracestate = tracestate;
79
80    let uri_str = format!("{}/bookings/{bookingId}/documents", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id));
81    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
82
83    if let Some(ref user_agent) = configuration.user_agent {
84        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
85    }
86    if let Some(param_value) = p_header_requestor {
87        req_builder = req_builder.header("Requestor", param_value.to_string());
88    }
89    if let Some(param_value) = p_header_accept_language {
90        req_builder = req_builder.header("Accept-Language", param_value.to_string());
91    }
92    if let Some(param_value) = p_header_traceparent {
93        req_builder = req_builder.header("traceparent", param_value.to_string());
94    }
95    if let Some(param_value) = p_header_tracestate {
96        req_builder = req_builder.header("tracestate", param_value.to_string());
97    }
98    if let Some(ref token) = configuration.oauth_access_token {
99        req_builder = req_builder.bearer_auth(token.to_owned());
100    };
101    req_builder = req_builder.json(&p_body_document_request);
102
103    let req = req_builder.build()?;
104    let resp = configuration.client.execute(req).await?;
105
106    let status = resp.status();
107    let content_type = resp
108        .headers()
109        .get("content-type")
110        .and_then(|v| v.to_str().ok())
111        .unwrap_or("application/octet-stream");
112    let content_type = super::ContentType::from(content_type);
113
114    if !status.is_client_error() && !status.is_server_error() {
115        let content = resp.text().await?;
116        match content_type {
117            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
118            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DocumentCollectionResponse`"))),
119            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::DocumentCollectionResponse`")))),
120        }
121    } else {
122        let content = resp.text().await?;
123        let entity: Option<CreateDocumentsError> = serde_json::from_str(&content).ok();
124        Err(Error::ResponseError(ResponseContent { status, content, entity }))
125    }
126}
127
128pub async fn delete_bookings_documents_id(configuration: &configuration::Configuration, booking_id: &str, document_id: &str, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>) -> Result<(), Error<DeleteBookingsDocumentsIdError>> {
129    // add a prefix to parameters to efficiently prevent name collisions
130    let p_path_booking_id = booking_id;
131    let p_path_document_id = document_id;
132    let p_header_requestor = requestor;
133    let p_header_accept_language = accept_language;
134    let p_header_traceparent = traceparent;
135    let p_header_tracestate = tracestate;
136
137    let uri_str = format!("{}/bookings/{bookingId}/documents/{documentId}", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id), documentId=crate::apis::urlencode(p_path_document_id));
138    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
139
140    if let Some(ref user_agent) = configuration.user_agent {
141        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
142    }
143    if let Some(param_value) = p_header_requestor {
144        req_builder = req_builder.header("Requestor", param_value.to_string());
145    }
146    if let Some(param_value) = p_header_accept_language {
147        req_builder = req_builder.header("Accept-Language", param_value.to_string());
148    }
149    if let Some(param_value) = p_header_traceparent {
150        req_builder = req_builder.header("traceparent", param_value.to_string());
151    }
152    if let Some(param_value) = p_header_tracestate {
153        req_builder = req_builder.header("tracestate", param_value.to_string());
154    }
155    if let Some(ref token) = configuration.oauth_access_token {
156        req_builder = req_builder.bearer_auth(token.to_owned());
157    };
158
159    let req = req_builder.build()?;
160    let resp = configuration.client.execute(req).await?;
161
162    let status = resp.status();
163
164    if !status.is_client_error() && !status.is_server_error() {
165        Ok(())
166    } else {
167        let content = resp.text().await?;
168        let entity: Option<DeleteBookingsDocumentsIdError> = serde_json::from_str(&content).ok();
169        Err(Error::ResponseError(ResponseContent { status, content, entity }))
170    }
171}
172
173/// booking documents found 
174pub async fn get_document(configuration: &configuration::Configuration, booking_id: &str, document_id: &str, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>) -> Result<models::DocumentResponse, Error<GetDocumentError>> {
175    // add a prefix to parameters to efficiently prevent name collisions
176    let p_path_booking_id = booking_id;
177    let p_path_document_id = document_id;
178    let p_header_requestor = requestor;
179    let p_header_accept_language = accept_language;
180    let p_header_traceparent = traceparent;
181    let p_header_tracestate = tracestate;
182
183    let uri_str = format!("{}/bookings/{bookingId}/documents/{documentId}", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id), documentId=crate::apis::urlencode(p_path_document_id));
184    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
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(ref token) = configuration.oauth_access_token {
202        req_builder = req_builder.bearer_auth(token.to_owned());
203    };
204
205    let req = req_builder.build()?;
206    let resp = configuration.client.execute(req).await?;
207
208    let status = resp.status();
209    let content_type = resp
210        .headers()
211        .get("content-type")
212        .and_then(|v| v.to_str().ok())
213        .unwrap_or("application/octet-stream");
214    let content_type = super::ContentType::from(content_type);
215
216    if !status.is_client_error() && !status.is_server_error() {
217        let content = resp.text().await?;
218        match content_type {
219            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
220            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DocumentResponse`"))),
221            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::DocumentResponse`")))),
222        }
223    } else {
224        let content = resp.text().await?;
225        let entity: Option<GetDocumentError> = serde_json::from_str(&content).ok();
226        Err(Error::ResponseError(ResponseContent { status, content, entity }))
227    }
228}
229