Crates.io | betterschool-sdk |
lib.rs | betterschool-sdk |
version | 1.0.4 |
source | src |
created_at | 2023-01-16 16:20:22.38419 |
updated_at | 2023-01-22 15:07:13.535198 |
description | The official BetterSchool rust sdk |
homepage | https://chph.tk/projects/BetterSchool-SDK-rust |
repository | https://github.com/CheesyPhoenix/betterschool-sdk |
max_upload_size | |
id | 760316 |
size | 15,795 |
This is the official rust BetterSchool SDK. It is a fully typed wrapper for interacting with the BetterSchool API
[dependecies]
betterschool-sdk = "1.0.4"
or
cargo add betterschool-sdk
// import the BetterSchool struct
use betterschool_sdk::BetterSchool;
// start by creating an instance of BetterSchool with the url to your api,
// eg. the official "https://api.betterschool.chph.tk"
let better_school = BetterSchool::new("https://api.betterschool.chph.tk");
// then get the list of schools for that API
let schools = better_school.get_schools().expect("could not get schools");
// then select the school you are interested in, get the schoolID
// and use it to get the classes for that school
let classes = better_school
.get_classes(&schools[0].schoolID)
.expect("Could not get classes");
// then select the class you are interested in, get the classID
// and use it to get the schedule for that class
// (This will return a vector with each element representing a single week)
let schedule = better_school
.get_schedule(&schools[0].schoolID, &classes[0].classID)
.expect("Could not get schedule");
// then select the week you are interested in, and use it however you like
let week = &schedule[0];
let week_nr = &week.weekNr;
// import the BetterSchool struct
use betterschool_sdk::BetterSchool;
// start by creating an instance of BetterSchool with the url to your api,
// eg. the official "https://api.betterschool.chph.tk"
let better_school = BetterSchool::new("https://api.betterschool.chph.tk");
// Add a user with the name: "Bob Kåre", password: "Kålmann" and classname: "245A", on the first school returned by get_schools
let res = better_school
.add_user(
"Bob Kåre",
"Kålmann",
"245A",
&better_school.get_schools().expect("Could not get schools")[0].schoolID,
)
.expect("Could not add user");
// print out the response from the API
println!("{:?}", res)
In this case the response from the API would look like this:
AddUserResponse { code: 401, response: "incorrect credentials" }
Since the credentials aren't valid Feide credentials the API returns a 401 - Unauthorized