1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum InitialError {
22 Status400(models::Error),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum LevelsError {
30 Status400(models::Error),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum RentalsError {
38 Status400(models::Error),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum StopsError {
46 Status400(models::Error),
47 UnknownValue(serde_json::Value),
48}
49
50#[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 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<f64>`"))),
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<f64>`")))),
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
132pub 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 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", ¶m_value.to_string())]);
149 }
150 if let Some(ref param_value) = p_query_max {
151 req_builder = req_builder.query(&[("max", ¶m_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(¶m_value.into_iter().map(|p| ("providerGroups".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
156 _ => req_builder.query(&[("providerGroups", ¶m_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(¶m_value.into_iter().map(|p| ("providers".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
162 _ => req_builder.query(&[("providers", ¶m_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", ¶m_value.to_string())]);
167 }
168 if let Some(ref param_value) = p_query_with_stations {
169 req_builder = req_builder.query(&[("withStations", ¶m_value.to_string())]);
170 }
171 if let Some(ref param_value) = p_query_with_vehicles {
172 req_builder = req_builder.query(&[("withVehicles", ¶m_value.to_string())]);
173 }
174 if let Some(ref param_value) = p_query_with_zones {
175 req_builder = req_builder.query(&[("withZones", ¶m_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 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<models::Place>`"))),
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<models::Place>`")))),
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 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<models::TripSegment>`"))),
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<models::TripSegment>`")))),
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