osdm_sys/apis/
product_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 [`get_product_tags`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetProductTagsError {
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_products`]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum GetProductsError {
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 [`get_products_id`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum GetProductsIdError {
56    Status400(models::Problem),
57    Status401(models::Problem),
58    Status403(models::Problem),
59    Status404(models::Problem),
60    Status406(models::Problem),
61    Status415(models::Problem),
62    Status500(models::Problem),
63    Status501(models::Problem),
64    Status503(models::Problem),
65    DefaultResponse(models::Problem),
66    UnknownValue(serde_json::Value),
67}
68
69/// struct for typed errors of method [`search_products`]
70#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum SearchProductsError {
73    Status400(models::Problem),
74    Status401(models::Problem),
75    Status403(models::Problem),
76    Status404(models::Problem),
77    Status406(models::Problem),
78    Status415(models::Problem),
79    Status500(models::Problem),
80    Status501(models::Problem),
81    Status503(models::Problem),
82    DefaultResponse(models::Problem),
83    UnknownValue(serde_json::Value),
84}
85
86
87pub async fn get_product_tags(configuration: &configuration::Configuration, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, x_accept_namespace: Option<&str>) -> Result<models::ProductTagsResponse, Error<GetProductTagsError>> {
88    // add a prefix to parameters to efficiently prevent name collisions
89    let p_header_requestor = requestor;
90    let p_header_accept_language = accept_language;
91    let p_header_traceparent = traceparent;
92    let p_header_tracestate = tracestate;
93    let p_header_x_accept_namespace = x_accept_namespace;
94
95    let uri_str = format!("{}/product-tags", configuration.base_path);
96    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
97
98    if let Some(ref user_agent) = configuration.user_agent {
99        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
100    }
101    if let Some(param_value) = p_header_requestor {
102        req_builder = req_builder.header("Requestor", param_value.to_string());
103    }
104    if let Some(param_value) = p_header_accept_language {
105        req_builder = req_builder.header("Accept-Language", param_value.to_string());
106    }
107    if let Some(param_value) = p_header_traceparent {
108        req_builder = req_builder.header("traceparent", param_value.to_string());
109    }
110    if let Some(param_value) = p_header_tracestate {
111        req_builder = req_builder.header("tracestate", param_value.to_string());
112    }
113    if let Some(param_value) = p_header_x_accept_namespace {
114        req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
115    }
116    if let Some(ref token) = configuration.oauth_access_token {
117        req_builder = req_builder.bearer_auth(token.to_owned());
118    };
119
120    let req = req_builder.build()?;
121    let resp = configuration.client.execute(req).await?;
122
123    let status = resp.status();
124    let content_type = resp
125        .headers()
126        .get("content-type")
127        .and_then(|v| v.to_str().ok())
128        .unwrap_or("application/octet-stream");
129    let content_type = super::ContentType::from(content_type);
130
131    if !status.is_client_error() && !status.is_server_error() {
132        let content = resp.text().await?;
133        match content_type {
134            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
135            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ProductTagsResponse`"))),
136            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::ProductTagsResponse`")))),
137        }
138    } else {
139        let content = resp.text().await?;
140        let entity: Option<GetProductTagsError> = serde_json::from_str(&content).ok();
141        Err(Error::ResponseError(ResponseContent { status, content, entity }))
142    }
143}
144
145pub async fn get_products(configuration: &configuration::Configuration, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, x_accept_namespace: Option<&str>, page: Option<&str>, product_code: Option<&str>, issuing_date: Option<String>, travel_date: Option<String>) -> Result<models::ProductCollectionResponse, Error<GetProductsError>> {
146    // add a prefix to parameters to efficiently prevent name collisions
147    let p_header_requestor = requestor;
148    let p_header_accept_language = accept_language;
149    let p_header_traceparent = traceparent;
150    let p_header_tracestate = tracestate;
151    let p_header_x_accept_namespace = x_accept_namespace;
152    let p_query_page = page;
153    let p_query_product_code = product_code;
154    let p_query_issuing_date = issuing_date;
155    let p_query_travel_date = travel_date;
156
157    let uri_str = format!("{}/products", configuration.base_path);
158    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
159
160    if let Some(ref param_value) = p_query_page {
161        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
162    }
163    if let Some(ref param_value) = p_query_product_code {
164        req_builder = req_builder.query(&[("productCode", &param_value.to_string())]);
165    }
166    if let Some(ref param_value) = p_query_issuing_date {
167        req_builder = req_builder.query(&[("issuingDate", &param_value.to_string())]);
168    }
169    if let Some(ref param_value) = p_query_travel_date {
170        req_builder = req_builder.query(&[("travelDate", &param_value.to_string())]);
171    }
172    if let Some(ref user_agent) = configuration.user_agent {
173        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
174    }
175    if let Some(param_value) = p_header_requestor {
176        req_builder = req_builder.header("Requestor", param_value.to_string());
177    }
178    if let Some(param_value) = p_header_accept_language {
179        req_builder = req_builder.header("Accept-Language", param_value.to_string());
180    }
181    if let Some(param_value) = p_header_traceparent {
182        req_builder = req_builder.header("traceparent", param_value.to_string());
183    }
184    if let Some(param_value) = p_header_tracestate {
185        req_builder = req_builder.header("tracestate", param_value.to_string());
186    }
187    if let Some(param_value) = p_header_x_accept_namespace {
188        req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
189    }
190    if let Some(ref token) = configuration.oauth_access_token {
191        req_builder = req_builder.bearer_auth(token.to_owned());
192    };
193
194    let req = req_builder.build()?;
195    let resp = configuration.client.execute(req).await?;
196
197    let status = resp.status();
198    let content_type = resp
199        .headers()
200        .get("content-type")
201        .and_then(|v| v.to_str().ok())
202        .unwrap_or("application/octet-stream");
203    let content_type = super::ContentType::from(content_type);
204
205    if !status.is_client_error() && !status.is_server_error() {
206        let content = resp.text().await?;
207        match content_type {
208            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
209            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ProductCollectionResponse`"))),
210            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::ProductCollectionResponse`")))),
211        }
212    } else {
213        let content = resp.text().await?;
214        let entity: Option<GetProductsError> = serde_json::from_str(&content).ok();
215        Err(Error::ResponseError(ResponseContent { status, content, entity }))
216    }
217}
218
219pub async fn get_products_id(configuration: &configuration::Configuration, product_id: &str, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, x_accept_namespace: Option<&str>) -> Result<models::ProductResponse, Error<GetProductsIdError>> {
220    // add a prefix to parameters to efficiently prevent name collisions
221    let p_path_product_id = product_id;
222    let p_header_requestor = requestor;
223    let p_header_accept_language = accept_language;
224    let p_header_traceparent = traceparent;
225    let p_header_tracestate = tracestate;
226    let p_header_x_accept_namespace = x_accept_namespace;
227
228    let uri_str = format!("{}/products/{productId}", configuration.base_path, productId=crate::apis::urlencode(p_path_product_id));
229    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
230
231    if let Some(ref user_agent) = configuration.user_agent {
232        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
233    }
234    if let Some(param_value) = p_header_requestor {
235        req_builder = req_builder.header("Requestor", param_value.to_string());
236    }
237    if let Some(param_value) = p_header_accept_language {
238        req_builder = req_builder.header("Accept-Language", param_value.to_string());
239    }
240    if let Some(param_value) = p_header_traceparent {
241        req_builder = req_builder.header("traceparent", param_value.to_string());
242    }
243    if let Some(param_value) = p_header_tracestate {
244        req_builder = req_builder.header("tracestate", param_value.to_string());
245    }
246    if let Some(param_value) = p_header_x_accept_namespace {
247        req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
248    }
249    if let Some(ref token) = configuration.oauth_access_token {
250        req_builder = req_builder.bearer_auth(token.to_owned());
251    };
252
253    let req = req_builder.build()?;
254    let resp = configuration.client.execute(req).await?;
255
256    let status = resp.status();
257    let content_type = resp
258        .headers()
259        .get("content-type")
260        .and_then(|v| v.to_str().ok())
261        .unwrap_or("application/octet-stream");
262    let content_type = super::ContentType::from(content_type);
263
264    if !status.is_client_error() && !status.is_server_error() {
265        let content = resp.text().await?;
266        match content_type {
267            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
268            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ProductResponse`"))),
269            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::ProductResponse`")))),
270        }
271    } else {
272        let content = resp.text().await?;
273        let entity: Option<GetProductsIdError> = serde_json::from_str(&content).ok();
274        Err(Error::ResponseError(ResponseContent { status, content, entity }))
275    }
276}
277
278pub 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>> {
279    // add a prefix to parameters to efficiently prevent name collisions
280    let p_body_product_search_request = product_search_request;
281    let p_header_requestor = requestor;
282    let p_header_accept_language = accept_language;
283    let p_header_traceparent = traceparent;
284    let p_header_tracestate = tracestate;
285    let p_header_x_accept_namespace = x_accept_namespace;
286
287    let uri_str = format!("{}/products-search", configuration.base_path);
288    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
289
290    if let Some(ref user_agent) = configuration.user_agent {
291        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
292    }
293    if let Some(param_value) = p_header_requestor {
294        req_builder = req_builder.header("Requestor", param_value.to_string());
295    }
296    if let Some(param_value) = p_header_accept_language {
297        req_builder = req_builder.header("Accept-Language", param_value.to_string());
298    }
299    if let Some(param_value) = p_header_traceparent {
300        req_builder = req_builder.header("traceparent", param_value.to_string());
301    }
302    if let Some(param_value) = p_header_tracestate {
303        req_builder = req_builder.header("tracestate", param_value.to_string());
304    }
305    if let Some(param_value) = p_header_x_accept_namespace {
306        req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
307    }
308    if let Some(ref token) = configuration.oauth_access_token {
309        req_builder = req_builder.bearer_auth(token.to_owned());
310    };
311    req_builder = req_builder.json(&p_body_product_search_request);
312
313    let req = req_builder.build()?;
314    let resp = configuration.client.execute(req).await?;
315
316    let status = resp.status();
317    let content_type = resp
318        .headers()
319        .get("content-type")
320        .and_then(|v| v.to_str().ok())
321        .unwrap_or("application/octet-stream");
322    let content_type = super::ContentType::from(content_type);
323
324    if !status.is_client_error() && !status.is_server_error() {
325        let content = resp.text().await?;
326        match content_type {
327            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
328            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ProductSearchResponse`"))),
329            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`")))),
330        }
331    } else {
332        let content = resp.text().await?;
333        let entity: Option<SearchProductsError> = serde_json::from_str(&content).ok();
334        Err(Error::ResponseError(ResponseContent { status, content, entity }))
335    }
336}
337