pub struct Client { /* private fields */ }Expand description
An authenticated Librus API client.
This is the main entry point for interacting with Librus Synergia. Create a client using one of the constructor methods, then call API methods to fetch data.
§Example
use librus_rs::Client;
#[tokio::main]
async fn main() -> Result<(), librus_rs::Error> {
let mut client = Client::from_env().await?;
// Fetch user info
let me = client.me().await?;
println!("Logged in as: {} {}", me.me.user.first_name, me.me.user.last_name);
// Fetch grades
let grades = client.grades().await?;
println!("Total grades: {}", grades.grades.len());
Ok(())
}Implementations§
Source§impl Client
impl Client
Sourcepub async fn from_env() -> Result<Self>
pub async fn from_env() -> Result<Self>
Creates a new client from environment variables.
Reads LIBRUS_USERNAME and LIBRUS_PASSWORD from the environment
and authenticates with Librus.
§Errors
Returns an error if:
LIBRUS_USERNAMEis not set (Error::MissingEnvVar)LIBRUS_PASSWORDis not set (Error::MissingEnvVar)- Authentication fails (
Error::Authentication)
§Example
use librus_rs::Client;
// Ensure LIBRUS_USERNAME and LIBRUS_PASSWORD are set
let client = Client::from_env().await?;Examples found in repository?
4async fn main() -> Result<(), librus_rs::Error> {
5 println!("Authenticating with Librus...");
6 let client = Client::from_env().await?;
7
8 println!("Fetching school notices...");
9 let notices = client.school_notices_latest(10).await?;
10
11 for notice in notices {
12 let content = Client::notice_content_to_text(¬ice.content);
13 let preview: String = content.chars().take(120).collect();
14 println!(
15 "[{}] {} - {}",
16 notice.creation_date, notice.subject, preview
17 );
18 }
19
20 Ok(())
21}More examples
4async fn main() -> Result<(), librus_rs::Error> {
5 println!("Authenticating with Librus...");
6 let mut client = Client::from_env().await?;
7
8 println!("Authentication successful!");
9
10 // Test Me endpoint
11 println!("\n--- Me ---");
12 let me = client.me().await?;
13 println!("User: {} {}", me.me.user.first_name, me.me.user.last_name);
14
15 // Test Grades
16 println!("\n--- Grades ---");
17 let grades = client.grades().await?;
18 println!("Total grades: {}", grades.grades.len());
19
20 // Test Homeworks
21 println!("\n--- Homeworks ---");
22 let homeworks = client.homeworks().await?;
23 println!("Total homeworks: {}", homeworks.homeworks.len());
24
25 // Test Attendances
26 println!("\n--- Attendances ---");
27 let attendances = client.attendances().await?;
28 println!("Total attendances: {}", attendances.attendances.len());
29
30 // Test School Notices (Announcements)
31 println!("\n--- School Notices ---");
32 let notices = client.school_notices().await?;
33 println!("Total notices: {}", notices.school_notices.len());
34
35 // Test Messages API
36 println!("\n--- Messages ---");
37 let unread = client.unread_counts().await?;
38 println!(
39 "Unread inbox: {}, notes: {}, alerts: {}",
40 unread.inbox, unread.notes, unread.alerts
41 );
42
43 let inbox = client.inbox_messages(1, 5).await?;
44 println!("Inbox messages (first 5):");
45 for msg in &inbox {
46 let content = Client::decode_message_content(&msg.content).unwrap_or_default();
47 let preview: String = content.chars().take(50).collect();
48 println!(
49 " [{}] {} - {} ({}...)",
50 msg.send_date, msg.sender_name, msg.topic, preview
51 );
52 }
53
54 // Get full message detail
55 if let Some(first_msg) = inbox.first() {
56 println!("\n--- Message Detail ---");
57 let detail = client.message(&first_msg.message_id).await?;
58 let content = Client::decode_message_content(&detail.message).unwrap_or_default();
59 println!("From: {}", detail.sender_name);
60 println!("Subject: {}", detail.topic);
61 println!("Content:\n{}", content);
62 if !detail.attachments.is_empty() {
63 println!("Attachments: {:?}", detail.attachments);
64 }
65 }
66
67 println!("\nAll API tests completed successfully!");
68 Ok(())
69}Sourcepub async fn new(username: &str, password: &str) -> Result<Self>
pub async fn new(username: &str, password: &str) -> Result<Self>
Creates a new client with explicit credentials.
§Errors
Returns an error if authentication fails (Error::Authentication)
or a network error occurs (Error::Request).
§Example
use librus_rs::Client;
let client = Client::new("username", "password").await?;Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Creates a builder for configuring the client.
§Example
use librus_rs::Client;
let client = Client::builder()
.username("username")
.password("password")
.build()
.await?;Sourcepub async fn me(&self) -> Result<ResponseMe>
pub async fn me(&self) -> Result<ResponseMe>
Gets current user information.
Returns account details, user profile, and class information.
§Errors
Returns an error if the request fails or response parsing fails.
§Example
use librus_rs::Client;
let client = Client::from_env().await?;
let me = client.me().await?;
println!("User: {} {}", me.me.user.first_name, me.me.user.last_name);
println!("Email: {}", me.me.account.email);Examples found in repository?
4async fn main() -> Result<(), librus_rs::Error> {
5 println!("Authenticating with Librus...");
6 let mut client = Client::from_env().await?;
7
8 println!("Authentication successful!");
9
10 // Test Me endpoint
11 println!("\n--- Me ---");
12 let me = client.me().await?;
13 println!("User: {} {}", me.me.user.first_name, me.me.user.last_name);
14
15 // Test Grades
16 println!("\n--- Grades ---");
17 let grades = client.grades().await?;
18 println!("Total grades: {}", grades.grades.len());
19
20 // Test Homeworks
21 println!("\n--- Homeworks ---");
22 let homeworks = client.homeworks().await?;
23 println!("Total homeworks: {}", homeworks.homeworks.len());
24
25 // Test Attendances
26 println!("\n--- Attendances ---");
27 let attendances = client.attendances().await?;
28 println!("Total attendances: {}", attendances.attendances.len());
29
30 // Test School Notices (Announcements)
31 println!("\n--- School Notices ---");
32 let notices = client.school_notices().await?;
33 println!("Total notices: {}", notices.school_notices.len());
34
35 // Test Messages API
36 println!("\n--- Messages ---");
37 let unread = client.unread_counts().await?;
38 println!(
39 "Unread inbox: {}, notes: {}, alerts: {}",
40 unread.inbox, unread.notes, unread.alerts
41 );
42
43 let inbox = client.inbox_messages(1, 5).await?;
44 println!("Inbox messages (first 5):");
45 for msg in &inbox {
46 let content = Client::decode_message_content(&msg.content).unwrap_or_default();
47 let preview: String = content.chars().take(50).collect();
48 println!(
49 " [{}] {} - {} ({}...)",
50 msg.send_date, msg.sender_name, msg.topic, preview
51 );
52 }
53
54 // Get full message detail
55 if let Some(first_msg) = inbox.first() {
56 println!("\n--- Message Detail ---");
57 let detail = client.message(&first_msg.message_id).await?;
58 let content = Client::decode_message_content(&detail.message).unwrap_or_default();
59 println!("From: {}", detail.sender_name);
60 println!("Subject: {}", detail.topic);
61 println!("Content:\n{}", content);
62 if !detail.attachments.is_empty() {
63 println!("Attachments: {:?}", detail.attachments);
64 }
65 }
66
67 println!("\nAll API tests completed successfully!");
68 Ok(())
69}Sourcepub async fn grades(&self) -> Result<ResponseGrades>
pub async fn grades(&self) -> Result<ResponseGrades>
Gets all grades for the student.
Returns a list of all grades across all subjects.
§Errors
Returns an error if the request fails or response parsing fails.
§Example
use librus_rs::Client;
let client = Client::from_env().await?;
let grades = client.grades().await?;
for grade in grades.grades {
println!("{}: {} ({})", grade.date, grade.grade, grade.semester);
}Examples found in repository?
4async fn main() -> Result<(), librus_rs::Error> {
5 println!("Authenticating with Librus...");
6 let mut client = Client::from_env().await?;
7
8 println!("Authentication successful!");
9
10 // Test Me endpoint
11 println!("\n--- Me ---");
12 let me = client.me().await?;
13 println!("User: {} {}", me.me.user.first_name, me.me.user.last_name);
14
15 // Test Grades
16 println!("\n--- Grades ---");
17 let grades = client.grades().await?;
18 println!("Total grades: {}", grades.grades.len());
19
20 // Test Homeworks
21 println!("\n--- Homeworks ---");
22 let homeworks = client.homeworks().await?;
23 println!("Total homeworks: {}", homeworks.homeworks.len());
24
25 // Test Attendances
26 println!("\n--- Attendances ---");
27 let attendances = client.attendances().await?;
28 println!("Total attendances: {}", attendances.attendances.len());
29
30 // Test School Notices (Announcements)
31 println!("\n--- School Notices ---");
32 let notices = client.school_notices().await?;
33 println!("Total notices: {}", notices.school_notices.len());
34
35 // Test Messages API
36 println!("\n--- Messages ---");
37 let unread = client.unread_counts().await?;
38 println!(
39 "Unread inbox: {}, notes: {}, alerts: {}",
40 unread.inbox, unread.notes, unread.alerts
41 );
42
43 let inbox = client.inbox_messages(1, 5).await?;
44 println!("Inbox messages (first 5):");
45 for msg in &inbox {
46 let content = Client::decode_message_content(&msg.content).unwrap_or_default();
47 let preview: String = content.chars().take(50).collect();
48 println!(
49 " [{}] {} - {} ({}...)",
50 msg.send_date, msg.sender_name, msg.topic, preview
51 );
52 }
53
54 // Get full message detail
55 if let Some(first_msg) = inbox.first() {
56 println!("\n--- Message Detail ---");
57 let detail = client.message(&first_msg.message_id).await?;
58 let content = Client::decode_message_content(&detail.message).unwrap_or_default();
59 println!("From: {}", detail.sender_name);
60 println!("Subject: {}", detail.topic);
61 println!("Content:\n{}", content);
62 if !detail.attachments.is_empty() {
63 println!("Attachments: {:?}", detail.attachments);
64 }
65 }
66
67 println!("\nAll API tests completed successfully!");
68 Ok(())
69}Sourcepub async fn grade_category(&self, id: i32) -> Result<ResponseGradesCategories>
pub async fn grade_category(&self, id: i32) -> Result<ResponseGradesCategories>
Gets a grade category by ID.
Categories describe the type of grade (e.g., test, homework, quiz).
§Arguments
id- The category ID from aGrade’scategoryfield
§Errors
Returns an error if the request fails or the category is not found.
§Example
use librus_rs::Client;
let client = Client::from_env().await?;
let category = client.grade_category(123).await?;
println!("Category: {}", category.category.name);Sourcepub async fn grade_comment(&self, id: i32) -> Result<ResponseGradesComments>
pub async fn grade_comment(&self, id: i32) -> Result<ResponseGradesComments>
Gets a grade comment by ID.
Comments provide additional context for a grade.
§Arguments
id- The comment ID from aGrade’scommentsfield
§Errors
Returns an error if the request fails or the comment is not found.
§Example
use librus_rs::Client;
let client = Client::from_env().await?;
let comment = client.grade_comment(456).await?;
if let Some(c) = comment.comment {
println!("Comment: {}", c.text);
}Sourcepub async fn lesson(&self, id: i32) -> Result<ResponseLesson>
pub async fn lesson(&self, id: i32) -> Result<ResponseLesson>
Gets a lesson by ID.
Lessons contain information about which teacher teaches which subject to which class.
§Arguments
id- The lesson ID
§Errors
Returns an error if the request fails or the lesson is not found.
§Example
use librus_rs::Client;
let client = Client::from_env().await?;
let lesson = client.lesson(789).await?;
println!("Lesson ID: {}", lesson.lesson.id);Sourcepub async fn subject(&self, id: i32) -> Result<ResponseLessonSubject>
pub async fn subject(&self, id: i32) -> Result<ResponseLessonSubject>
Gets a subject by ID.
Subjects contain the name and short code for academic subjects.
§Arguments
id- The subject ID
§Errors
Returns an error if the request fails or the subject is not found.
§Example
use librus_rs::Client;
let client = Client::from_env().await?;
let subject = client.subject(101).await?;
if let Some(s) = subject.subject {
println!("Subject: {} ({})", s.name, s.short);
}Sourcepub async fn attendances(&self) -> Result<ResponseAttendances>
pub async fn attendances(&self) -> Result<ResponseAttendances>
Gets all attendances for the student.
Returns attendance records for all lessons.
§Errors
Returns an error if the request fails or response parsing fails.
§Example
use librus_rs::Client;
let client = Client::from_env().await?;
let attendances = client.attendances().await?;
println!("Total records: {}", attendances.attendances.len());Examples found in repository?
4async fn main() -> Result<(), librus_rs::Error> {
5 println!("Authenticating with Librus...");
6 let mut client = Client::from_env().await?;
7
8 println!("Authentication successful!");
9
10 // Test Me endpoint
11 println!("\n--- Me ---");
12 let me = client.me().await?;
13 println!("User: {} {}", me.me.user.first_name, me.me.user.last_name);
14
15 // Test Grades
16 println!("\n--- Grades ---");
17 let grades = client.grades().await?;
18 println!("Total grades: {}", grades.grades.len());
19
20 // Test Homeworks
21 println!("\n--- Homeworks ---");
22 let homeworks = client.homeworks().await?;
23 println!("Total homeworks: {}", homeworks.homeworks.len());
24
25 // Test Attendances
26 println!("\n--- Attendances ---");
27 let attendances = client.attendances().await?;
28 println!("Total attendances: {}", attendances.attendances.len());
29
30 // Test School Notices (Announcements)
31 println!("\n--- School Notices ---");
32 let notices = client.school_notices().await?;
33 println!("Total notices: {}", notices.school_notices.len());
34
35 // Test Messages API
36 println!("\n--- Messages ---");
37 let unread = client.unread_counts().await?;
38 println!(
39 "Unread inbox: {}, notes: {}, alerts: {}",
40 unread.inbox, unread.notes, unread.alerts
41 );
42
43 let inbox = client.inbox_messages(1, 5).await?;
44 println!("Inbox messages (first 5):");
45 for msg in &inbox {
46 let content = Client::decode_message_content(&msg.content).unwrap_or_default();
47 let preview: String = content.chars().take(50).collect();
48 println!(
49 " [{}] {} - {} ({}...)",
50 msg.send_date, msg.sender_name, msg.topic, preview
51 );
52 }
53
54 // Get full message detail
55 if let Some(first_msg) = inbox.first() {
56 println!("\n--- Message Detail ---");
57 let detail = client.message(&first_msg.message_id).await?;
58 let content = Client::decode_message_content(&detail.message).unwrap_or_default();
59 println!("From: {}", detail.sender_name);
60 println!("Subject: {}", detail.topic);
61 println!("Content:\n{}", content);
62 if !detail.attachments.is_empty() {
63 println!("Attachments: {:?}", detail.attachments);
64 }
65 }
66
67 println!("\nAll API tests completed successfully!");
68 Ok(())
69}Sourcepub async fn attendance_types(&self) -> Result<ResponseAttendancesType>
pub async fn attendance_types(&self) -> Result<ResponseAttendancesType>
Gets all attendance types.
Types describe the kind of attendance (present, absent, late, etc.).
§Errors
Returns an error if the request fails or response parsing fails.
§Example
use librus_rs::Client;
let client = Client::from_env().await?;
let types = client.attendance_types().await?;
for t in types.types {
println!("{}: {} ({})", t.id, t.name, t.short);
}Sourcepub async fn homeworks(&self) -> Result<ResponseHomeworks>
pub async fn homeworks(&self) -> Result<ResponseHomeworks>
Gets all homeworks.
Returns a list of all homework assignments.
§Errors
Returns an error if the request fails or response parsing fails.
§Example
use librus_rs::Client;
let client = Client::from_env().await?;
let homeworks = client.homeworks().await?;
for hw in homeworks.homeworks {
println!("{}: {}", hw.date, hw.content);
}Examples found in repository?
4async fn main() -> Result<(), librus_rs::Error> {
5 println!("Authenticating with Librus...");
6 let mut client = Client::from_env().await?;
7
8 println!("Authentication successful!");
9
10 // Test Me endpoint
11 println!("\n--- Me ---");
12 let me = client.me().await?;
13 println!("User: {} {}", me.me.user.first_name, me.me.user.last_name);
14
15 // Test Grades
16 println!("\n--- Grades ---");
17 let grades = client.grades().await?;
18 println!("Total grades: {}", grades.grades.len());
19
20 // Test Homeworks
21 println!("\n--- Homeworks ---");
22 let homeworks = client.homeworks().await?;
23 println!("Total homeworks: {}", homeworks.homeworks.len());
24
25 // Test Attendances
26 println!("\n--- Attendances ---");
27 let attendances = client.attendances().await?;
28 println!("Total attendances: {}", attendances.attendances.len());
29
30 // Test School Notices (Announcements)
31 println!("\n--- School Notices ---");
32 let notices = client.school_notices().await?;
33 println!("Total notices: {}", notices.school_notices.len());
34
35 // Test Messages API
36 println!("\n--- Messages ---");
37 let unread = client.unread_counts().await?;
38 println!(
39 "Unread inbox: {}, notes: {}, alerts: {}",
40 unread.inbox, unread.notes, unread.alerts
41 );
42
43 let inbox = client.inbox_messages(1, 5).await?;
44 println!("Inbox messages (first 5):");
45 for msg in &inbox {
46 let content = Client::decode_message_content(&msg.content).unwrap_or_default();
47 let preview: String = content.chars().take(50).collect();
48 println!(
49 " [{}] {} - {} ({}...)",
50 msg.send_date, msg.sender_name, msg.topic, preview
51 );
52 }
53
54 // Get full message detail
55 if let Some(first_msg) = inbox.first() {
56 println!("\n--- Message Detail ---");
57 let detail = client.message(&first_msg.message_id).await?;
58 let content = Client::decode_message_content(&detail.message).unwrap_or_default();
59 println!("From: {}", detail.sender_name);
60 println!("Subject: {}", detail.topic);
61 println!("Content:\n{}", content);
62 if !detail.attachments.is_empty() {
63 println!("Attachments: {:?}", detail.attachments);
64 }
65 }
66
67 println!("\nAll API tests completed successfully!");
68 Ok(())
69}Sourcepub async fn school_notices(&self) -> Result<ResponseSchoolNotices>
pub async fn school_notices(&self) -> Result<ResponseSchoolNotices>
Gets school notices (announcements).
Returns a list of school notices.
§Errors
Returns an error if the request fails or response parsing fails.
§Example
use librus_rs::Client;
let client = Client::from_env().await?;
let notices = client.school_notices().await?;
for notice in notices.school_notices {
println!("{}: {}", notice.creation_date, notice.subject);
}Examples found in repository?
4async fn main() -> Result<(), librus_rs::Error> {
5 println!("Authenticating with Librus...");
6 let mut client = Client::from_env().await?;
7
8 println!("Authentication successful!");
9
10 // Test Me endpoint
11 println!("\n--- Me ---");
12 let me = client.me().await?;
13 println!("User: {} {}", me.me.user.first_name, me.me.user.last_name);
14
15 // Test Grades
16 println!("\n--- Grades ---");
17 let grades = client.grades().await?;
18 println!("Total grades: {}", grades.grades.len());
19
20 // Test Homeworks
21 println!("\n--- Homeworks ---");
22 let homeworks = client.homeworks().await?;
23 println!("Total homeworks: {}", homeworks.homeworks.len());
24
25 // Test Attendances
26 println!("\n--- Attendances ---");
27 let attendances = client.attendances().await?;
28 println!("Total attendances: {}", attendances.attendances.len());
29
30 // Test School Notices (Announcements)
31 println!("\n--- School Notices ---");
32 let notices = client.school_notices().await?;
33 println!("Total notices: {}", notices.school_notices.len());
34
35 // Test Messages API
36 println!("\n--- Messages ---");
37 let unread = client.unread_counts().await?;
38 println!(
39 "Unread inbox: {}, notes: {}, alerts: {}",
40 unread.inbox, unread.notes, unread.alerts
41 );
42
43 let inbox = client.inbox_messages(1, 5).await?;
44 println!("Inbox messages (first 5):");
45 for msg in &inbox {
46 let content = Client::decode_message_content(&msg.content).unwrap_or_default();
47 let preview: String = content.chars().take(50).collect();
48 println!(
49 " [{}] {} - {} ({}...)",
50 msg.send_date, msg.sender_name, msg.topic, preview
51 );
52 }
53
54 // Get full message detail
55 if let Some(first_msg) = inbox.first() {
56 println!("\n--- Message Detail ---");
57 let detail = client.message(&first_msg.message_id).await?;
58 let content = Client::decode_message_content(&detail.message).unwrap_or_default();
59 println!("From: {}", detail.sender_name);
60 println!("Subject: {}", detail.topic);
61 println!("Content:\n{}", content);
62 if !detail.attachments.is_empty() {
63 println!("Attachments: {:?}", detail.attachments);
64 }
65 }
66
67 println!("\nAll API tests completed successfully!");
68 Ok(())
69}Sourcepub async fn school_notices_page(
&self,
page: u32,
limit: u32,
) -> Result<ResponseSchoolNotices>
pub async fn school_notices_page( &self, page: u32, limit: u32, ) -> Result<ResponseSchoolNotices>
Sourcepub async fn school_notices_latest(
&self,
limit: usize,
) -> Result<Vec<SchoolNotice>>
pub async fn school_notices_latest( &self, limit: usize, ) -> Result<Vec<SchoolNotice>>
Gets the latest school notices (announcements).
This paginates through all notices, sorts them by creation_date (descending),
and returns the newest limit items.
§Errors
Returns an error if the request fails or response parsing fails.
Examples found in repository?
4async fn main() -> Result<(), librus_rs::Error> {
5 println!("Authenticating with Librus...");
6 let client = Client::from_env().await?;
7
8 println!("Fetching school notices...");
9 let notices = client.school_notices_latest(10).await?;
10
11 for notice in notices {
12 let content = Client::notice_content_to_text(¬ice.content);
13 let preview: String = content.chars().take(120).collect();
14 println!(
15 "[{}] {} - {}",
16 notice.creation_date, notice.subject, preview
17 );
18 }
19
20 Ok(())
21}Sourcepub async fn user(&self, id: i32) -> Result<ResponseUser>
pub async fn user(&self, id: i32) -> Result<ResponseUser>
Gets a user by ID.
Users include teachers, students, and parents.
§Arguments
id- The user ID
§Errors
Returns an error if the request fails or the user is not found.
§Example
use librus_rs::Client;
let client = Client::from_env().await?;
let user = client.user(12345).await?;
if let Some(u) = user.user {
println!("{} {}", u.first_name, u.last_name);
}Sourcepub async fn current_user(&self) -> Result<ResponseUser>
pub async fn current_user(&self) -> Result<ResponseUser>
Gets current user details.
Returns detailed information about the authenticated user.
§Errors
Returns an error if the request fails or response parsing fails.
Sourcepub async fn unread_counts(&mut self) -> Result<UnreadCounts>
pub async fn unread_counts(&mut self) -> Result<UnreadCounts>
Gets unread message counts for all folders.
Returns counts for inbox, notes, alerts, and other message categories.
§Errors
Returns an error if the request fails or response parsing fails.
§Example
use librus_rs::Client;
let mut client = Client::from_env().await?;
let counts = client.unread_counts().await?;
println!("Unread inbox: {}", counts.inbox);
println!("Unread alerts: {}", counts.alerts);Examples found in repository?
4async fn main() -> Result<(), librus_rs::Error> {
5 println!("Authenticating with Librus...");
6 let mut client = Client::from_env().await?;
7
8 println!("Authentication successful!");
9
10 // Test Me endpoint
11 println!("\n--- Me ---");
12 let me = client.me().await?;
13 println!("User: {} {}", me.me.user.first_name, me.me.user.last_name);
14
15 // Test Grades
16 println!("\n--- Grades ---");
17 let grades = client.grades().await?;
18 println!("Total grades: {}", grades.grades.len());
19
20 // Test Homeworks
21 println!("\n--- Homeworks ---");
22 let homeworks = client.homeworks().await?;
23 println!("Total homeworks: {}", homeworks.homeworks.len());
24
25 // Test Attendances
26 println!("\n--- Attendances ---");
27 let attendances = client.attendances().await?;
28 println!("Total attendances: {}", attendances.attendances.len());
29
30 // Test School Notices (Announcements)
31 println!("\n--- School Notices ---");
32 let notices = client.school_notices().await?;
33 println!("Total notices: {}", notices.school_notices.len());
34
35 // Test Messages API
36 println!("\n--- Messages ---");
37 let unread = client.unread_counts().await?;
38 println!(
39 "Unread inbox: {}, notes: {}, alerts: {}",
40 unread.inbox, unread.notes, unread.alerts
41 );
42
43 let inbox = client.inbox_messages(1, 5).await?;
44 println!("Inbox messages (first 5):");
45 for msg in &inbox {
46 let content = Client::decode_message_content(&msg.content).unwrap_or_default();
47 let preview: String = content.chars().take(50).collect();
48 println!(
49 " [{}] {} - {} ({}...)",
50 msg.send_date, msg.sender_name, msg.topic, preview
51 );
52 }
53
54 // Get full message detail
55 if let Some(first_msg) = inbox.first() {
56 println!("\n--- Message Detail ---");
57 let detail = client.message(&first_msg.message_id).await?;
58 let content = Client::decode_message_content(&detail.message).unwrap_or_default();
59 println!("From: {}", detail.sender_name);
60 println!("Subject: {}", detail.topic);
61 println!("Content:\n{}", content);
62 if !detail.attachments.is_empty() {
63 println!("Attachments: {:?}", detail.attachments);
64 }
65 }
66
67 println!("\nAll API tests completed successfully!");
68 Ok(())
69}Sourcepub async fn inbox_messages(
&mut self,
page: u32,
limit: u32,
) -> Result<Vec<InboxMessage>>
pub async fn inbox_messages( &mut self, page: u32, limit: u32, ) -> Result<Vec<InboxMessage>>
Gets inbox messages (received).
§Arguments
page- Page number (1-indexed)limit- Number of messages per page
§Errors
Returns an error if the request fails or response parsing fails.
§Example
use librus_rs::Client;
let mut client = Client::from_env().await?;
let messages = client.inbox_messages(1, 10).await?;
for msg in messages {
println!("{}: {}", msg.sender_name, msg.topic);
}Examples found in repository?
4async fn main() -> Result<(), librus_rs::Error> {
5 println!("Authenticating with Librus...");
6 let mut client = Client::from_env().await?;
7
8 println!("Authentication successful!");
9
10 // Test Me endpoint
11 println!("\n--- Me ---");
12 let me = client.me().await?;
13 println!("User: {} {}", me.me.user.first_name, me.me.user.last_name);
14
15 // Test Grades
16 println!("\n--- Grades ---");
17 let grades = client.grades().await?;
18 println!("Total grades: {}", grades.grades.len());
19
20 // Test Homeworks
21 println!("\n--- Homeworks ---");
22 let homeworks = client.homeworks().await?;
23 println!("Total homeworks: {}", homeworks.homeworks.len());
24
25 // Test Attendances
26 println!("\n--- Attendances ---");
27 let attendances = client.attendances().await?;
28 println!("Total attendances: {}", attendances.attendances.len());
29
30 // Test School Notices (Announcements)
31 println!("\n--- School Notices ---");
32 let notices = client.school_notices().await?;
33 println!("Total notices: {}", notices.school_notices.len());
34
35 // Test Messages API
36 println!("\n--- Messages ---");
37 let unread = client.unread_counts().await?;
38 println!(
39 "Unread inbox: {}, notes: {}, alerts: {}",
40 unread.inbox, unread.notes, unread.alerts
41 );
42
43 let inbox = client.inbox_messages(1, 5).await?;
44 println!("Inbox messages (first 5):");
45 for msg in &inbox {
46 let content = Client::decode_message_content(&msg.content).unwrap_or_default();
47 let preview: String = content.chars().take(50).collect();
48 println!(
49 " [{}] {} - {} ({}...)",
50 msg.send_date, msg.sender_name, msg.topic, preview
51 );
52 }
53
54 // Get full message detail
55 if let Some(first_msg) = inbox.first() {
56 println!("\n--- Message Detail ---");
57 let detail = client.message(&first_msg.message_id).await?;
58 let content = Client::decode_message_content(&detail.message).unwrap_or_default();
59 println!("From: {}", detail.sender_name);
60 println!("Subject: {}", detail.topic);
61 println!("Content:\n{}", content);
62 if !detail.attachments.is_empty() {
63 println!("Attachments: {:?}", detail.attachments);
64 }
65 }
66
67 println!("\nAll API tests completed successfully!");
68 Ok(())
69}Sourcepub async fn outbox_messages(
&mut self,
page: u32,
limit: u32,
) -> Result<Vec<OutboxMessage>>
pub async fn outbox_messages( &mut self, page: u32, limit: u32, ) -> Result<Vec<OutboxMessage>>
Gets outbox messages (sent).
§Arguments
page- Page number (1-indexed)limit- Number of messages per page
§Errors
Returns an error if the request fails or response parsing fails.
§Example
use librus_rs::Client;
let mut client = Client::from_env().await?;
let messages = client.outbox_messages(1, 10).await?;
for msg in messages {
println!("To {}: {}", msg.receiver_name, msg.topic);
}Sourcepub async fn message(&mut self, message_id: &str) -> Result<MessageDetail>
pub async fn message(&mut self, message_id: &str) -> Result<MessageDetail>
Gets full message details by ID.
Returns the complete message including body content and attachments.
§Arguments
message_id- The message ID from anInboxMessageorOutboxMessage
§Errors
Returns an error if the request fails or the message is not found.
§Example
use librus_rs::Client;
let mut client = Client::from_env().await?;
let detail = client.message("12345").await?;
if let Some(content) = Client::decode_message_content(&detail.message) {
println!("Content: {}", content);
}Examples found in repository?
4async fn main() -> Result<(), librus_rs::Error> {
5 println!("Authenticating with Librus...");
6 let mut client = Client::from_env().await?;
7
8 println!("Authentication successful!");
9
10 // Test Me endpoint
11 println!("\n--- Me ---");
12 let me = client.me().await?;
13 println!("User: {} {}", me.me.user.first_name, me.me.user.last_name);
14
15 // Test Grades
16 println!("\n--- Grades ---");
17 let grades = client.grades().await?;
18 println!("Total grades: {}", grades.grades.len());
19
20 // Test Homeworks
21 println!("\n--- Homeworks ---");
22 let homeworks = client.homeworks().await?;
23 println!("Total homeworks: {}", homeworks.homeworks.len());
24
25 // Test Attendances
26 println!("\n--- Attendances ---");
27 let attendances = client.attendances().await?;
28 println!("Total attendances: {}", attendances.attendances.len());
29
30 // Test School Notices (Announcements)
31 println!("\n--- School Notices ---");
32 let notices = client.school_notices().await?;
33 println!("Total notices: {}", notices.school_notices.len());
34
35 // Test Messages API
36 println!("\n--- Messages ---");
37 let unread = client.unread_counts().await?;
38 println!(
39 "Unread inbox: {}, notes: {}, alerts: {}",
40 unread.inbox, unread.notes, unread.alerts
41 );
42
43 let inbox = client.inbox_messages(1, 5).await?;
44 println!("Inbox messages (first 5):");
45 for msg in &inbox {
46 let content = Client::decode_message_content(&msg.content).unwrap_or_default();
47 let preview: String = content.chars().take(50).collect();
48 println!(
49 " [{}] {} - {} ({}...)",
50 msg.send_date, msg.sender_name, msg.topic, preview
51 );
52 }
53
54 // Get full message detail
55 if let Some(first_msg) = inbox.first() {
56 println!("\n--- Message Detail ---");
57 let detail = client.message(&first_msg.message_id).await?;
58 let content = Client::decode_message_content(&detail.message).unwrap_or_default();
59 println!("From: {}", detail.sender_name);
60 println!("Subject: {}", detail.topic);
61 println!("Content:\n{}", content);
62 if !detail.attachments.is_empty() {
63 println!("Attachments: {:?}", detail.attachments);
64 }
65 }
66
67 println!("\nAll API tests completed successfully!");
68 Ok(())
69}Sourcepub async fn attachment(
&mut self,
attachment_id: &str,
message_id: &str,
) -> Result<Vec<u8>>
pub async fn attachment( &mut self, attachment_id: &str, message_id: &str, ) -> Result<Vec<u8>>
Downloads attachment bytes.
§Arguments
attachment_id- The attachment ID from aMessageDetail’s attachmentsmessage_id- The message ID containing the attachment
§Errors
Returns an error if the request fails or the attachment is not found.
§Example
use librus_rs::Client;
use std::fs;
let mut client = Client::from_env().await?;
let detail = client.message("12345").await?;
for attachment in &detail.attachments {
let bytes = client.attachment(&attachment.id, &detail.message_id).await?;
fs::write(&attachment.name, &bytes).expect("Failed to save file");
}Sourcepub fn decode_message_content(content: &str) -> Option<String>
pub fn decode_message_content(content: &str) -> Option<String>
Decodes base64-encoded message content to a string.
Message bodies in Librus are base64-encoded. Use this helper to decode them.
§Arguments
content- The base64-encoded content string
§Returns
Some(String) if decoding succeeds, None if the content is invalid.
§Example
use librus_rs::Client;
let encoded = "SGVsbG8sIFdvcmxkIQ==";
let decoded = Client::decode_message_content(encoded);
assert_eq!(decoded, Some("Hello, World!".to_string()));Examples found in repository?
4async fn main() -> Result<(), librus_rs::Error> {
5 println!("Authenticating with Librus...");
6 let mut client = Client::from_env().await?;
7
8 println!("Authentication successful!");
9
10 // Test Me endpoint
11 println!("\n--- Me ---");
12 let me = client.me().await?;
13 println!("User: {} {}", me.me.user.first_name, me.me.user.last_name);
14
15 // Test Grades
16 println!("\n--- Grades ---");
17 let grades = client.grades().await?;
18 println!("Total grades: {}", grades.grades.len());
19
20 // Test Homeworks
21 println!("\n--- Homeworks ---");
22 let homeworks = client.homeworks().await?;
23 println!("Total homeworks: {}", homeworks.homeworks.len());
24
25 // Test Attendances
26 println!("\n--- Attendances ---");
27 let attendances = client.attendances().await?;
28 println!("Total attendances: {}", attendances.attendances.len());
29
30 // Test School Notices (Announcements)
31 println!("\n--- School Notices ---");
32 let notices = client.school_notices().await?;
33 println!("Total notices: {}", notices.school_notices.len());
34
35 // Test Messages API
36 println!("\n--- Messages ---");
37 let unread = client.unread_counts().await?;
38 println!(
39 "Unread inbox: {}, notes: {}, alerts: {}",
40 unread.inbox, unread.notes, unread.alerts
41 );
42
43 let inbox = client.inbox_messages(1, 5).await?;
44 println!("Inbox messages (first 5):");
45 for msg in &inbox {
46 let content = Client::decode_message_content(&msg.content).unwrap_or_default();
47 let preview: String = content.chars().take(50).collect();
48 println!(
49 " [{}] {} - {} ({}...)",
50 msg.send_date, msg.sender_name, msg.topic, preview
51 );
52 }
53
54 // Get full message detail
55 if let Some(first_msg) = inbox.first() {
56 println!("\n--- Message Detail ---");
57 let detail = client.message(&first_msg.message_id).await?;
58 let content = Client::decode_message_content(&detail.message).unwrap_or_default();
59 println!("From: {}", detail.sender_name);
60 println!("Subject: {}", detail.topic);
61 println!("Content:\n{}", content);
62 if !detail.attachments.is_empty() {
63 println!("Attachments: {:?}", detail.attachments);
64 }
65 }
66
67 println!("\nAll API tests completed successfully!");
68 Ok(())
69}Sourcepub fn notice_content_to_text(content: &str) -> String
pub fn notice_content_to_text(content: &str) -> String
Formats API-provided HTML content into readable text.
School notices (announcements) are often HTML-formatted. This helper removes tags and performs a minimal entity decode to make the content readable.
§Example
use librus_rs::Client;
let html = "<p>Hello <b>World</b> & friends</p>";
let text = Client::notice_content_to_text(html);
assert_eq!(text, "Hello World & friends");Examples found in repository?
4async fn main() -> Result<(), librus_rs::Error> {
5 println!("Authenticating with Librus...");
6 let client = Client::from_env().await?;
7
8 println!("Fetching school notices...");
9 let notices = client.school_notices_latest(10).await?;
10
11 for notice in notices {
12 let content = Client::notice_content_to_text(¬ice.content);
13 let preview: String = content.chars().take(120).collect();
14 println!(
15 "[{}] {} - {}",
16 notice.creation_date, notice.subject, preview
17 );
18 }
19
20 Ok(())
21}