Skip to main content

motis_openapi_sdk/apis/
map_api.rs

1/*
2 * MOTIS API
3 *
4 * This is the MOTIS routing API.  Overview of MOTIS API versions:  MOTIS 0.x - deprecated/discontinued  MOTIS 2.x - current, providing:  * /api/v5/{plan,trip,stoptimes,map/trips} renamed METRO mode to SUBURBAN, AREAL_LIFT to AERIAL_LIFT; since MOTIS 2.5.0 * /api/v4/{plan,trip,stoptimes,map/trips} new displayName property, routeShortName only contains actual route short name from source; since MOTIS 2.2.0 * /api/v3/plan with correct maxTransfers API parameter (transfers actually corresponding to number of changes between transit legs (and not to number of transit legs), i.e. maxTransfers=0 returns direct public transit connections, as expected); since MOTIS 2.0.84  * /api/v2/{plan,trip} returns Google polylines with precision=6; since MOTIS 2.0.60 * /api/v1/{plan,trip} returns Google polylines with precision=7 (not defined for |longitude|>107) * /api/v1/_* all other endpoints  If you use the JS client lib https://www.npmjs.com/package/@motis-project/motis-client, endpoint versions will be taken into account automatically (i.e. the newest one available will be used). 
5 *
6 * The version of the OpenAPI document: v5
7 * Contact: felix@triptix.tech
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 [`initial`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum InitialError {
22    Status400(models::Error),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`levels`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum LevelsError {
30    Status400(models::Error),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`rentals`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum RentalsError {
38    Status400(models::Error),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`stops`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum StopsError {
46    Status400(models::Error),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`trips`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum TripsError {
54    Status400(models::Error),
55    UnknownValue(serde_json::Value),
56}
57
58
59pub async fn initial(configuration: &configuration::Configuration, ) -> Result<models::Initial200Response, Error<InitialError>> {
60
61    let uri_str = format!("{}/api/v1/map/initial", configuration.base_path);
62    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
63
64    if let Some(ref user_agent) = configuration.user_agent {
65        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
66    }
67
68    let req = req_builder.build()?;
69    let resp = configuration.client.execute(req).await?;
70
71    let status = resp.status();
72    let content_type = resp
73        .headers()
74        .get("content-type")
75        .and_then(|v| v.to_str().ok())
76        .unwrap_or("application/octet-stream");
77    let content_type = super::ContentType::from(content_type);
78
79    if !status.is_client_error() && !status.is_server_error() {
80        let content = resp.text().await?;
81        match content_type {
82            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
83            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Initial200Response`"))),
84            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::Initial200Response`")))),
85        }
86    } else {
87        let content = resp.text().await?;
88        let entity: Option<InitialError> = serde_json::from_str(&content).ok();
89        Err(Error::ResponseError(ResponseContent { status, content, entity }))
90    }
91}
92
93pub async fn levels(configuration: &configuration::Configuration, min: &str, max: &str) -> Result<Vec<f64>, Error<LevelsError>> {
94    // add a prefix to parameters to efficiently prevent name collisions
95    let p_query_min = min;
96    let p_query_max = max;
97
98    let uri_str = format!("{}/api/v1/map/levels", configuration.base_path);
99    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
100
101    req_builder = req_builder.query(&[("min", &p_query_min.to_string())]);
102    req_builder = req_builder.query(&[("max", &p_query_max.to_string())]);
103    if let Some(ref user_agent) = configuration.user_agent {
104        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
105    }
106
107    let req = req_builder.build()?;
108    let resp = configuration.client.execute(req).await?;
109
110    let status = resp.status();
111    let content_type = resp
112        .headers()
113        .get("content-type")
114        .and_then(|v| v.to_str().ok())
115        .unwrap_or("application/octet-stream");
116    let content_type = super::ContentType::from(content_type);
117
118    if !status.is_client_error() && !status.is_server_error() {
119        let content = resp.text().await?;
120        match content_type {
121            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
122            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;f64&gt;`"))),
123            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;f64&gt;`")))),
124        }
125    } else {
126        let content = resp.text().await?;
127        let entity: Option<LevelsError> = serde_json::from_str(&content).ok();
128        Err(Error::ResponseError(ResponseContent { status, content, entity }))
129    }
130}
131
132/// If neither the map section (`min` and `max`) nor a provider filter (either `providerGroups` or `providers`) is provided, returns a list of all available rental providers, but no station, vehicle or zone data. Provide the `withProviders=false` parameter to retrieve only provider groups if detailed feed information is not required.  Either the map section (`min` and `max`) or the provider filter (either `providerGroups` or `providers`) must be provided to retrieve station, vehicle and zone data.  If only the map section is provided, all data in the area is returned. If only the provider filter is provided, all data for the given providers is returned. If both parameters are provided, only data for the given providers in the map section is returned. 
133pub async fn rentals(configuration: &configuration::Configuration, min: Option<&str>, max: Option<&str>, provider_groups: Option<Vec<String>>, providers: Option<Vec<String>>, with_providers: Option<bool>, with_stations: Option<bool>, with_vehicles: Option<bool>, with_zones: Option<bool>) -> Result<models::Rentals200Response, Error<RentalsError>> {
134    // add a prefix to parameters to efficiently prevent name collisions
135    let p_query_min = min;
136    let p_query_max = max;
137    let p_query_provider_groups = provider_groups;
138    let p_query_providers = providers;
139    let p_query_with_providers = with_providers;
140    let p_query_with_stations = with_stations;
141    let p_query_with_vehicles = with_vehicles;
142    let p_query_with_zones = with_zones;
143
144    let uri_str = format!("{}/api/v1/rentals", configuration.base_path);
145    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
146
147    if let Some(ref param_value) = p_query_min {
148        req_builder = req_builder.query(&[("min", &param_value.to_string())]);
149    }
150    if let Some(ref param_value) = p_query_max {
151        req_builder = req_builder.query(&[("max", &param_value.to_string())]);
152    }
153    if let Some(ref param_value) = p_query_provider_groups {
154        req_builder = match "csv" {
155            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("providerGroups".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
156            _ => req_builder.query(&[("providerGroups", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
157        };
158    }
159    if let Some(ref param_value) = p_query_providers {
160        req_builder = match "csv" {
161            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("providers".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
162            _ => req_builder.query(&[("providers", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
163        };
164    }
165    if let Some(ref param_value) = p_query_with_providers {
166        req_builder = req_builder.query(&[("withProviders", &param_value.to_string())]);
167    }
168    if let Some(ref param_value) = p_query_with_stations {
169        req_builder = req_builder.query(&[("withStations", &param_value.to_string())]);
170    }
171    if let Some(ref param_value) = p_query_with_vehicles {
172        req_builder = req_builder.query(&[("withVehicles", &param_value.to_string())]);
173    }
174    if let Some(ref param_value) = p_query_with_zones {
175        req_builder = req_builder.query(&[("withZones", &param_value.to_string())]);
176    }
177    if let Some(ref user_agent) = configuration.user_agent {
178        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
179    }
180
181    let req = req_builder.build()?;
182    let resp = configuration.client.execute(req).await?;
183
184    let status = resp.status();
185    let content_type = resp
186        .headers()
187        .get("content-type")
188        .and_then(|v| v.to_str().ok())
189        .unwrap_or("application/octet-stream");
190    let content_type = super::ContentType::from(content_type);
191
192    if !status.is_client_error() && !status.is_server_error() {
193        let content = resp.text().await?;
194        match content_type {
195            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
196            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Rentals200Response`"))),
197            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::Rentals200Response`")))),
198        }
199    } else {
200        let content = resp.text().await?;
201        let entity: Option<RentalsError> = serde_json::from_str(&content).ok();
202        Err(Error::ResponseError(ResponseContent { status, content, entity }))
203    }
204}
205
206pub async fn stops(configuration: &configuration::Configuration, min: &str, max: &str) -> Result<Vec<models::Place>, Error<StopsError>> {
207    // add a prefix to parameters to efficiently prevent name collisions
208    let p_query_min = min;
209    let p_query_max = max;
210
211    let uri_str = format!("{}/api/v1/map/stops", configuration.base_path);
212    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
213
214    req_builder = req_builder.query(&[("min", &p_query_min.to_string())]);
215    req_builder = req_builder.query(&[("max", &p_query_max.to_string())]);
216    if let Some(ref user_agent) = configuration.user_agent {
217        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
218    }
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 `Vec&lt;models::Place&gt;`"))),
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 `Vec&lt;models::Place&gt;`")))),
237        }
238    } else {
239        let content = resp.text().await?;
240        let entity: Option<StopsError> = serde_json::from_str(&content).ok();
241        Err(Error::ResponseError(ResponseContent { status, content, entity }))
242    }
243}
244
245pub async fn trips(configuration: &configuration::Configuration, zoom: f64, min: &str, max: &str, start_time: String, end_time: String) -> Result<Vec<models::TripSegment>, Error<TripsError>> {
246    // add a prefix to parameters to efficiently prevent name collisions
247    let p_query_zoom = zoom;
248    let p_query_min = min;
249    let p_query_max = max;
250    let p_query_start_time = start_time;
251    let p_query_end_time = end_time;
252
253    let uri_str = format!("{}/api/v5/map/trips", configuration.base_path);
254    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
255
256    req_builder = req_builder.query(&[("zoom", &p_query_zoom.to_string())]);
257    req_builder = req_builder.query(&[("min", &p_query_min.to_string())]);
258    req_builder = req_builder.query(&[("max", &p_query_max.to_string())]);
259    req_builder = req_builder.query(&[("startTime", &p_query_start_time.to_string())]);
260    req_builder = req_builder.query(&[("endTime", &p_query_end_time.to_string())]);
261    if let Some(ref user_agent) = configuration.user_agent {
262        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
263    }
264
265    let req = req_builder.build()?;
266    let resp = configuration.client.execute(req).await?;
267
268    let status = resp.status();
269    let content_type = resp
270        .headers()
271        .get("content-type")
272        .and_then(|v| v.to_str().ok())
273        .unwrap_or("application/octet-stream");
274    let content_type = super::ContentType::from(content_type);
275
276    if !status.is_client_error() && !status.is_server_error() {
277        let content = resp.text().await?;
278        match content_type {
279            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
280            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::TripSegment&gt;`"))),
281            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::TripSegment&gt;`")))),
282        }
283    } else {
284        let content = resp.text().await?;
285        let entity: Option<TripsError> = serde_json::from_str(&content).ok();
286        Err(Error::ResponseError(ResponseContent { status, content, entity }))
287    }
288}
289