docs: Add official lib
This commit is contained in:
210
web/content/posts/api/lib/index.md
Normal file
210
web/content/posts/api/lib/index.md
Normal file
@@ -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<SuplResult, SuplError>`
|
||||
|
||||
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<TeacherAbsenceResult, SuplError>`
|
||||
|
||||
Example usage:
|
||||
|
||||
```rust
|
||||
match client.get_teacher_absence() {
|
||||
Ok(result) => {
|
||||
/* Code */
|
||||
}
|
||||
Err(error) => {
|
||||
panic!("Error: {}", error)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### `get_all() -> Result<ApiResponse, SuplError>`
|
||||
|
||||
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<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
|
||||
|
||||
- [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!**
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user