diff --git a/Cargo.lock b/Cargo.lock index 85dbcb8..d528ead 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -152,6 +152,19 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "time 0.1.43", + "winapi 0.3.9", +] + [[package]] name = "cipher" version = "0.2.5" @@ -902,6 +915,25 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.13.0" @@ -1258,6 +1290,7 @@ dependencies = [ name = "rust-api" version = "0.1.0" dependencies = [ + "chrono", "reqwest", "rocket", "rocket_contrib", diff --git a/Cargo.toml b/Cargo.toml index c994ff9..0442ebf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = "2018" [dependencies] rocket = "0.4.7" serde = "1.0.124" +chrono = "0.4.19" [dependencies.reqwest] version = "0.11.2" diff --git a/src/ivago/controller/mod.rs b/src/ivago/controller/mod.rs index 01f00a4..e2555c5 100644 --- a/src/ivago/controller/mod.rs +++ b/src/ivago/controller/mod.rs @@ -1,5 +1,7 @@ mod search; +mod pickup_times; pub use search::{Street, search_streets}; +pub use pickup_times::{get_pickup_times, PickupTime}; ///// Return the known pickup times for the given street and/or city diff --git a/src/ivago/controller/pickup_times.rs b/src/ivago/controller/pickup_times.rs index 98b8e64..37d84c4 100644 --- a/src/ivago/controller/pickup_times.rs +++ b/src/ivago/controller/pickup_times.rs @@ -1,19 +1,27 @@ +use std::error::Error; +use chrono::NaiveDate; +use super::search::Street; + + const BASE_URL: &str = "https://www.ivago.be/nl/particulier/afval/ophaling"; -/// Represents a timezoneless date -pub struct Date { - day: u8, - month: u8, - year: u32, -} - /// Represents a pickup time instance. All fields are a direct map of the /// original API pub struct PickupTime { - date: Date, + date: NaiveDate, label: String, classes: Vec, url: String } + + +pub fn get_pickup_times( + street: Street, + number: u64, + start_date: NaiveDate, + end_date: NaiveDate +) -> Result, Box> { + Ok(Vec::new()) +} diff --git a/src/ivago/mod.rs b/src/ivago/mod.rs index 7ba799e..8547130 100644 --- a/src/ivago/mod.rs +++ b/src/ivago/mod.rs @@ -2,10 +2,11 @@ mod controller; use rocket_contrib::json::Json; +use chrono::NaiveDate; pub fn routes() -> Vec { routes![ - search_streets_json, + route_search_streets, ] } @@ -13,12 +14,19 @@ pub fn routes() -> Vec { // TODO make this async // TODO change this so it can return errors instead of empty json #[get("/search?", format="json")] -pub fn search_streets_json(street: String) -> Json> { +pub fn route_search_streets(street: String) -> Json> { match controller::search_streets(&street) { Ok(streets) => Json(streets), - Err(err) => { - println!("{:?}", err); - Json(Vec::new()) - }, + Err(err) => Json(Vec::new()), } } + +#[get("/?&&&")] +pub fn route_get_pickup_times( + street: controller::Street, + number: u64, + start_date: NaiveDate, + end_date: NaiveDate + ) -> Json> { + +}