Skip to main content

Client

Struct Client 

Source
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

Source

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:

§Example
use librus_rs::Client;

// Ensure LIBRUS_USERNAME and LIBRUS_PASSWORD are set
let client = Client::from_env().await?;
Examples found in repository?
examples/announcements.rs (line 6)
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(&notice.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
Hide additional examples
examples/test_api.rs (line 6)
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}
Source

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?;
Source

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?;
Source

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?
examples/test_api.rs (line 12)
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}
Source

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?
examples/test_api.rs (line 17)
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}
Source

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 a Grade’s category field
§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);
Source

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 a Grade’s comments field
§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);
}
Source

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);
Source

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);
}
Source

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?
examples/test_api.rs (line 27)
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}
Source

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);
}
Source

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?
examples/test_api.rs (line 22)
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}
Source

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?
examples/test_api.rs (line 32)
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}
Source

pub async fn school_notices_page( &self, page: u32, limit: u32, ) -> Result<ResponseSchoolNotices>

Gets school notices (announcements) with pagination.

§Arguments
  • page - Page number (1-indexed)
  • limit - Number of notices per page
§Errors

Returns an error if the request fails or response parsing fails.

Source

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?
examples/announcements.rs (line 9)
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(&notice.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}
Source

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);
}
Source

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.

Source

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?
examples/test_api.rs (line 37)
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}
Source

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?
examples/test_api.rs (line 43)
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}
Source

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);
}
Source

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
§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?
examples/test_api.rs (line 57)
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}
Source

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 a MessageDetail’s attachments
  • message_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");
}
Source

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?
examples/test_api.rs (line 46)
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}
Source

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&nbsp;<b>World</b> &amp; friends</p>";
let text = Client::notice_content_to_text(html);
assert_eq!(text, "Hello World & friends");
Examples found in repository?
examples/announcements.rs (line 12)
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(&notice.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}

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more