1#![allow(
3 clippy::doc_markdown,
4 clippy::missing_errors_doc,
5 clippy::must_use_candidate,
6 clippy::needless_pass_by_value,
7 clippy::return_self_not_must_use,
8 clippy::single_match_else
9)]
10
11use super::get_bus_arrival::{decode_get_bus_arrival_response, get_bus_arrival_parts};
12use super::get_bus_stops::{decode_get_bus_stops_response, get_bus_stops_parts};
13use super::get_facilities_maintenance::{
14 decode_get_facilities_maintenance_response, get_facilities_maintenance_parts,
15};
16use super::get_road_openings::{decode_get_road_openings_response, get_road_openings_parts};
17use super::get_road_works::{decode_get_road_works_response, get_road_works_parts};
18use super::get_taxi_availability::{
19 decode_get_taxi_availability_response, get_taxi_availability_parts,
20};
21use super::get_taxi_stands::{decode_get_taxi_stands_response, get_taxi_stands_parts};
22use super::get_traffic_flow::{decode_get_traffic_flow_response, get_traffic_flow_parts};
23use super::get_traffic_images::{decode_get_traffic_images_response, get_traffic_images_parts};
24use super::get_traffic_incidents::{
25 decode_get_traffic_incidents_response, get_traffic_incidents_parts,
26};
27use super::get_traffic_speed_bands::{
28 decode_get_traffic_speed_bands_response, get_traffic_speed_bands_parts,
29};
30use super::{
31 BusServiceNumber, BusStopCode, GetBusArrivalInput, GetBusArrivalResponse, GetBusStopsInput,
32 GetBusStopsResponse, GetFacilitiesMaintenanceInput, GetFacilitiesMaintenanceResponse,
33 GetRoadOpeningsInput, GetRoadOpeningsResponse, GetRoadWorksInput, GetRoadWorksResponse,
34 GetTaxiAvailabilityInput, GetTaxiAvailabilityResponse, GetTaxiStandsInput,
35 GetTaxiStandsResponse, GetTrafficFlowInput, GetTrafficFlowResponse, GetTrafficImagesInput,
36 GetTrafficImagesResponse, GetTrafficIncidentsInput, GetTrafficIncidentsResponse,
37 GetTrafficSpeedBandsInput, GetTrafficSpeedBandsResponse, StationCode,
38};
39use crate::bus;
40use crate::facility;
41use crate::taxi;
42use crate::traffic;
43#[derive(Debug, Clone)]
44pub struct Api {
45 base_url: String,
46 account_key: Option<String>,
47}
48impl Default for Api {
49 fn default() -> Self {
50 Self::new()
51 }
52}
53impl Api {
54 pub fn new() -> Self {
55 Self {
56 base_url: super::SERVER_URL.to_owned(),
57 account_key: None,
58 }
59 }
60 pub fn base_url(mut self, base_url: impl Into<String>) -> Self {
61 self.base_url = base_url.into();
62 self
63 }
64 pub fn account_key(mut self, value: impl Into<String>) -> Self {
65 self.account_key = Some(value.into());
66 self
67 }
68 pub fn bus(&self) -> bus::Api<'_> {
70 bus::Api { api: self }
71 }
72 pub fn traffic(&self) -> traffic::Api<'_> {
74 traffic::Api { api: self }
75 }
76 pub fn taxi(&self) -> taxi::Api<'_> {
78 taxi::Api { api: self }
79 }
80 pub fn facility(&self) -> facility::Api<'_> {
82 facility::Api { api: self }
83 }
84 fn apply<B>(
85 &self,
86 parts: &mut satay_runtime::RequestParts<B>,
87 ) -> Result<(), satay_runtime::Error> {
88 if let Some(value) = &self.account_key {
89 satay_runtime::insert_header(&mut parts.headers, "AccountKey", value)?;
90 }
91 if self.base_url.is_empty() {
92 return Ok(());
93 }
94 let path_and_query = parts.uri.as_str();
95 let base_url = self.base_url.trim_end_matches('/');
96 let separator = if path_and_query.starts_with('/') {
97 ""
98 } else {
99 "/"
100 };
101 parts.uri = format!("{base_url}{separator}{path_and_query}");
102 Ok(())
103 }
104}
105#[must_use = "configure this action and execute it or call `.request()`"]
114#[derive(Debug, Clone)]
115pub struct GetBusArrivalAction<'a> {
116 api: &'a Api,
117 input: GetBusArrivalInput,
118}
119impl<'a> GetBusArrivalAction<'a> {
120 pub(crate) fn new(api: &'a Api, bus_stop_code: BusStopCode) -> Self {
121 Self {
122 api,
123 input: GetBusArrivalInput::new(bus_stop_code),
124 }
125 }
126 #[must_use = "builder methods return the configured action"]
128 pub fn service_no(mut self, service_no: BusServiceNumber) -> Self {
129 self.input = self.input.service_no(service_no);
130 self
131 }
132 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
133 let api = self.api;
134 let mut parts = get_bus_arrival_parts(self.input)?;
135 api.apply(&mut parts)?;
136 satay_runtime::into_empty_request(parts)
137 }
138 pub fn decode<B: AsRef<[u8]>>(
139 response: satay_runtime::ResponseParts<B>,
140 ) -> Result<GetBusArrivalResponse, satay_runtime::Error> {
141 decode_get_bus_arrival_response(response)
142 }
143}
144impl satay_runtime::Action for GetBusArrivalAction<'_> {
145 type Response = GetBusArrivalResponse;
146 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
147 self.request()
148 }
149 fn decode<B: AsRef<[u8]>>(
150 response: satay_runtime::ResponseParts<B>,
151 ) -> Result<Self::Response, satay_runtime::Error> {
152 Self::decode(response)
153 }
154}
155#[must_use = "configure this action and execute it or call `.request()`"]
160#[derive(Debug, Clone)]
161pub struct GetTrafficIncidentsAction<'a> {
162 api: &'a Api,
163 input: GetTrafficIncidentsInput,
164}
165impl<'a> GetTrafficIncidentsAction<'a> {
166 pub(crate) fn new(api: &'a Api) -> Self {
167 Self {
168 api,
169 input: GetTrafficIncidentsInput::new(),
170 }
171 }
172 #[must_use = "builder methods return the configured action"]
174 pub fn skip(mut self, skip: u32) -> Self {
175 self.input = self.input.skip(skip);
176 self
177 }
178 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
179 let api = self.api;
180 let mut parts = get_traffic_incidents_parts(self.input)?;
181 api.apply(&mut parts)?;
182 satay_runtime::into_empty_request(parts)
183 }
184 pub fn decode<B: AsRef<[u8]>>(
185 response: satay_runtime::ResponseParts<B>,
186 ) -> Result<GetTrafficIncidentsResponse, satay_runtime::Error> {
187 decode_get_traffic_incidents_response(response)
188 }
189}
190impl satay_runtime::Action for GetTrafficIncidentsAction<'_> {
191 type Response = GetTrafficIncidentsResponse;
192 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
193 self.request()
194 }
195 fn decode<B: AsRef<[u8]>>(
196 response: satay_runtime::ResponseParts<B>,
197 ) -> Result<Self::Response, satay_runtime::Error> {
198 Self::decode(response)
199 }
200}
201#[must_use = "configure this action and execute it or call `.request()`"]
206#[derive(Debug, Clone)]
207pub struct GetTrafficImagesAction<'a> {
208 api: &'a Api,
209 input: GetTrafficImagesInput,
210}
211impl<'a> GetTrafficImagesAction<'a> {
212 pub(crate) fn new(api: &'a Api) -> Self {
213 Self {
214 api,
215 input: GetTrafficImagesInput::new(),
216 }
217 }
218 #[must_use = "builder methods return the configured action"]
220 pub fn skip(mut self, skip: u32) -> Self {
221 self.input = self.input.skip(skip);
222 self
223 }
224 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
225 let api = self.api;
226 let mut parts = get_traffic_images_parts(self.input)?;
227 api.apply(&mut parts)?;
228 satay_runtime::into_empty_request(parts)
229 }
230 pub fn decode<B: AsRef<[u8]>>(
231 response: satay_runtime::ResponseParts<B>,
232 ) -> Result<GetTrafficImagesResponse, satay_runtime::Error> {
233 decode_get_traffic_images_response(response)
234 }
235}
236impl satay_runtime::Action for GetTrafficImagesAction<'_> {
237 type Response = GetTrafficImagesResponse;
238 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
239 self.request()
240 }
241 fn decode<B: AsRef<[u8]>>(
242 response: satay_runtime::ResponseParts<B>,
243 ) -> Result<Self::Response, satay_runtime::Error> {
244 Self::decode(response)
245 }
246}
247#[must_use = "configure this action and execute it or call `.request()`"]
253#[derive(Debug, Clone)]
254pub struct GetTrafficSpeedBandsAction<'a> {
255 api: &'a Api,
256 input: GetTrafficSpeedBandsInput,
257}
258impl<'a> GetTrafficSpeedBandsAction<'a> {
259 pub(crate) fn new(api: &'a Api) -> Self {
260 Self {
261 api,
262 input: GetTrafficSpeedBandsInput::new(),
263 }
264 }
265 #[must_use = "builder methods return the configured action"]
267 pub fn skip(mut self, skip: u32) -> Self {
268 self.input = self.input.skip(skip);
269 self
270 }
271 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
272 let api = self.api;
273 let mut parts = get_traffic_speed_bands_parts(self.input)?;
274 api.apply(&mut parts)?;
275 satay_runtime::into_empty_request(parts)
276 }
277 pub fn decode<B: AsRef<[u8]>>(
278 response: satay_runtime::ResponseParts<B>,
279 ) -> Result<GetTrafficSpeedBandsResponse, satay_runtime::Error> {
280 decode_get_traffic_speed_bands_response(response)
281 }
282}
283impl satay_runtime::Action for GetTrafficSpeedBandsAction<'_> {
284 type Response = GetTrafficSpeedBandsResponse;
285 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
286 self.request()
287 }
288 fn decode<B: AsRef<[u8]>>(
289 response: satay_runtime::ResponseParts<B>,
290 ) -> Result<Self::Response, satay_runtime::Error> {
291 Self::decode(response)
292 }
293}
294#[must_use = "configure this action and execute it or call `.request()`"]
299#[derive(Debug, Clone)]
300pub struct GetTrafficFlowAction<'a> {
301 api: &'a Api,
302 input: GetTrafficFlowInput,
303}
304impl<'a> GetTrafficFlowAction<'a> {
305 pub(crate) fn new(api: &'a Api) -> Self {
306 Self {
307 api,
308 input: GetTrafficFlowInput::new(),
309 }
310 }
311 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
312 let api = self.api;
313 let mut parts = get_traffic_flow_parts(self.input)?;
314 api.apply(&mut parts)?;
315 satay_runtime::into_empty_request(parts)
316 }
317 pub fn decode<B: AsRef<[u8]>>(
318 response: satay_runtime::ResponseParts<B>,
319 ) -> Result<GetTrafficFlowResponse, satay_runtime::Error> {
320 decode_get_traffic_flow_response(response)
321 }
322}
323impl satay_runtime::Action for GetTrafficFlowAction<'_> {
324 type Response = GetTrafficFlowResponse;
325 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
326 self.request()
327 }
328 fn decode<B: AsRef<[u8]>>(
329 response: satay_runtime::ResponseParts<B>,
330 ) -> Result<Self::Response, satay_runtime::Error> {
331 Self::decode(response)
332 }
333}
334#[must_use = "configure this action and execute it or call `.request()`"]
340#[derive(Debug, Clone)]
341pub struct GetRoadWorksAction<'a> {
342 api: &'a Api,
343 input: GetRoadWorksInput,
344}
345impl<'a> GetRoadWorksAction<'a> {
346 pub(crate) fn new(api: &'a Api) -> Self {
347 Self {
348 api,
349 input: GetRoadWorksInput::new(),
350 }
351 }
352 #[must_use = "builder methods return the configured action"]
354 pub fn skip(mut self, skip: u32) -> Self {
355 self.input = self.input.skip(skip);
356 self
357 }
358 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
359 let api = self.api;
360 let mut parts = get_road_works_parts(self.input)?;
361 api.apply(&mut parts)?;
362 satay_runtime::into_empty_request(parts)
363 }
364 pub fn decode<B: AsRef<[u8]>>(
365 response: satay_runtime::ResponseParts<B>,
366 ) -> Result<GetRoadWorksResponse, satay_runtime::Error> {
367 decode_get_road_works_response(response)
368 }
369}
370impl satay_runtime::Action for GetRoadWorksAction<'_> {
371 type Response = GetRoadWorksResponse;
372 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
373 self.request()
374 }
375 fn decode<B: AsRef<[u8]>>(
376 response: satay_runtime::ResponseParts<B>,
377 ) -> Result<Self::Response, satay_runtime::Error> {
378 Self::decode(response)
379 }
380}
381#[must_use = "configure this action and execute it or call `.request()`"]
386#[derive(Debug, Clone)]
387pub struct GetRoadOpeningsAction<'a> {
388 api: &'a Api,
389 input: GetRoadOpeningsInput,
390}
391impl<'a> GetRoadOpeningsAction<'a> {
392 pub(crate) fn new(api: &'a Api) -> Self {
393 Self {
394 api,
395 input: GetRoadOpeningsInput::new(),
396 }
397 }
398 #[must_use = "builder methods return the configured action"]
400 pub fn skip(mut self, skip: u32) -> Self {
401 self.input = self.input.skip(skip);
402 self
403 }
404 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
405 let api = self.api;
406 let mut parts = get_road_openings_parts(self.input)?;
407 api.apply(&mut parts)?;
408 satay_runtime::into_empty_request(parts)
409 }
410 pub fn decode<B: AsRef<[u8]>>(
411 response: satay_runtime::ResponseParts<B>,
412 ) -> Result<GetRoadOpeningsResponse, satay_runtime::Error> {
413 decode_get_road_openings_response(response)
414 }
415}
416impl satay_runtime::Action for GetRoadOpeningsAction<'_> {
417 type Response = GetRoadOpeningsResponse;
418 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
419 self.request()
420 }
421 fn decode<B: AsRef<[u8]>>(
422 response: satay_runtime::ResponseParts<B>,
423 ) -> Result<Self::Response, satay_runtime::Error> {
424 Self::decode(response)
425 }
426}
427#[must_use = "configure this action and execute it or call `.request()`"]
433#[derive(Debug, Clone)]
434pub struct GetBusStopsAction<'a> {
435 api: &'a Api,
436 input: GetBusStopsInput,
437}
438impl<'a> GetBusStopsAction<'a> {
439 pub(crate) fn new(api: &'a Api) -> Self {
440 Self {
441 api,
442 input: GetBusStopsInput::new(),
443 }
444 }
445 #[must_use = "builder methods return the configured action"]
447 pub fn skip(mut self, skip: u32) -> Self {
448 self.input = self.input.skip(skip);
449 self
450 }
451 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
452 let api = self.api;
453 let mut parts = get_bus_stops_parts(self.input)?;
454 api.apply(&mut parts)?;
455 satay_runtime::into_empty_request(parts)
456 }
457 pub fn decode<B: AsRef<[u8]>>(
458 response: satay_runtime::ResponseParts<B>,
459 ) -> Result<GetBusStopsResponse, satay_runtime::Error> {
460 decode_get_bus_stops_response(response)
461 }
462}
463impl satay_runtime::Action for GetBusStopsAction<'_> {
464 type Response = GetBusStopsResponse;
465 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
466 self.request()
467 }
468 fn decode<B: AsRef<[u8]>>(
469 response: satay_runtime::ResponseParts<B>,
470 ) -> Result<Self::Response, satay_runtime::Error> {
471 Self::decode(response)
472 }
473}
474#[must_use = "configure this action and execute it or call `.request()`"]
480#[derive(Debug, Clone)]
481pub struct GetTaxiAvailabilityAction<'a> {
482 api: &'a Api,
483 input: GetTaxiAvailabilityInput,
484}
485impl<'a> GetTaxiAvailabilityAction<'a> {
486 pub(crate) fn new(api: &'a Api) -> Self {
487 Self {
488 api,
489 input: GetTaxiAvailabilityInput::new(),
490 }
491 }
492 #[must_use = "builder methods return the configured action"]
494 pub fn skip(mut self, skip: u32) -> Self {
495 self.input = self.input.skip(skip);
496 self
497 }
498 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
499 let api = self.api;
500 let mut parts = get_taxi_availability_parts(self.input)?;
501 api.apply(&mut parts)?;
502 satay_runtime::into_empty_request(parts)
503 }
504 pub fn decode<B: AsRef<[u8]>>(
505 response: satay_runtime::ResponseParts<B>,
506 ) -> Result<GetTaxiAvailabilityResponse, satay_runtime::Error> {
507 decode_get_taxi_availability_response(response)
508 }
509}
510impl satay_runtime::Action for GetTaxiAvailabilityAction<'_> {
511 type Response = GetTaxiAvailabilityResponse;
512 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
513 self.request()
514 }
515 fn decode<B: AsRef<[u8]>>(
516 response: satay_runtime::ResponseParts<B>,
517 ) -> Result<Self::Response, satay_runtime::Error> {
518 Self::decode(response)
519 }
520}
521#[must_use = "configure this action and execute it or call `.request()`"]
527#[derive(Debug, Clone)]
528pub struct GetTaxiStandsAction<'a> {
529 api: &'a Api,
530 input: GetTaxiStandsInput,
531}
532impl<'a> GetTaxiStandsAction<'a> {
533 pub(crate) fn new(api: &'a Api) -> Self {
534 Self {
535 api,
536 input: GetTaxiStandsInput::new(),
537 }
538 }
539 #[must_use = "builder methods return the configured action"]
541 pub fn skip(mut self, skip: u32) -> Self {
542 self.input = self.input.skip(skip);
543 self
544 }
545 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
546 let api = self.api;
547 let mut parts = get_taxi_stands_parts(self.input)?;
548 api.apply(&mut parts)?;
549 satay_runtime::into_empty_request(parts)
550 }
551 pub fn decode<B: AsRef<[u8]>>(
552 response: satay_runtime::ResponseParts<B>,
553 ) -> Result<GetTaxiStandsResponse, satay_runtime::Error> {
554 decode_get_taxi_stands_response(response)
555 }
556}
557impl satay_runtime::Action for GetTaxiStandsAction<'_> {
558 type Response = GetTaxiStandsResponse;
559 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
560 self.request()
561 }
562 fn decode<B: AsRef<[u8]>>(
563 response: satay_runtime::ResponseParts<B>,
564 ) -> Result<Self::Response, satay_runtime::Error> {
565 Self::decode(response)
566 }
567}
568#[must_use = "configure this action and execute it or call `.request()`"]
574#[derive(Debug, Clone)]
575pub struct GetFacilitiesMaintenanceAction<'a> {
576 api: &'a Api,
577 input: GetFacilitiesMaintenanceInput,
578}
579impl<'a> GetFacilitiesMaintenanceAction<'a> {
580 pub(crate) fn new(api: &'a Api, station_code: StationCode) -> Self {
581 Self {
582 api,
583 input: GetFacilitiesMaintenanceInput::new(station_code),
584 }
585 }
586 pub fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
587 let api = self.api;
588 let mut parts = get_facilities_maintenance_parts(self.input)?;
589 api.apply(&mut parts)?;
590 satay_runtime::into_empty_request(parts)
591 }
592 pub fn decode<B: AsRef<[u8]>>(
593 response: satay_runtime::ResponseParts<B>,
594 ) -> Result<GetFacilitiesMaintenanceResponse, satay_runtime::Error> {
595 decode_get_facilities_maintenance_response(response)
596 }
597}
598impl satay_runtime::Action for GetFacilitiesMaintenanceAction<'_> {
599 type Response = GetFacilitiesMaintenanceResponse;
600 fn request(self) -> Result<http::Request<Vec<u8>>, satay_runtime::Error> {
601 self.request()
602 }
603 fn decode<B: AsRef<[u8]>>(
604 response: satay_runtime::ResponseParts<B>,
605 ) -> Result<Self::Response, satay_runtime::Error> {
606 Self::decode(response)
607 }
608}