Skip to main content

osdm_sys/apis/
reimbursement_management_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_reimbursement`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateReimbursementError {
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_reimbursement`]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum GetReimbursementError {
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 [`update_reimbursement`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum UpdateReimbursementError {
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
71/// Create a reimbursement request for part of a booking. 
72pub async fn create_reimbursement(configuration: &configuration::Configuration, booking_id: &str, reimbursement_request: models::ReimbursementRequest, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>) -> Result<models::ReimbursementResponse, Error<CreateReimbursementError>> {
73    // add a prefix to parameters to efficiently prevent name collisions
74    let p_path_booking_id = booking_id;
75    let p_body_reimbursement_request = reimbursement_request;
76    let p_header_requestor = requestor;
77    let p_header_accept_language = accept_language;
78    let p_header_traceparent = traceparent;
79    let p_header_tracestate = tracestate;
80
81    let uri_str = format!("{}/bookings/{bookingId}/reimbursements", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id));
82    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
83
84    if let Some(ref user_agent) = configuration.user_agent {
85        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
86    }
87    if let Some(param_value) = p_header_requestor {
88        req_builder = req_builder.header("Requestor", param_value.to_string());
89    }
90    if let Some(param_value) = p_header_accept_language {
91        req_builder = req_builder.header("Accept-Language", param_value.to_string());
92    }
93    if let Some(param_value) = p_header_traceparent {
94        req_builder = req_builder.header("traceparent", param_value.to_string());
95    }
96    if let Some(param_value) = p_header_tracestate {
97        req_builder = req_builder.header("tracestate", param_value.to_string());
98    }
99    if let Some(ref token) = configuration.oauth_access_token {
100        req_builder = req_builder.bearer_auth(token.to_owned());
101    };
102    req_builder = req_builder.json(&p_body_reimbursement_request);
103
104    let req = req_builder.build()?;
105    let resp = configuration.client.execute(req).await?;
106
107    let status = resp.status();
108    let content_type = resp
109        .headers()
110        .get("content-type")
111        .and_then(|v| v.to_str().ok())
112        .unwrap_or("application/octet-stream");
113    let content_type = super::ContentType::from(content_type);
114
115    if !status.is_client_error() && !status.is_server_error() {
116        let content = resp.text().await?;
117        match content_type {
118            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
119            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ReimbursementResponse`"))),
120            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::ReimbursementResponse`")))),
121        }
122    } else {
123        let content = resp.text().await?;
124        let entity: Option<CreateReimbursementError> = serde_json::from_str(&content).ok();
125        Err(Error::ResponseError(ResponseContent { status, content, entity }))
126    }
127}
128
129/// Get reimbursement including its current state. 
130pub async fn get_reimbursement(configuration: &configuration::Configuration, booking_id: &str, reimbursement_id: &str, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>) -> Result<models::ReimbursementResponse, Error<GetReimbursementError>> {
131    // add a prefix to parameters to efficiently prevent name collisions
132    let p_path_booking_id = booking_id;
133    let p_path_reimbursement_id = reimbursement_id;
134    let p_header_requestor = requestor;
135    let p_header_accept_language = accept_language;
136    let p_header_traceparent = traceparent;
137    let p_header_tracestate = tracestate;
138
139    let uri_str = format!("{}/bookings/{bookingId}/reimbursements/{reimbursementId}", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id), reimbursementId=crate::apis::urlencode(p_path_reimbursement_id));
140    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
141
142    if let Some(ref user_agent) = configuration.user_agent {
143        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
144    }
145    if let Some(param_value) = p_header_requestor {
146        req_builder = req_builder.header("Requestor", param_value.to_string());
147    }
148    if let Some(param_value) = p_header_accept_language {
149        req_builder = req_builder.header("Accept-Language", param_value.to_string());
150    }
151    if let Some(param_value) = p_header_traceparent {
152        req_builder = req_builder.header("traceparent", param_value.to_string());
153    }
154    if let Some(param_value) = p_header_tracestate {
155        req_builder = req_builder.header("tracestate", param_value.to_string());
156    }
157    if let Some(ref token) = configuration.oauth_access_token {
158        req_builder = req_builder.bearer_auth(token.to_owned());
159    };
160
161    let req = req_builder.build()?;
162    let resp = configuration.client.execute(req).await?;
163
164    let status = resp.status();
165    let content_type = resp
166        .headers()
167        .get("content-type")
168        .and_then(|v| v.to_str().ok())
169        .unwrap_or("application/octet-stream");
170    let content_type = super::ContentType::from(content_type);
171
172    if !status.is_client_error() && !status.is_server_error() {
173        let content = resp.text().await?;
174        match content_type {
175            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
176            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ReimbursementResponse`"))),
177            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::ReimbursementResponse`")))),
178        }
179    } else {
180        let content = resp.text().await?;
181        let entity: Option<GetReimbursementError> = serde_json::from_str(&content).ok();
182        Err(Error::ResponseError(ResponseContent { status, content, entity }))
183    }
184}
185
186/// Update a reimbursement request, i.e add missing documents or change state. 
187pub async fn update_reimbursement(configuration: &configuration::Configuration, booking_id: &str, reimbursement_id: &str, reimbursement_patch_request: models::ReimbursementPatchRequest, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>) -> Result<models::ReimbursementResponse, Error<UpdateReimbursementError>> {
188    // add a prefix to parameters to efficiently prevent name collisions
189    let p_path_booking_id = booking_id;
190    let p_path_reimbursement_id = reimbursement_id;
191    let p_body_reimbursement_patch_request = reimbursement_patch_request;
192    let p_header_requestor = requestor;
193    let p_header_accept_language = accept_language;
194    let p_header_traceparent = traceparent;
195    let p_header_tracestate = tracestate;
196
197    let uri_str = format!("{}/bookings/{bookingId}/reimbursements/{reimbursementId}", configuration.base_path, bookingId=crate::apis::urlencode(p_path_booking_id), reimbursementId=crate::apis::urlencode(p_path_reimbursement_id));
198    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
199
200    if let Some(ref user_agent) = configuration.user_agent {
201        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
202    }
203    if let Some(param_value) = p_header_requestor {
204        req_builder = req_builder.header("Requestor", param_value.to_string());
205    }
206    if let Some(param_value) = p_header_accept_language {
207        req_builder = req_builder.header("Accept-Language", param_value.to_string());
208    }
209    if let Some(param_value) = p_header_traceparent {
210        req_builder = req_builder.header("traceparent", param_value.to_string());
211    }
212    if let Some(param_value) = p_header_tracestate {
213        req_builder = req_builder.header("tracestate", param_value.to_string());
214    }
215    if let Some(ref token) = configuration.oauth_access_token {
216        req_builder = req_builder.bearer_auth(token.to_owned());
217    };
218    req_builder = req_builder.json(&p_body_reimbursement_patch_request);
219
220    let req = req_builder.build()?;
221    let resp = configuration.client.execute(req).await?;
222
223    let status = resp.status();
224    let content_type = resp
225        .headers()
226        .get("content-type")
227        .and_then(|v| v.to_str().ok())
228        .unwrap_or("application/octet-stream");
229    let content_type = super::ContentType::from(content_type);
230
231    if !status.is_client_error() && !status.is_server_error() {
232        let content = resp.text().await?;
233        match content_type {
234            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
235            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ReimbursementResponse`"))),
236            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::ReimbursementResponse`")))),
237        }
238    } else {
239        let content = resp.text().await?;
240        let entity: Option<UpdateReimbursementError> = serde_json::from_str(&content).ok();
241        Err(Error::ResponseError(ResponseContent { status, content, entity }))
242    }
243}
244