pub struct Client {
pub key: String,
}Expand description
MetroBus client. Used to fetch MetroBus-related information from the WMATA API.
Fields§
§key: StringThe WMATA API key to use for all requests routed through this client.
Implementations§
Source§impl Client
impl Client
Sourcepub async fn routes(&self) -> Result<Routes, Error>
pub async fn routes(&self) -> Result<Routes, Error>
List of all bus route variants. WMATA Documentation
§Examples
use wmata::MetroBus;
use tokio_test::block_on;
let client = MetroBus::new("9e38c3eab34c4e6c990828002828f5ed");
let routes = block_on(async { client.routes().await });
assert!(routes.is_ok());Sourcepub async fn stops(
&self,
radius_at_lat_long: Option<RadiusAtLatLong>,
) -> Result<Stops, Error>
pub async fn stops( &self, radius_at_lat_long: Option<RadiusAtLatLong>, ) -> Result<Stops, Error>
Nearby bus stops based on latitude, longitude, and radius. WMATA Documentation
§Examples
use wmata::{MetroBus, RadiusAtLatLong};
use tokio_test::block_on;
let client = MetroBus::new("9e38c3eab34c4e6c990828002828f5ed");
let stops = block_on(async { client.stops(Some(RadiusAtLatLong::new(1000, 38.8817596, -77.0166426))).await });
assert!(stops.is_ok());Source§impl Client
impl Client
Sourcepub async fn positions_along(
&self,
route: Option<Route>,
radius_at_lat_long: Option<RadiusAtLatLong>,
) -> Result<BusPositions, Error>
pub async fn positions_along( &self, route: Option<Route>, radius_at_lat_long: Option<RadiusAtLatLong>, ) -> Result<BusPositions, Error>
Bus positions for the given route around a given lat/long. WMATA Documentation
§Example
use wmata::{MetroBus, Route, RadiusAtLatLong};
use tokio_test::block_on;
let client = MetroBus::new("9e38c3eab34c4e6c990828002828f5ed");
let positions = block_on(async {
client.positions_along(
Some(Route::A2),
Some(RadiusAtLatLong::new(1000, 38.8817596, -77.0166426))
).await
});
assert!(positions.is_ok());Sourcepub async fn incidents_along(
&self,
route: Option<Route>,
) -> Result<Incidents, Error>
pub async fn incidents_along( &self, route: Option<Route>, ) -> Result<Incidents, Error>
Reported bus incidents/delays for a given route. WMATA Documentation
§Examples
use wmata::{MetroBus, Route};
use tokio_test::block_on;
let client = MetroBus::new("9e38c3eab34c4e6c990828002828f5ed");
let incidents = block_on(async { client.incidents_along(Some(Route::A2)).await });
assert!(incidents.is_ok());Sourcepub async fn path(
&self,
route: Route,
date: Option<Date>,
) -> Result<PathDetails, Error>
pub async fn path( &self, route: Route, date: Option<Date>, ) -> Result<PathDetails, Error>
For an optional given date, returns the set of ordered latitude/longitude points along a route variant along with the list of stops served. WMATA Documentation
§Date
Omit date for current date
§Examples
use wmata::{MetroBus, Route};
use tokio_test::block_on;
let client = MetroBus::new("9e38c3eab34c4e6c990828002828f5ed");
let path = block_on(async { client.path(Route::A2, None).await });
assert!(path.is_ok());With a date
use wmata::{MetroBus, Route, Date};
use tokio_test::block_on;
let client = MetroBus::new("9e38c3eab34c4e6c990828002828f5ed");
let path = block_on(async { client.path(Route::A2, Some(Date::new(2019, 10, 2))).await });
assert!(path.is_ok());Sourcepub async fn route_schedule(
&self,
route: Route,
date: Option<Date>,
including_variations: bool,
) -> Result<RouteSchedule, Error>
pub async fn route_schedule( &self, route: Route, date: Option<Date>, including_variations: bool, ) -> Result<RouteSchedule, Error>
Schedules for a given route variant for an optional given date. WMATA Documentation
§Date
Omit date for current date
§Variations
Whether or not to include variations if a base route is specified in Route. For example, if B30 is specified and IncludingVariations is set to true, data for all variations of B30 such as B30v1, B30v2, etc. will be returned.
§Examples
use wmata::{MetroBus, Route};
use tokio_test::block_on;
let client = MetroBus::new("9e38c3eab34c4e6c990828002828f5ed");
let route_schedule = block_on(async { client.route_schedule(Route::A2, None, false).await });
assert!(route_schedule.is_ok());with date and variations
use wmata::{MetroBus, Route, Date};
use tokio_test::block_on;
let client = MetroBus::new("9e38c3eab34c4e6c990828002828f5ed");
let route_schedule = block_on(async { client.route_schedule(Route::A2, Some(Date::new(2019, 10, 2)), true).await });
assert!(route_schedule.is_ok());Source§impl Client
impl Client
Sourcepub async fn next_buses(&self, stop: Stop) -> Result<Predictions, Error>
pub async fn next_buses(&self, stop: Stop) -> Result<Predictions, Error>
Next bus arrivals at a given stop. WMATA Documentation
§Examples
use wmata::{MetroBus, Stop};
use tokio_test::block_on;
let client = MetroBus::new("9e38c3eab34c4e6c990828002828f5ed");
let next_buses = block_on(async { client.next_buses(Stop::new("1001195")).await });
assert!(next_buses.is_ok());Sourcepub async fn stop_schedule(
&self,
stop: Stop,
date: Option<Date>,
) -> Result<StopSchedule, Error>
pub async fn stop_schedule( &self, stop: Stop, date: Option<Date>, ) -> Result<StopSchedule, Error>
Buses scheduled at a stop for an optional given date. WMATA Documentation
§Date
Omit date for current date
§Examples
use wmata::{MetroBus, Stop};
use tokio_test::block_on;
let client = MetroBus::new("9e38c3eab34c4e6c990828002828f5ed");
let stop_schedule = block_on(async { client.stop_schedule(Stop::new("1001195"), None).await });
assert!(stop_schedule.is_ok());with date
use wmata::{MetroBus, Stop, Date};
use tokio_test::block_on;
let client = MetroBus::new("9e38c3eab34c4e6c990828002828f5ed");
let stop_schedule = block_on(async { client.stop_schedule(Stop::new("1001195"), Some(Date::new(2019, 10, 2))).await });
assert!(stop_schedule.is_ok());