osdm_sys/apis/
on_demand_services_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_availabilities_continuous_services`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetAvailabilitiesContinuousServicesError {
22    Status400(models::Problem),
23    Status401(models::Problem),
24    Status403(models::Problem),
25    Status404(models::Problem),
26    Status415(models::Problem),
27    Status500(models::Problem),
28    Status501(models::Problem),
29    Status503(models::Problem),
30    DefaultResponse(models::Problem),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`get_continuous_service_usage_id`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetContinuousServiceUsageIdError {
38    Status400(models::Problem),
39    Status401(models::Problem),
40    Status403(models::Problem),
41    Status404(models::Problem),
42    Status415(models::Problem),
43    Status500(models::Problem),
44    Status501(models::Problem),
45    Status503(models::Problem),
46    DefaultResponse(models::Problem),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`patch_continuous_service_usage_id`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum PatchContinuousServiceUsageIdError {
54    Status400(models::Problem),
55    Status401(models::Problem),
56    Status403(models::Problem),
57    Status404(models::Problem),
58    Status409(models::Problem),
59    Status415(models::Problem),
60    Status500(models::Problem),
61    Status501(models::Problem),
62    Status503(models::Problem),
63    DefaultResponse(models::Problem),
64    UnknownValue(serde_json::Value),
65}
66
67
68/// Get availabilities of an on-demand services. 
69pub async fn get_availabilities_continuous_services(configuration: &configuration::Configuration, context_id: &str, context_type: models::ContextType, resource_id: &str, resource_type: models::ResourceType, continuous_service_availability_scope: models::ContinuousServiceAvailabilityScope, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>) -> Result<models::ContinuousServicesAvailabilityResponse, Error<GetAvailabilitiesContinuousServicesError>> {
70    // add a prefix to parameters to efficiently prevent name collisions
71    let p_query_context_id = context_id;
72    let p_query_context_type = context_type;
73    let p_query_resource_id = resource_id;
74    let p_query_resource_type = resource_type;
75    let p_body_continuous_service_availability_scope = continuous_service_availability_scope;
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!("{}/availabilities/on-demand-services", configuration.base_path);
82    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
83
84    req_builder = req_builder.query(&[("contextId", &p_query_context_id.to_string())]);
85    req_builder = req_builder.query(&[("contextType", &p_query_context_type.to_string())]);
86    req_builder = req_builder.query(&[("resourceId", &p_query_resource_id.to_string())]);
87    req_builder = req_builder.query(&[("resourceType", &p_query_resource_type.to_string())]);
88    if let Some(ref user_agent) = configuration.user_agent {
89        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
90    }
91    if let Some(param_value) = p_header_requestor {
92        req_builder = req_builder.header("Requestor", param_value.to_string());
93    }
94    if let Some(param_value) = p_header_accept_language {
95        req_builder = req_builder.header("Accept-Language", param_value.to_string());
96    }
97    if let Some(param_value) = p_header_traceparent {
98        req_builder = req_builder.header("traceparent", param_value.to_string());
99    }
100    if let Some(param_value) = p_header_tracestate {
101        req_builder = req_builder.header("tracestate", param_value.to_string());
102    }
103    if let Some(ref token) = configuration.oauth_access_token {
104        req_builder = req_builder.bearer_auth(token.to_owned());
105    };
106    req_builder = req_builder.json(&p_body_continuous_service_availability_scope);
107
108    let req = req_builder.build()?;
109    let resp = configuration.client.execute(req).await?;
110
111    let status = resp.status();
112    let content_type = resp
113        .headers()
114        .get("content-type")
115        .and_then(|v| v.to_str().ok())
116        .unwrap_or("application/octet-stream");
117    let content_type = super::ContentType::from(content_type);
118
119    if !status.is_client_error() && !status.is_server_error() {
120        let content = resp.text().await?;
121        match content_type {
122            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
123            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ContinuousServicesAvailabilityResponse`"))),
124            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::ContinuousServicesAvailabilityResponse`")))),
125        }
126    } else {
127        let content = resp.text().await?;
128        let entity: Option<GetAvailabilitiesContinuousServicesError> = serde_json::from_str(&content).ok();
129        Err(Error::ResponseError(ResponseContent { status, content, entity }))
130    }
131}
132
133pub async fn get_continuous_service_usage_id(configuration: &configuration::Configuration, fulfillment_id: &str, continuous_service_usage_id: &str, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, x_accept_namespace: Option<&str>) -> Result<models::ContinuousServiceUsage, Error<GetContinuousServiceUsageIdError>> {
134    // add a prefix to parameters to efficiently prevent name collisions
135    let p_path_fulfillment_id = fulfillment_id;
136    let p_path_continuous_service_usage_id = continuous_service_usage_id;
137    let p_header_requestor = requestor;
138    let p_header_accept_language = accept_language;
139    let p_header_traceparent = traceparent;
140    let p_header_tracestate = tracestate;
141    let p_header_x_accept_namespace = x_accept_namespace;
142
143    let uri_str = format!("{}/fulfillments/{fulfillmentId}/continuous-service-usage/{continuousServiceUsageId}", configuration.base_path, fulfillmentId=crate::apis::urlencode(p_path_fulfillment_id), continuousServiceUsageId=crate::apis::urlencode(p_path_continuous_service_usage_id));
144    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
145
146    if let Some(ref user_agent) = configuration.user_agent {
147        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
148    }
149    if let Some(param_value) = p_header_requestor {
150        req_builder = req_builder.header("Requestor", param_value.to_string());
151    }
152    if let Some(param_value) = p_header_accept_language {
153        req_builder = req_builder.header("Accept-Language", param_value.to_string());
154    }
155    if let Some(param_value) = p_header_traceparent {
156        req_builder = req_builder.header("traceparent", param_value.to_string());
157    }
158    if let Some(param_value) = p_header_tracestate {
159        req_builder = req_builder.header("tracestate", param_value.to_string());
160    }
161    if let Some(param_value) = p_header_x_accept_namespace {
162        req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
163    }
164    if let Some(ref token) = configuration.oauth_access_token {
165        req_builder = req_builder.bearer_auth(token.to_owned());
166    };
167
168    let req = req_builder.build()?;
169    let resp = configuration.client.execute(req).await?;
170
171    let status = resp.status();
172    let content_type = resp
173        .headers()
174        .get("content-type")
175        .and_then(|v| v.to_str().ok())
176        .unwrap_or("application/octet-stream");
177    let content_type = super::ContentType::from(content_type);
178
179    if !status.is_client_error() && !status.is_server_error() {
180        let content = resp.text().await?;
181        match content_type {
182            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
183            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ContinuousServiceUsage`"))),
184            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::ContinuousServiceUsage`")))),
185        }
186    } else {
187        let content = resp.text().await?;
188        let entity: Option<GetContinuousServiceUsageIdError> = serde_json::from_str(&content).ok();
189        Err(Error::ResponseError(ResponseContent { status, content, entity }))
190    }
191}
192
193/// start or end the usage of a continuous service of an demand vehicle 
194pub async fn patch_continuous_service_usage_id(configuration: &configuration::Configuration, fulfillment_id: &str, continuous_service_usage_id: &str, continuous_service_usage_patch_request: models::ContinuousServiceUsagePatchRequest, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, idempotency_key: Option<&str>, x_accept_namespace: Option<&str>) -> Result<models::ContinuousServiceUsage, Error<PatchContinuousServiceUsageIdError>> {
195    // add a prefix to parameters to efficiently prevent name collisions
196    let p_path_fulfillment_id = fulfillment_id;
197    let p_path_continuous_service_usage_id = continuous_service_usage_id;
198    let p_body_continuous_service_usage_patch_request = continuous_service_usage_patch_request;
199    let p_header_requestor = requestor;
200    let p_header_accept_language = accept_language;
201    let p_header_traceparent = traceparent;
202    let p_header_tracestate = tracestate;
203    let p_header_idempotency_key = idempotency_key;
204    let p_header_x_accept_namespace = x_accept_namespace;
205
206    let uri_str = format!("{}/fulfillments/{fulfillmentId}/continuous-service-usage/{continuousServiceUsageId}", configuration.base_path, fulfillmentId=crate::apis::urlencode(p_path_fulfillment_id), continuousServiceUsageId=crate::apis::urlencode(p_path_continuous_service_usage_id));
207    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
208
209    if let Some(ref user_agent) = configuration.user_agent {
210        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
211    }
212    if let Some(param_value) = p_header_requestor {
213        req_builder = req_builder.header("Requestor", param_value.to_string());
214    }
215    if let Some(param_value) = p_header_accept_language {
216        req_builder = req_builder.header("Accept-Language", param_value.to_string());
217    }
218    if let Some(param_value) = p_header_traceparent {
219        req_builder = req_builder.header("traceparent", param_value.to_string());
220    }
221    if let Some(param_value) = p_header_tracestate {
222        req_builder = req_builder.header("tracestate", param_value.to_string());
223    }
224    if let Some(param_value) = p_header_idempotency_key {
225        req_builder = req_builder.header("Idempotency-Key", param_value.to_string());
226    }
227    if let Some(param_value) = p_header_x_accept_namespace {
228        req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
229    }
230    if let Some(ref token) = configuration.oauth_access_token {
231        req_builder = req_builder.bearer_auth(token.to_owned());
232    };
233    req_builder = req_builder.json(&p_body_continuous_service_usage_patch_request);
234
235    let req = req_builder.build()?;
236    let resp = configuration.client.execute(req).await?;
237
238    let status = resp.status();
239    let content_type = resp
240        .headers()
241        .get("content-type")
242        .and_then(|v| v.to_str().ok())
243        .unwrap_or("application/octet-stream");
244    let content_type = super::ContentType::from(content_type);
245
246    if !status.is_client_error() && !status.is_server_error() {
247        let content = resp.text().await?;
248        match content_type {
249            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
250            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ContinuousServiceUsage`"))),
251            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::ContinuousServiceUsage`")))),
252        }
253    } else {
254        let content = resp.text().await?;
255        let entity: Option<PatchContinuousServiceUsageIdError> = serde_json::from_str(&content).ok();
256        Err(Error::ResponseError(ResponseContent { status, content, entity }))
257    }
258}
259