diff --git a/src/gtfs/mod.rs b/src/gtfs/mod.rs index 1d14b94..953059a 100644 --- a/src/gtfs/mod.rs +++ b/src/gtfs/mod.rs @@ -2,6 +2,7 @@ mod arrival; mod loader; mod utils; mod refresher; +mod realtime; pub mod structs; use chrono::{DateTime, Local, Timelike}; use log::{debug, trace}; @@ -10,7 +11,7 @@ use gtfs_structures::{Exception, RawTrip}; use crate::gtfs::{loader::load_gtfs, structs::{Arrival, Gtfs, Preferences, Error}}; -impl Gtfs { +impl Gtfs<'_> { pub fn get_next_arrivals_for(&self, target_datetime: &DateTime) -> Option>> { let naive_target = target_datetime.naive_local(); @@ -98,6 +99,7 @@ impl Gtfs { let mut zip_reader = zip::ZipArchive::new(zip_file)?; let mut gtfs: Gtfs = Gtfs { + preferences: prefs, agencies: Vec::new(), calendar: HashMap::new(), calendar_dates: HashMap::new(), diff --git a/src/gtfs/realtime.rs b/src/gtfs/realtime.rs new file mode 100644 index 0000000..7a24992 --- /dev/null +++ b/src/gtfs/realtime.rs @@ -0,0 +1,36 @@ +/*** + * Implementation of GTFS-R polling + */ + +use std::{str::FromStr, time::Duration}; + +use reqwest::{blocking::Client, header::{HeaderName, HeaderValue}}; + +use crate::gtfs::structs::{Arrival, Error, Gtfs}; + +impl Gtfs<'_> { + fn realtime_update (&self, arrivals: Vec>) -> Result{ + + // Poll GTFS-R API + let client = Client::builder() + .timeout(Duration::from_secs(10)) + .connect_timeout(Duration::from_secs(5)) + .build()?; + + let mut response = client + .get(self.preferences.realtime_url) + .header("x-api-key", self.preferences.realtime_api_key) + .send()?; + + // Parse response + let response = json::rdr + + // Match deltas to existing arrivals + + // Update the arrival times + + } + + + +} \ No newline at end of file diff --git a/src/gtfs/structs.rs b/src/gtfs/structs.rs index 75bcdef..42187f5 100644 --- a/src/gtfs/structs.rs +++ b/src/gtfs/structs.rs @@ -74,7 +74,10 @@ impl Preferences { // The main GTFS struct. This is similar to (but not exactly) gtfs-structures::Gtfs because we don't need everything #[derive(Debug)] -pub struct Gtfs { +pub struct Gtfs<'a> { + /// A copy of the preferences struct + pub(crate) preferences: &'a Preferences, + /// All agencies. They can not be read by `agency_id`, as it is not a required field pub(crate) agencies: Vec, /// All Calendar by `service_id`