Crates.io | septa-api |
lib.rs | septa-api |
version | 0.4.0 |
source | src |
created_at | 2023-04-12 22:28:41.122123 |
updated_at | 2024-06-16 01:46:28.777044 |
description | SEPTA Async Rust API Client |
homepage | |
repository | https://github.com/StefanBossbaly/septa-api/ |
max_upload_size | |
id | 837343 |
size | 124,901 |
This project provides developers with a standard and ergonomic Rust API for calling the various endpoints in SEPTA (Southeastern Pennsylvania Transportation Authority) API. It handles the serialization and deserialization of the requests and responses and allows the developer to use the provided well-defined data types. It also handles some of the messy parts of the API (multiple serializations per stop, quarky endpoint responses, multiple datetime formats, etc).
use septa_api::{requests, types, Client};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a new client with the default url
let client = Client::new();
// Get a list of all active trains
let train_view_response = client.train_view().await?;
for train in train_view_response {
println!("Train {} is heading to {}", train.train_number, train.dest);
}
// Make a request to get the next arrivals
let arrivals_request = requests::ArrivalsRequest {
station: types::RegionalRailStop::TempleUniversity,
results: None,
direction: None,
};
let arrivals_response = client.arrivals(arrivals_request).await?;
println!("Trains coming in southbound:");
for southbound_arrival in arrivals_response.southbound {
println!(
"Train {} is {}",
southbound_arrival.train_id, southbound_arrival.status
);
}
println!("Trains coming in northbound:");
for northbound_arrival in arrivals_response.northbound {
println!(
"Train {} is {}",
northbound_arrival.train_id, northbound_arrival.status
);
}
Ok(())
}
This crate is tested daily during the morning (8:30 AM EST) and evening (5:15 PM EST) rush hour commutes and in the dead of the night (3 AM EST). You may wonder why such a dichotomy, and the reason is to attempt to get data when the network is at its peak and during a lull. SEPTA is not the best in outlining all their API responses so some of this library is reversed engineered. By capturing both these states, we hope to detect any breaking changes in SEPTA's API and can therefore fix them ASAP.
Endpoint | Implemented | Tested |
---|---|---|
/Arrivals/index.php |
✅ | ✅ |
/TrainView/index.php |
✅ | ✅ |
/NextToArrive/index.php |
✅ | ✅ |
/TransitView/index.php |
❌ | ❌ |
/TransitViewAll/index.php |
❌ | ❌ |
/BusDetours/index.php |
❌ | ❌ |
/Alerts/index.php |
❌ | ❌ |
/Alerts/get_alert_data.php |
❌ | ❌ |
/elevator/index.php |
❌ | ❌ |
Endpoint | Implemented | Tested |
---|---|---|
/RRSchedules/index.php |
✅ | ✅ |
/BusSchedules/index.php |
❌ | ❌ |
/Stops/index.php |
❌ | ❌ |
/locations/get_locations.php |
❌ | ❌ |
Stefan Bossbaly
This project is licensed under the MIT License - see the LICENSE file for details