Skip to content

Commit

Permalink
docs(examples): add instance-information for rust
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Jul 21, 2024
1 parent 38ca9c0 commit 0b3d0ae
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Pawnote - Examples

This directory contains examples of how to use the Pawnote API.

| Name | Description | Implementations |
|------|-------------|----|------|
| `instance-information` | Get information about a PRONOTE instance using `get_instance_information`. | [JS/TS](./javascript/instance-information.ts), [Rust](./rust/instance-information/src/main.rs) |
| `authenticate` | Authenticate to a PRONOTE instance using `authenticate_with_credentials`. | [JS/TS](./javascript/authenticate.ts), [Rust](./rust/authenticate/src/main.rs) |
4 changes: 2 additions & 2 deletions examples/rust/authenticate/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ async fn main() {
let password = String::from("pronotevs");
let device_uuid = Uuid::new_v4();

let pronote_session = authenticate_with_credentials(
let session = authenticate_with_credentials(
pronote_url,
WebSpace::Students,
username,
password,
device_uuid.to_string()
).await.unwrap();

println!("{}", serde_json::to_string_pretty(&pronote_session).unwrap());
println!("{}", serde_json::to_string_pretty(&session).unwrap());

// We do a lil' memory usage check at the end.
let peak_mem = PEAK_ALLOC.peak_usage_as_kb();
Expand Down
10 changes: 10 additions & 0 deletions examples/rust/instance-information/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "instance-information"
version = "0.0.0"
edition = "2021"

[dependencies]
pawnote = { path = "../../../pawnote" }
tokio = { version = "1", features = ["full"] }
serde_json = "1.0"
peak_alloc = "0.2.1"
18 changes: 18 additions & 0 deletions examples/rust/instance-information/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use peak_alloc::PeakAlloc;
use pawnote::services::get_instance_information;

#[global_allocator]
static PEAK_ALLOC: PeakAlloc = PeakAlloc;

#[tokio::main]
async fn main() {
let pronote_url = String::from("https://demo.index-education.net/pronote");
let instance_information = get_instance_information(pronote_url).await;

println!("{}", serde_json::to_string_pretty(&instance_information).unwrap());

// We do a lil' memory usage check at the end.
let peak_mem = PEAK_ALLOC.peak_usage_as_kb();
let current_mem = PEAK_ALLOC.current_usage_as_kb();
println!("This program currently uses {} KB of RAM, max was {} KB.", current_mem, peak_mem);
}

0 comments on commit 0b3d0ae

Please sign in to comment.