From c37a114a78762c8b3778346c1bd4cbf78647d09a Mon Sep 17 00:00:00 2001 From: jzitnik-dev Date: Wed, 11 Feb 2026 22:09:32 +0100 Subject: [PATCH] docs: Add official lib --- web/content/posts/api/lib/index.md | 210 +++++++++++++++++++++++++++ web/content/posts/api/usage/index.md | 4 + 2 files changed, 214 insertions(+) create mode 100644 web/content/posts/api/lib/index.md diff --git a/web/content/posts/api/lib/index.md b/web/content/posts/api/lib/index.md new file mode 100644 index 0000000..90d4d71 --- /dev/null +++ b/web/content/posts/api/lib/index.md @@ -0,0 +1,210 @@ +--- +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!** diff --git a/web/content/posts/api/usage/index.md b/web/content/posts/api/usage/index.md index 468701c..19e512b 100644 --- a/web/content/posts/api/usage/index.md +++ b/web/content/posts/api/usage/index.md @@ -6,6 +6,10 @@ tags: ["api", "docs"] Vítejte v dokumentaci pro API systému Ječná Rozvrh. Toto API poskytuje programový přístup k rozvrhům, suplování a dalším informacím. +## Oficiální knihovna + +[Oficiální knihovna pro komunikaci s Ječná Rozvrh API](../lib) + ## Základní Informace ### URL