This commit is contained in:
Dominic Grimm 2023-01-27 18:05:00 +01:00
parent 21009ada78
commit 51c09d0e5a
No known key found for this signature in database
GPG Key ID: 6F294212DEAAC530
1 changed files with 10 additions and 7 deletions

View File

@ -285,7 +285,7 @@ struct ApiTeachersResponse {
#[derive(Debug)]
pub struct Client {
pub api_url: url::Url,
pub webuntis_url: url::Url,
pub rpc_url: url::Url,
pub client_name: String,
pub user_agent: String,
@ -296,10 +296,11 @@ pub struct Client {
}
impl Client {
pub fn gen_rpc_url(mut endpoint: url::Url, school: &str) -> url::Url {
endpoint.query_pairs_mut().append_pair("school", school);
pub fn gen_rpc_url(endpoint: url::Url, school: &str) -> Result<url::Url> {
let mut x = endpoint.join("jsonrpc.do")?;
x.query_pairs_mut().append_pair("school", school);
endpoint
Ok(x)
}
pub async fn login_rpc(&mut self) -> Result<RpcLogin> {
@ -347,7 +348,7 @@ impl Client {
pub async fn login_api(&mut self) -> Result<String> {
let jwt = reqwest::Client::new()
.get(self.api_url.join("token/new")?)
.get(self.webuntis_url.join("api/token/new")?)
.header(reqwest::header::USER_AGENT, &self.user_agent)
.header(
reqwest::header::COOKIE,
@ -691,7 +692,7 @@ impl Client {
pub async fn current_tenant(&self) -> Result<ApiTenant> {
let resp: ApiDataResponse = reqwest::Client::new()
.get(self.api_url.join("rest/view/v1/app/data")?)
.get(self.webuntis_url.join("api/rest/view/v1/app/data")?)
.header(reqwest::header::USER_AGENT, &self.user_agent)
.header(reqwest::header::ACCEPT, "application/json")
.header(
@ -711,7 +712,9 @@ impl Client {
}
pub async fn teachers(&self) -> Result<Vec<ApiTeacher>> {
let mut url = self.api_url.join("public/timetable/weekly/pageconfig")?;
let mut url = self
.webuntis_url
.join("api/public/timetable/weekly/pageconfig")?;
url.query_pairs_mut().append_pair("type", "2");
let resp: ApiTeachersResponse = reqwest::Client::new()
.get(url)