--- title: "Oficiální knihovna" date: 2025-12-20 tags: ["api", "docs"] hiddenInHomelist: true TocOpen: true --- 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`. ```rust 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: ```rust client.set_provider("https://jecnarozvrh.example.com"); ``` ### `get_schedule(class_name: String) -> Result` Example usage: ```rust 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` Example usage: ```rust match client.get_teacher_absence() { Ok(result) => { /* Code */ } Err(error) => { panic!("Error: {}", error) } } ``` ### `get_all() -> Result` Example usage: ```rust 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: ```rust 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 ```rust #[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, teacher_code: String, }, Single { teacher: Option, teacher_code: String, hours: u16, }, Range { teacher: Option, teacher_code: String, hours: AbsenceRange, }, Exkurze { teacher: Option, teacher_code: String, }, Zastoupen { teacher: Option, teacher_code: String, zastupuje: SubstituteInfo, }, Invalid { original: String }, } pub struct AbsenceRange { pub from: u16, pub to: u16, } pub struct SubstituteInfo { pub teacher: Option, pub teacher_code: String, } pub struct ChangeEntry { pub text: String, pub background_color: Option, pub foreground_color: Option, pub will_be_specified: Option, } pub struct ApiResponse { pub status: Status, pub schedule: HashMap, } pub struct DailyData { pub info: DayInfo, pub changes: HashMap>>, pub absence: Vec, pub takes_place: String, pub reserved_rooms: Vec>, } 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, } pub struct DailySchedule { pub info: DayInfo, pub changes: Vec>, pub absence: Vec, pub takes_place: String, } pub struct TeacherAbsenceResult { pub absences: HashMap>, } ``` ## Mappings do jiných jazyků ### Kotlin - [Mappings (required)](https://mvnrepository.com/artifact/cz.jzitnik/jecna-supl-client) Jednotlivé buildy: - [Android](https://mvnrepository.com/artifact/cz.jzitnik/jecna-supl-client-android) - [Linux X64](https://mvnrepository.com/artifact/cz.jzitnik/jecna-supl-client-linux-x64) - [Windows X64](https://mvnrepository.com/artifact/cz.jzitnik/jecna-supl-client-windows-x64) Všechny funkce jsou mappovány do `camelCase`. **Nejedná se o suspend funkce!**