1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use lta_models::prelude::{BusArrivalResp, BusArrivalRespRaw as RawBusArrivalResp};
use ureq::Agent;

use crate::Client;
use crate::{
    blocking::{prelude::BusRequests, ClientExt, LTAClient},
    Bus, LTAResult,
};
use concat_string::concat_string;

impl BusRequests<LTAClient<Agent>> for Bus {
    fn get_arrival<'a>(
        client: &LTAClient<Agent>,
        bus_stop_code: u32,
        service_no: impl Into<Option<&'a str>>,
    ) -> LTAResult<BusArrivalResp> {
        let url = concat_string!(client.base_url(), "/BusArrivalv2");
        let bus_stop_code = bus_stop_code.to_string();

        match service_no.into() {
            Some(srv_no) => client.build_req_with_query::<RawBusArrivalResp, _, _>(&url, |rb| {
                let srv_no = srv_no.as_ref();
                rb.query("BusStopCode", &bus_stop_code)
                    .query("ServiceNo", srv_no)
            }),
            None => client.build_req_with_query::<RawBusArrivalResp, _, _>(&url, |rb| {
                rb.query("BusStopCode", &bus_stop_code)
            }),
        }
    }
}