Skip to main content

Client

Struct Client 

Source
pub struct Client {
    pub key: String,
}
Expand description

MetroBus client. Used to fetch MetroBus-related information from the WMATA API.

Fields§

§key: String

The WMATA API key to use for all requests routed through this client.

Implementations§

Source§

impl Client

Source

pub fn new(api_key: &str) -> Self

Constructor for the MetroRail client.

§Example
use wmata::MetroBus;

let client = MetroBus::new("9e38c3eab34c4e6c990828002828f5ed");
Source§

impl Client

Source

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());
Source

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

Source

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());
Source

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());
Source

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());
Source

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

Source

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());
Source

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());

Trait Implementations§

Source§

impl FromStr for Client

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Converts a string into a MetroBus Client.

§Examples
use wmata::MetroBus;
let client: MetroBus = "9e38c3eab34c4e6c990828002828f5ed".parse().unwrap();

assert_eq!(client.key, "9e38c3eab34c4e6c990828002828f5ed");
Source§

type Err = Error

The associated error which can be returned from parsing.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more