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
//! All API pertaining to traffic related data
use futures::Future;
use reqwest::Error;

use crate::r#async::lta_client::LTAClient;
use crate::traffic::*;
use crate::utils::commons::Client;

/// Returns ERP rates of all vehicle types across all timings for each
/// zone.
///
/// **Update freq**: Ad-Hoc
pub fn get_erp_rates(
    client: &LTAClient,
) -> impl Future<Item = Vec<erp_rates::ErpRate>, Error = Error> {
    let rb = client.get_req_builder(erp_rates::URL);
    rb.send()
        .and_then(|mut f| f.json::<erp_rates::ErpRatesResp>())
        .map(|r| r.value)
}

/// 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
pub fn get_carkpark_avail(
    client: &LTAClient,
) -> impl Future<Item = Vec<carpark_avail::Carpark>, Error = Error> {
    let rb = client.get_req_builder(carpark_avail::URL);
    rb.send()
        .and_then(|mut f| f.json::<carpark_avail::CarparkAvailResp>())
        .map(|r| r.value)
}

/// Returns estimated travel times of expressways (in segments).
///
/// **Update freq**: 5min
pub fn get_est_travel_time(
    client: &LTAClient,
) -> impl Future<Item = Vec<est_travel_time::EstTravelTime>, Error = Error> {
    let rb = client.get_req_builder(est_travel_time::URL);
    rb.send()
        .and_then(|mut f| f.json::<est_travel_time::EstTravelTimeResp>())
        .map(|r| r.value)
}

/// Returns alerts of traffic lights that are currently faulty, or currently
/// undergoing scheduled maintenance.
///
/// **Update freq**: 2min or whenever there are updates
pub fn get_faulty_traffic_lights(
    client: &LTAClient,
) -> impl Future<Item = Vec<faulty_traffic_lights::FaultyTrafficLight>, Error = Error> {
    let rb = client.get_req_builder(faulty_traffic_lights::URL);
    rb.send()
        .and_then(|mut f| f.json::<faulty_traffic_lights::FaultyTrafficLightResp>())
        .map(|r| r.value)
}

/// Returns all planned road openings
///
/// **Update freq**: 24 hours – whenever there are updates
pub fn get_road_details(
    client: &LTAClient,
    road_details_type: road::RoadDetailsType,
) -> impl Future<Item = Vec<road::RoadDetails>, Error = Error> {
    let url = match road_details_type {
        road::RoadDetailsType::RoadOpening => road::URL_ROAD_OPENING,
        road::RoadDetailsType::RoadWorks => road::URL_ROAD_WORKS,
    };

    let rb = client.get_req_builder(url);
    rb.send()
        .and_then(|mut f| f.json::<road::RoadDetailsResp>())
        .map(|r| r.value)
}

/// Returns links to images of live traffic conditions along expressways and
/// Woodlands & Tuas Checkpoints.
///
/// **Update freq**: 1 to 5 minutes
pub fn get_traffic_images(
    client: &LTAClient,
) -> impl Future<Item = Vec<traffic_images::TrafficImage>, Error = Error> {
    let rb = client.get_req_builder(traffic_images::URL);
    rb.send()
        .and_then(|mut f| f.json::<traffic_images::TrafficImageResp>())
        .map(|r| r.value)
}

/// Returns current traffic speeds on expressways and arterial roads,
/// expressed in speed bands.
///
/// **Update freq**: 5 minutes
pub fn get_traffic_incidents(
    client: &LTAClient,
) -> impl Future<Item = Vec<traffic_incidents::TrafficIncident>, Error = Error> {
    let rb = client.get_req_builder(traffic_incidents::URL);
    rb.send()
        .and_then(|mut f| f.json::<traffic_incidents::TrafficIncidentResp>())
        .map(|r| r.value)
}

/// Returns current traffic speeds on expressways and arterial roads,
/// expressed in speed bands.
///
/// **Update freq**: 5 minutes
pub fn get_traffic_speed_band(
    client: &LTAClient,
) -> impl Future<Item = Vec<traffic_speed_bands::TrafficSpeedBand>, Error = Error> {
    let rb = client.get_req_builder(traffic_speed_bands::URL);
    rb.send()
        .and_then(|mut f| f.json::<traffic_speed_bands::TrafficSpeedBandResp>())
        .map(|r| r.value)
}

/// 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
pub fn get_vms_emas(client: &LTAClient) -> impl Future<Item = Vec<vms_emas::VMS>, Error = Error> {
    let rb = client.get_req_builder(vms_emas::URL);
    rb.send()
        .and_then(|mut f| f.json::<vms_emas::VMSResp>())
        .map(|r| r.value)
}

/// Returns bicycle parking locations within a radius
///
/// Dist is default to 0.5 even if you provide `None`
///
/// **Update freq**: Monthly
pub fn get_bike_parking(
    client: &LTAClient,
    lat: f64,
    long: f64,
    dist: Option<f64>,
) -> impl Future<Item = Vec<bike_parking::BikeParking>, Error = Error> {
    let unwrapped_dist = dist.unwrap_or(0.5);
    let rb = client.get_req_builder(bike_parking::URL).query(&[
        ("Lat", lat),
        ("Long", long),
        ("Dist", unwrapped_dist),
    ]);

    rb.send()
        .and_then(|mut f| f.json::<bike_parking::BikeParkingResp>())
        .map(|r| r.value)
}