Ječná Rozvrh API má svoji Rust knihovnu pro komunikaci s API. Obsahuje mappings pro Kotlin. Pro další jazyky budou mappingy v budoucnu.

Usage

JecnaSuplClient struct

Knihovna používá JecnaSuplClient struct. Vytvoříte instanci pomocí new.

fn main() {
    let client = JecnaSuplClient::new();
}

set_provider(url: String)

Pokud nenastavíte vlastní provider path API použije hosted https://jecnarozvrh.jzitnik.dev

Example usage:

client.set_provider("https://jecnarozvrh.example.com");

get_schedule(class_name: String) -> Result<SuplResult, SuplError>

Example usage:

let class = String::from("C2c");
match client.get_schedule(class) {
    Ok(result) => {
        println!("Last update: {}", result.status.last_updated);
    }
    Err(error) => {
        panic!("Error: {}", error)
    }
}

get_teacher_absence() -> Result<TeacherAbsenceResult, SuplError>

Example usage:

match client.get_teacher_absence() {
    Ok(result) => {
        /* Code */
    }
    Err(error) => {
        panic!("Error: {}", error)
    }
}

get_all() -> Result<ApiResponse, SuplError>

Example usage:

match client.get_all() {
    Ok(result) => {
        /* Code */
    }
    Err(error) => {
        panic!("Error: {}", error)
    }
}

report(content: String, class: String, report_location: ReportLocation) -> Result<(), SuplError>

Report function for reporting errors of the parser to the provider.

Example usage:

let content = String::from("Detailni popis chyby");
let class = String::from("C2c");
let report_location = ReportLocation::Timetable;

match client.report(content, class, report_location) {
    Ok(result) => {
        println!("Success");
    }
    Err(error) => {
        panic!("Error: {}", error)
    }
}

Datové struktury

#[derive(Debug, thiserror::Error, uniffi::Error)]
pub enum SuplError {
    #[error("Network error: {reason}")]
    NetworkError { reason: String },
    #[error("Parse error: {reason}")]
    ParseError { reason: String },
    #[error("Invalid date format: {reason}")]
    DateFormatError { reason: String },
    #[error("Internal runtime error: {reason}")]
    RuntimeError { reason: String },
}

pub enum AbsenceEntry {
    WholeDay {
        teacher: Option<String>,
        teacher_code: String,
    },
    Single {
        teacher: Option<String>,
        teacher_code: String,
        hours: u16,
    },
    Range {
        teacher: Option<String>,
        teacher_code: String,
        hours: AbsenceRange,
    },
    Exkurze {
        teacher: Option<String>,
        teacher_code: String,
    },
    Zastoupen {
        teacher: Option<String>,
        teacher_code: String,
        zastupuje: SubstituteInfo,
    },
    Invalid { original: String },
}

pub struct AbsenceRange {
    pub from: u16,
    pub to: u16,
}

pub struct SubstituteInfo {
    pub teacher: Option<String>,
    pub teacher_code: String,
}

pub struct ChangeEntry {
    pub text: String,
    pub background_color: Option<String>,
    pub foreground_color: Option<String>,
    pub will_be_specified: Option<bool>,
}

pub struct ApiResponse {
    pub status: Status,
    pub schedule: HashMap<String, DailyData>,
}

pub struct DailyData {
    pub info: DayInfo,
    pub changes: HashMap<String, Vec<Option<ChangeEntry>>>,
    pub absence: Vec<AbsenceEntry>,
    pub takes_place: String,
    pub reserved_rooms: Vec<Option<String>>,
}

pub struct DayInfo {
    pub in_work: bool,
}

pub struct Status {
    pub last_updated: String,
    pub current_update_schedule: u16,
}

pub struct SuplResult {
    pub status: Status,
    pub schedule: HashMap<String, DailySchedule>,
}

pub struct DailySchedule {
    pub info: DayInfo,
    pub changes: Vec<Option<ChangeEntry>>,
    pub absence: Vec<AbsenceEntry>,
    pub takes_place: String,
}

pub struct TeacherAbsenceResult {
    pub absences: HashMap<String, Vec<AbsenceEntry>>,
}

Mappings do jiných jazyků

Kotlin

Jednotlivé buildy:

Všechny funkce jsou mappovány do camelCase. Nejedná se o suspend funkce!