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