diff --git a/src/lib.rs b/src/lib.rs index 651618e..b6be2de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { + 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 { @@ -347,7 +348,7 @@ impl Client { pub async fn login_api(&mut self) -> Result { 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 { 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> { - 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)