5 个稳定版本
1.0.4 | 2023 年 1 月 22 日 |
---|---|
1.0.3 | 2023 年 1 月 17 日 |
1.0.2 | 2023 年 1 月 16 日 |
#2290 在 网页编程
15KB
191 行
BetterSchool SDK
这是官方的 Rust BetterSchool SDK。它是一个用于与 BetterSchool API 交互的完全类型化的包装器
安装
[dependecies]
betterschool-sdk = "1.0.4"
或
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)
在这种情况下,API 的响应将如下所示
AddUserResponse { code: 401, response: "incorrect credentials" }
由于凭证不是有效的 Feide 凭证,API 返回 401 - 未授权
依赖项
~4–19MB
~247K SLoC