pub struct Client { /* private fields */ }
Implementations§
Source§impl Client
impl Client
pub fn new() -> Self
pub fn with_base_url(base_url: &str) -> Self
Sourcepub async fn arrivals(
&self,
request: ArrivalsRequest,
) -> Result<ArrivalsResponse>
pub async fn arrivals( &self, request: ArrivalsRequest, ) -> Result<ArrivalsResponse>
Returns a list of regional rail trains to arrive at a given station
This function calls into the /Arrivals/index.php
endpoint.
The returned list is split into northbound and southbound trains. The definition of “Northbound” and “Southbound” is defined by SEPTA as the following: The direction are obviously not geographical references, but rather a reference to the old Reading and Pennsy Railroads. The key to understanding the direction is by using Suburban Station as a starting point: Any trains that move eastbound towards Market East are all considered Northbound; trains going from suburban to 30th St are all Southbound. The path field describes more accurately the path of travel along various branches.
§Arguments
request
- A struct containing the request parameters
§Example
use septa_api::Client;
use septa_api::requests::ArrivalsRequest;
use septa_api::types::RegionalRailStop;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let request = ArrivalsRequest {
station: RegionalRailStop::SuburbanStation,
results: Some(5),
direction: None
};
let response = client.arrivals(request).await?;
// Loop through the northbound arrivals
for train in response.northbound {
println!("Train {} is currently {} on the {} line", train.train_id, train.status, train.line.to_string());
}
// Loop through the southbound arrivals
for train in response.southbound {
println!("Train {} is currently {} on the {} line", train.train_id, train.status, train.line.to_string());
}
Ok(())
}
Sourcepub async fn train_view(&self) -> Result<TrainResponse>
pub async fn train_view(&self) -> Result<TrainResponse>
Returns a list of all active regional rail trains
This function calls into the /TrainView/index.php
endpoint.
§Example
use septa_api::Client;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let response = client.train_view().await?;
for train in response {
println!("Train {} is currently {} mins late on the {} line", train.train_number, train.late, train.line.to_string());
}
Ok(())
}
Sourcepub async fn next_to_arrive(
&self,
request: NextToArriveRequest,
) -> Result<NextToArriveResponse>
pub async fn next_to_arrive( &self, request: NextToArriveRequest, ) -> Result<NextToArriveResponse>
Returns departure and arrival times between two different stations
This function calls into the /NextToArrive/index.php
endpoint.
§Arguments
request
- A struct containing the request parameters
§Example
use septa_api::Client;
use septa_api::requests::NextToArriveRequest;
use septa_api::types::RegionalRailStop;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let request = NextToArriveRequest {
starting_station: RegionalRailStop::SuburbanStation,
ending_station: RegionalRailStop::Downingtown,
results: None,
};
let response = client.next_to_arrive(request).await?;
for next_to_arrive in response {
println!("Train {} is scheduled to arrive {}", next_to_arrive.orig_train, next_to_arrive.orig_departure_time);
}
Ok(())
}
Sourcepub async fn rail_schedule(
&self,
request: RailScheduleRequest,
) -> Result<RailScheduleResponse>
pub async fn rail_schedule( &self, request: RailScheduleRequest, ) -> Result<RailScheduleResponse>
Returns the schedule for a train by the train’s number
This function calls into the /RRSchedules/index.php
endpoint.
§Arguments
request
- A struct containing the request parameters
§Example
use septa_api::Client;
use septa_api::requests::RailScheduleRequest;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let request = RailScheduleRequest {
train_number: "514".to_string()
};
let response = client.rail_schedule(request).await?;
for schedule in response {
println!("The train is scheduled to arrive at {} at {}", schedule.station.to_string(), schedule.scheduled_time);
}
Ok(())
}