use crate::api_url;
use crate::blocking::{build_req_with_query, build_req_with_skip, LTAClient};
use crate::models::traffic::prelude::*;
use crate::{Client, LTAError, LTAResult, Traffic};
pub trait TrafficRequests<C: Client> {
fn get_erp_rates<S>(client: &C, skip: S) -> LTAResult<Vec<ErpRate>>
where
S: Into<Option<u32>>;
fn get_carpark_avail<S>(client: &C, skip: S) -> LTAResult<Vec<CarPark>>
where
S: Into<Option<u32>>;
fn get_est_travel_time<S>(client: &C, skip: S) -> LTAResult<Vec<EstTravelTime>>
where
S: Into<Option<u32>>;
fn get_faulty_traffic_lights<S>(client: &C, skip: S) -> LTAResult<Vec<FaultyTrafficLight>>
where
S: Into<Option<u32>>;
fn get_road_details<S>(
client: &C,
road_details_type: RoadDetailsType,
skip: S,
) -> LTAResult<Vec<RoadDetails>>
where
S: Into<Option<u32>>;
fn get_traffic_speed_band<S>(client: &C, skip: S) -> LTAResult<Vec<TrafficSpeedBand>>
where
S: Into<Option<u32>>;
fn get_traffic_images<S>(client: &C, skip: S) -> LTAResult<Vec<TrafficImage>>
where
S: Into<Option<u32>>;
fn get_traffic_incidents<S>(client: &C, skip: S) -> LTAResult<Vec<TrafficIncident>>
where
S: Into<Option<u32>>;
fn get_vms_emas<S>(client: &C, skip: S) -> LTAResult<Vec<Vms>>
where
S: Into<Option<u32>>;
fn get_bike_parking<D>(client: &C, lat: f64, long: f64, dist: D) -> LTAResult<Vec<BikeParking>>
where
D: Into<Option<f64>>;
}
impl TrafficRequests<LTAClient> for Traffic {
fn get_erp_rates<S>(client: <AClient, skip: S) -> LTAResult<Vec<ErpRate>>
where
S: Into<Option<u32>>,
{
build_req_with_skip::<ErpRatesResp, _, _>(client, api_url!("/ERPRates"), skip.into())
}
fn get_carpark_avail<S>(client: <AClient, skip: S) -> LTAResult<Vec<CarPark>>
where
S: Into<Option<u32>>,
{
build_req_with_skip::<CarparkAvailResp, _, _>(
client,
api_url!("/CarParkAvailabilityv2"),
skip.into(),
)
}
fn get_est_travel_time<S>(client: <AClient, skip: S) -> LTAResult<Vec<EstTravelTime>>
where
S: Into<Option<u32>>,
{
build_req_with_skip::<EstTravelTimeResp, _, _>(
client,
api_url!("/EstTravelTimes"),
skip.into(),
)
}
fn get_faulty_traffic_lights<S>(
client: <AClient,
skip: S,
) -> LTAResult<Vec<FaultyTrafficLight>>
where
S: Into<Option<u32>>,
{
build_req_with_skip::<FaultyTrafficLightResp, _, _>(
client,
api_url!("/FaultyTrafficLights"),
skip.into(),
)
}
fn get_road_details<S>(
client: <AClient,
road_details_type: RoadDetailsType,
skip: S,
) -> LTAResult<Vec<RoadDetails>>
where
S: Into<Option<u32>>,
{
let url = match road_details_type {
RoadDetailsType::RoadOpening => api_url!("/RoadOpenings"),
RoadDetailsType::RoadWorks => api_url!("/RoadWorks"),
_ => return Err(LTAError::UnknownEnumVariant),
};
build_req_with_skip::<RoadDetailsResp, _, _>(client, url, skip.into())
}
fn get_traffic_speed_band<S>(client: <AClient, skip: S) -> LTAResult<Vec<TrafficSpeedBand>>
where
S: Into<Option<u32>>,
{
build_req_with_skip::<TrafficSpeedBandResp, _, _>(
client,
api_url!("/TrafficSpeedBandsv2"),
skip.into(),
)
}
fn get_traffic_images<S>(client: <AClient, skip: S) -> LTAResult<Vec<TrafficImage>>
where
S: Into<Option<u32>>,
{
build_req_with_skip::<TrafficImageResp, _, _>(
client,
api_url!("/Traffic-Imagesv2"),
skip.into(),
)
}
fn get_traffic_incidents<S>(client: <AClient, skip: S) -> LTAResult<Vec<TrafficIncident>>
where
S: Into<Option<u32>>,
{
build_req_with_skip::<TrafficIncidentResp, _, _>(
client,
api_url!("/TrafficIncidents"),
skip.into(),
)
}
fn get_vms_emas<S>(client: <AClient, skip: S) -> LTAResult<Vec<Vms>>
where
S: Into<Option<u32>>,
{
build_req_with_skip::<VMSResp, _, _>(client, api_url!("/VMS"), skip.into())
}
fn get_bike_parking<D>(
client: <AClient,
lat: f64,
long: f64,
dist: D,
) -> LTAResult<Vec<BikeParking>>
where
D: Into<Option<f64>>,
{
let unwrapped_dist = dist.into().unwrap_or(0.5);
build_req_with_query::<BikeParkingResp, _, _, _>(
client,
api_url!("/BicycleParkingv2"),
|rb| rb.query(&[("Lat", lat), ("Long", long), ("Dist", unwrapped_dist)]),
)
}
}