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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
use crate::models::traffic::prelude::*;
use crate::{Client, LTAError, LTAResult};
use concat_string::concat_string;

use super::ClientExt;

pub trait TrafficRequests<C: Client + ClientExt> {
    /// Returns ERP rates of all vehicle types across all timings for each
    /// zone.
    ///
    /// **Update freq**: Ad-Hoc
    async fn get_erp_rates<S>(client: &C, skip: S) -> LTAResult<Vec<ErpRate>>
    where
        S: Into<Option<u32>>,
    {
        client
            .build_req_with_skip::<ErpRatesResp, _>(
                &concat_string!(client.base_url(), "/ERPRates"),
                skip.into(),
            )
            .await
    }

    /// Returns no. of available lots for HDB, LTA and URA carpark data.
    /// The LTA carpark data consist of major shopping malls and developments within
    /// Orchard, Marina, HarbourFront, Jurong Lake District.
    /// (Note: list of LTA carpark data available on this API is subset of those listed on
    /// One.Motoring and MyTransport Portals)
    ///
    /// **Update freq**: 1 min
    async fn get_carpark_avail<S>(client: &C, skip: S) -> LTAResult<Vec<CarPark>>
    where
        S: Into<Option<u32>>,
    {
        client
            .build_req_with_skip::<CarparkAvailResp, _>(
                &concat_string!(client.base_url(), "/CarParkAvailabilityv2"),
                skip.into(),
            )
            .await
    }

    /// Returns estimated travel times of expressways (in segments).
    ///
    /// **Update freq**: 5min
    async fn get_est_travel_time<S>(client: &C, skip: S) -> LTAResult<Vec<EstTravelTime>>
    where
        S: Into<Option<u32>>,
    {
        client
            .build_req_with_skip::<EstTravelTimeResp, _>(
                &concat_string!(client.base_url(), "/EstTravelTimes"),
                skip.into(),
            )
            .await
    }

    /// Returns alerts of traffic lights that are currently faulty, or currently
    /// undergoing scheduled maintenance.
    ///
    /// **Update freq**: 2min or whenever there are updates
    async fn get_faulty_traffic_lights<S>(client: &C, skip: S) -> LTAResult<Vec<FaultyTrafficLight>>
    where
        S: Into<Option<u32>>,
    {
        client
            .build_req_with_skip::<FaultyTrafficLightResp, _>(
                &concat_string!(client.base_url(), "/FaultyTrafficLights"),
                skip.into(),
            )
            .await
    }

    /// Returns all planned road openings or road works depending on the `RoadDetailsType` supplied
    ///
    /// **Update freq**: 24 hours – whenever there are updates
    async fn get_road_details<S>(
        client: &C,
        road_details_type: RoadDetailsType,
        skip: S,
    ) -> LTAResult<Vec<RoadDetails>>
    where
        S: Into<Option<u32>>,
    {
        let url = match road_details_type {
            RoadDetailsType::RoadOpening => concat_string!(client.base_url(), "/RoadOpenings"),
            RoadDetailsType::RoadWorks => concat_string!(client.base_url(), "/RoadWorks"),
            _ => return Err(LTAError::UnknownEnumVariant),
        };

        client
            .build_req_with_skip::<RoadDetailsResp, _>(&url, skip.into())
            .await
    }

    /// Returns current traffic speeds on expressways and arterial roads,
    /// expressed in speed bands.
    ///
    /// **Update freq**: 5 minutes
    async fn get_traffic_speed_band<S>(client: &C, skip: S) -> LTAResult<Vec<TrafficSpeedBand>>
    where
        S: Into<Option<u32>>,
    {
        client
            .build_req_with_skip::<TrafficSpeedBandResp, _>(
                &concat_string!(client.base_url(), "/v3/TrafficSpeedBands"),
                skip.into(),
            )
            .await
    }

    /// Returns links to images of live traffic conditions along expressways and
    /// Woodlands & Tuas Checkpoints.
    ///
    /// **Update freq**: 1 to 5 minutes
    async fn get_traffic_images<S>(client: &C, skip: S) -> LTAResult<Vec<TrafficImage>>
    where
        S: Into<Option<u32>>,
    {
        client
            .build_req_with_skip::<TrafficImageResp, _>(
                &concat_string!(client.base_url(), "/Traffic-Imagesv2"),
                skip.into(),
            )
            .await
    }

    /// Returns current traffic speeds on expressways and arterial roads,
    /// expressed in speed bands.
    ///
    /// **Update freq**: 5 minutes
    async fn get_traffic_incidents<S>(client: &C, skip: S) -> LTAResult<Vec<TrafficIncident>>
    where
        S: Into<Option<u32>> + Send,
    {
        client
            .build_req_with_skip::<TrafficIncidentResp, _>(
                &concat_string!(client.base_url(), "/TrafficIncidents"),
                skip.into(),
            )
            .await
    }

    /// Returns traffic advisories (via variable message services) concerning
    /// current traffic conditions that are displayed on EMAS signboards
    /// along expressways and arterial roads.
    ///
    /// **Update freq**: 2 minutes
    async fn get_vms_emas<S>(client: &C, skip: S) -> LTAResult<Vec<Vms>>
    where
        S: Into<Option<u32>>,
    {
        client
            .build_req_with_skip::<VMSResp, _>(
                &concat_string!(client.base_url(), "/VMS"),
                skip.into(),
            )
            .await
    }

    /// Returns bicycle parking locations within a radius
    ///
    /// Dist is default to 0.5 even if you provide `None`
    ///
    /// **Update freq**: Monthly
    async fn get_bike_parking<D>(
        client: &C,
        lat: f64,
        long: f64,
        dist: D,
    ) -> LTAResult<Vec<BikeParking>>
    where
        D: Into<Option<f64>>;

    /// Returns hourly average traffic flow, taken from a representative month of
    /// every quarter during 0700-0900 hours.
    ///
    /// **Update freq**: Quaterly
    async fn get_traffic_flow(client: &C) -> LTAResult<Vec<String>> {
        client
            .build_req_with_skip::<TrafficFlowRawResp, _>(
                &concat_string!(client.base_url(), "/TrafficFlow"),
                None,
            )
            .await
    }
}