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
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
extern crate reqwest;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;

mod grades;
pub use grades::{Course, Grade};
mod exams;
pub use exams::Exam;
mod lesson;
pub use lesson::Lesson;
mod rooms;
pub use rooms::Room;
mod semester;
pub use semester::{SemesterPlan, Period, Holiday};

pub type Year = u16;
pub type CourseId = u16;

#[derive(Deserialize, Debug)]
pub enum Week {
    Even,
    Odd,
}

#[derive(Deserialize, Debug)]
pub enum Weekday {
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday,
    Sunday,
}

#[derive(Debug)]
pub struct Studygroup {
    pub year: Year,
    pub course: CourseId,
    pub group: u16,
    pub degree: Degree,
}

impl Studygroup {
    pub fn identifier(&self) -> String {
        format!("{}/{}/{}", self.year, self.course, self.group)
    }
}

/// A degree, e.g. something you graduate with.
#[derive(Debug, Clone, Copy)]
pub enum Degree {
    Bachelor = 'B' as isize,
    Master = 'M' as isize,
    Diploma = 'D' as isize,
}

impl Degree {
    // fn short(&self) -> &'static str {
    //     match *self {
    //         Degree::Bachelor => "B",
    //         Degree::Master => "M",
    //         Degree::Diploma => "D",
    //     }
    // }

    // not quite sure yet if this a better solution than above...
    fn short(&self) -> String {
        ((*self as u8) as char).to_string()
    }
}

/// HTW Buildings supported by the API.
#[derive(Debug)]
pub enum Building {
    Z,
    S,
}

/// A login used to authenticate with the server.
pub struct Login {
    snumber: String,
    password: String,
}

impl Login {
    /// Create a new login
    ///
    /// # Arguments
    ///
    /// * `snumber` - The "sNummer", e.g. s12345
    /// * `password` - Password
    pub fn new(snumber: &str, password: &str) -> Login {
        Login {
            snumber: snumber.to_string(),
            password: password.to_string(),
        }
    }
}

/// A set of errors that may occur during execution.
#[derive(Debug)]
pub enum Error {
    Network(reqwest::Error),
}

impl From<reqwest::Error> for Error {
    fn from(err: reqwest::Error) -> Self {
        Error::Network(err)
    }
}