diff --git a/client/bin/Cargo.toml b/client/bin/Cargo.toml index 2a0eddb..e02cd5d 100644 --- a/client/bin/Cargo.toml +++ b/client/bin/Cargo.toml @@ -17,3 +17,7 @@ datetime = "0.5.2" # Necessary for web crawler openssl = { version = "0.10", features = ["vendored"] } reqwest = { version = "0.11", features = ["blocking", "json"] } +serde = "1.0" +serde_derive = "1.0" +serde_json = "1.0" +# end of web stuff diff --git a/client/bin/src/straba.rs b/client/bin/src/straba.rs index 91e51b3..9175226 100644 --- a/client/bin/src/straba.rs +++ b/client/bin/src/straba.rs @@ -2,12 +2,62 @@ * @brief fetch next depature of light rail vehicle */ use std::error::Error; +use serde::Deserialize; -const stationURL:&str = "https://www.rnv-online.de/rest/departure/2494/1"; +const stationURL:&str = "https://www.rnv-online.de/rest/departure/2494"; -pub fn fetchData() -> Result<(), Box> { - println!("Test RNV API"); - let resp = reqwest::blocking::get(stationURL)?.text()?; - println!("{:#?}", resp); - Ok(()) +#[derive(Default, Debug, Clone, PartialEq, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Station { + pub id: i64, + pub name: String, + pub lines: Vec, + pub journeys: Vec, +} + +#[derive(Default, Debug, Clone, PartialEq, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Line { + pub id: i64, + pub text: String, + pub iconOutlined: i64, + pub iconColor: String, + pub iconTextColor: i64, +} + +#[derive(Default, Debug, Clone, PartialEq, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Journey { + pub line: Line, + pub destination: String, + pub barrierLevel: String, + pub loadsForecastType: String, + pub realtimeDeparture: i64, + pub scheduledDeparture: i64, + pub difference: i64, + pub canceled: bool, +} + +pub struct NextDeparture { + pub rheinau: i64, + pub schoenau: i64, +} + + +pub fn fetchData() -> Result { + let result = reqwest::blocking::get(stationURL); + + let response = match result { + Ok(res) => res, + Err(err) => return reqwest::Error(err), + }; + + let body = serde_json::from_str(&text); + + let json = match body { + Ok(json) => json, + Err(err) => return reqwest::Error(err), + }; + let date = json["id"].to_string(); + Ok(date) }