librus-rs
Rust client for Librus Synergia - the Polish school diary system.
Installation
Add to your Cargo.toml:
[dependencies]
librus-rs = "2.0"
tokio = { version = "1", features = ["full"] }
Quick Start
use librus_rs::Client;
#[tokio::main]
async fn main() -> Result<(), librus_rs::Error> {
let mut client = Client::from_env().await?;
let grades = client.grades().await?;
for grade in grades.grades {
println!("{}: {}", grade.date, grade.grade);
}
let unread = client.unread_counts().await?;
println!("Unread messages: {}", unread.inbox);
let messages = client.inbox_messages(1, 10).await?;
for msg in messages {
println!("{}: {}", msg.sender_name, msg.topic);
}
Ok(())
}
Client Construction
Three ways to create a client:
use librus_rs::Client;
let client = Client::from_env().await?;
let client = Client::new("username", "password").await?;
let client = Client::builder()
.username("username")
.password("password")
.build()
.await?;
API Reference
Synergia API
Base URL: https://synergia.librus.pl/gateway/api/2.0/
| Method |
Description |
me() |
Get current user info |
grades() |
Get all grades |
grade_category(id) |
Get grade category by ID |
grade_comment(id) |
Get grade comment by ID |
lesson(id) |
Get lesson info by ID |
subject(id) |
Get subject info by ID |
attendances() |
Get all attendances |
attendance_types() |
Get attendance types |
homeworks() |
Get all homeworks |
user(id) |
Get user by ID |
current_user() |
Get current user details |
Messages API
Base URL: https://wiadomosci.librus.pl/api/
| Method |
Description |
unread_counts() |
Get unread message counts for all folders |
inbox_messages(page, limit) |
List received messages |
outbox_messages(page, limit) |
List sent messages |
message(id) |
Get full message details |
attachment(attachment_id, message_id) |
Download attachment as bytes |
decode_message_content(base64) |
Decode base64 message content to string |
Error Handling
All methods return Result<T, librus_rs::Error>. Error variants:
pub enum Error {
Authentication, MissingEnvVar(&'static str), MissingCredentials(&'static str), HttpClient(reqwest::Error), Request(reqwest::Error), ApiError { status, body }, Parse { source, body }, }
Types
Key Exported Types
pub use librus_rs::{
Client, Error,
Grade, GradeCategory, GradeComment,
ResponseGrades, ResponseGradesCategories, ResponseGradesComments,
Lesson, LessonSubject, Attendance, AttendanceType,
ResponseLesson, ResponseLessonSubject, ResponseAttendances, ResponseAttendancesType,
Me, User, ResponseMe, ResponseUser,
Homework, ResponseHomeworks,
InboxMessage, OutboxMessage, MessageDetail, Attachment, UnreadCounts,
};
InboxMessage
pub struct InboxMessage {
pub message_id: String,
pub sender_first_name: String,
pub sender_last_name: String,
pub sender_name: String,
pub topic: String,
pub content: String, pub send_date: String,
pub read_date: Option<String>,
pub is_any_file_attached: bool,
pub tags: Vec<String>,
pub category: Option<String>,
}
MessageDetail
pub struct MessageDetail {
pub message_id: String,
pub sender_id: Option<String>,
pub sender_first_name: String,
pub sender_last_name: String,
pub sender_name: String,
pub sender_group: Option<String>,
pub topic: String,
pub message: String, pub send_date: String,
pub read_date: Option<String>,
pub attachments: Vec<Attachment>,
pub receivers_count: Option<u32>,
pub no_reply: Option<u8>,
pub archive: Option<u8>,
}
Development
For Nix users:
nix develop
cargo build
cargo test
License
MIT