Added code formatting
parent
68434ca75f
commit
e3f134a9bf
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# This hook lints the code, and if we're on develop or master, also forces the tests to pass.
|
||||
cargo fmt -- --check
|
||||
|
||||
branch=`git rev-parse --abbrev-ref HEAD`
|
||||
|
||||
|
|
4
Makefile
4
Makefile
|
@ -32,6 +32,10 @@ test:
|
|||
@ cargo test
|
||||
.PHONY: test
|
||||
|
||||
format:
|
||||
@ cargo fmt
|
||||
.PHONY: format
|
||||
|
||||
|
||||
# Documentation
|
||||
docs:
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
#[cfg(test)] mod tests;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
pub fn routes() -> Vec<rocket::Route> {
|
||||
routes![
|
||||
world,
|
||||
hello,
|
||||
name_age
|
||||
]
|
||||
routes![world, hello, name_age]
|
||||
}
|
||||
|
||||
#[get("/world")]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use rocket::local::Client;
|
||||
use rocket::http::Status;
|
||||
use rocket::local::Client;
|
||||
|
||||
fn rocket() -> rocket::Rocket {
|
||||
rocket::ignite().mount("/", super::routes())
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
mod search;
|
||||
mod pickup_times;
|
||||
pub use search::{Street, search_streets};
|
||||
mod search;
|
||||
pub use pickup_times::{get_pickup_times, PickupTime};
|
||||
|
||||
pub use search::{search_streets, Street};
|
||||
|
||||
///// Return the known pickup times for the given street and/or city
|
||||
/////
|
||||
|
@ -30,7 +29,7 @@ pub use pickup_times::{get_pickup_times, PickupTime};
|
|||
// let params = [
|
||||
// ("_format", "json"),
|
||||
// ("type", ""),
|
||||
|
||||
|
||||
// ]
|
||||
|
||||
//r2 = s.get("https://www.ivago.be/nl/particulier/garbage/pick-up/pickups?",
|
||||
|
|
|
@ -1,27 +1,23 @@
|
|||
use std::error::Error;
|
||||
use chrono::NaiveDate;
|
||||
use super::search::Street;
|
||||
|
||||
use chrono::NaiveDate;
|
||||
use std::error::Error;
|
||||
|
||||
const BASE_URL: &str = "https://www.ivago.be/nl/particulier/afval/ophaling";
|
||||
|
||||
|
||||
|
||||
/// Represents a pickup time instance. All fields are a direct map of the
|
||||
/// original API
|
||||
pub struct PickupTime {
|
||||
date: NaiveDate,
|
||||
label: String,
|
||||
classes: Vec<String>,
|
||||
url: String
|
||||
url: String,
|
||||
}
|
||||
|
||||
|
||||
pub fn get_pickup_times(
|
||||
street: Street,
|
||||
number: u64,
|
||||
start_date: NaiveDate,
|
||||
end_date: NaiveDate
|
||||
end_date: NaiveDate,
|
||||
) -> Result<Vec<PickupTime>, Box<dyn Error>> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
use reqwest::blocking as reqwest;
|
||||
use serde::ser::{Serialize, SerializeStruct, Serializer};
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryFrom;
|
||||
use serde::ser::{Serialize, Serializer, SerializeStruct};
|
||||
use std::error::Error;
|
||||
|
||||
|
||||
/// Endpoint for the search feature
|
||||
const SEARCH_URL: &str ="https://www.ivago.be/nl/particulier/autocomplete/garbage/streets";
|
||||
|
||||
const SEARCH_URL: &str = "https://www.ivago.be/nl/particulier/autocomplete/garbage/streets";
|
||||
|
||||
impl From<Street> for String {
|
||||
fn from(street: Street) -> String {
|
||||
|
@ -15,44 +13,39 @@ impl From<Street> for String {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl Serialize for Street {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut s = serializer.serialize_struct("Street", 2)?;
|
||||
s.serialize_field("name", &self.name)?;
|
||||
s.serialize_field("city", &self.city)?;
|
||||
s.end()
|
||||
}
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut s = serializer.serialize_struct("Street", 2)?;
|
||||
s.serialize_field("name", &self.name)?;
|
||||
s.serialize_field("city", &self.city)?;
|
||||
s.end()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl TryFrom<String> for Street {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(value: String) -> Result<Self, Self::Error> {
|
||||
if let Some(index) = value.find('(') {
|
||||
Ok(Street {
|
||||
name: (value[0 .. index - 1].trim()).to_string(),
|
||||
city: (value[index + 1 .. value.len() - 1].trim()).to_string(),
|
||||
name: (value[0..index - 1].trim()).to_string(),
|
||||
city: (value[index + 1..value.len() - 1].trim()).to_string(),
|
||||
})
|
||||
|
||||
}else {
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Represents a street
|
||||
pub struct Street {
|
||||
pub name: String,
|
||||
pub city: String,
|
||||
}
|
||||
|
||||
|
||||
/// Searches the Ivago API for streets in the given city
|
||||
///
|
||||
/// # Arguments
|
||||
|
@ -62,9 +55,7 @@ pub struct Street {
|
|||
// TODO find out how to do this async
|
||||
pub fn search_streets(street_name: &String) -> Result<Vec<Street>, Box<dyn Error>> {
|
||||
let client = reqwest::Client::new();
|
||||
let response = client.get(SEARCH_URL)
|
||||
.query(&[("q", street_name)])
|
||||
.send()?;
|
||||
let response = client.get(SEARCH_URL).query(&[("q", street_name)]).send()?;
|
||||
let data: Vec<HashMap<String, String>> = response.json()?;
|
||||
|
||||
let mut output: Vec<Street> = Vec::new();
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
#[cfg(test)] mod tests;
|
||||
mod controller;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use rocket_contrib::json::Json;
|
||||
use chrono::NaiveDate;
|
||||
use rocket_contrib::json::Json;
|
||||
|
||||
pub fn routes() -> Vec<rocket::Route> {
|
||||
routes![
|
||||
route_search_streets,
|
||||
]
|
||||
routes![route_search_streets,]
|
||||
}
|
||||
|
||||
// URL: https://www.ivago.be/nl/particulier/autocomplete/garbage/streets?q=Lange
|
||||
|
@ -26,7 +25,6 @@ pub fn route_get_pickup_times(
|
|||
street: controller::Street,
|
||||
number: u64,
|
||||
start_date: NaiveDate,
|
||||
end_date: NaiveDate
|
||||
) -> Json<Vec<controller::PickupTime>> {
|
||||
|
||||
end_date: NaiveDate,
|
||||
) -> Json<Vec<controller::PickupTime>> {
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
|
||||
#[macro_use] extern crate rocket;
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
|
||||
// Route modules
|
||||
mod hello;
|
||||
|
|
Loading…
Reference in New Issue