1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use Error;
use Week;
use Weekday;
use Building;
use reqwest;
#[derive(Debug)]
pub struct Room {
pub name: String,
}
impl From<String> for Room {
fn from(string: String) -> Self {
Room { name: string }
}
}
const BASE_URL: &'static str = "https://www2.htw-dresden.de/~app/API/GetFreeRooms.php";
impl Room {
pub fn get_free(week: Week,
day: Weekday,
start_time: &str,
end_time: &str,
building: Building)
-> Result<Vec<Room>, Error> {
let url = format!("{}?week={}&day={}&startTime={}&endTime={}&building={:?}",
BASE_URL,
week as u8,
day as u8,
start_time,
end_time,
building);
let rooms = reqwest::get(&url)
?
.json()
.map(|response: Vec<String>| response)?
.iter()
.map(|room| room.to_string().into())
.collect();
Ok(rooms)
}
}