From 197b4e2ecf94bd1765593e8680008162d41a3015 Mon Sep 17 00:00:00 2001 From: Dominic Grimm Date: Tue, 20 Dec 2022 18:44:55 +0100 Subject: [PATCH] Update --- src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index c54d77f..6b876c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -288,6 +288,7 @@ pub struct Client { pub api_url: url::Url, pub rpc_url: url::Url, pub client_name: String, + pub user_agent: String, pub username: String, pub password: String, pub session: Option, @@ -304,6 +305,7 @@ impl Client { pub async fn login_rpc(&mut self) -> Result { let resp: RpcResponse = reqwest::Client::new() .get(self.rpc_url.as_str()) + .header(reqwest::header::USER_AGENT, &self.user_agent) .header(reqwest::header::CONTENT_TYPE, "application/json") .header(reqwest::header::ACCEPT, "application/json") .json(&json!({ @@ -346,6 +348,7 @@ impl Client { pub async fn login_api(&mut self) -> Result { let jwt = reqwest::Client::new() .get(self.api_url.join("token/new")?) + .header(reqwest::header::USER_AGENT, &self.user_agent) .header( reqwest::header::COOKIE, self.session.as_ref().context("Not logged in")?, @@ -369,6 +372,7 @@ impl Client { pub async fn logout(&mut self) -> Result<()> { let resp: RpcResponse = reqwest::Client::new() .get(self.rpc_url.as_str()) + .header(reqwest::header::USER_AGENT, &self.user_agent) .header(reqwest::header::CONTENT_TYPE, "application/json") .header(reqwest::header::ACCEPT, "application/json") .header( @@ -396,6 +400,7 @@ impl Client { pub async fn classes(&self) -> Result> { let resp: RpcResponse> = reqwest::Client::new() .get(self.rpc_url.as_str()) + .header(reqwest::header::USER_AGENT, &self.user_agent) .header(reqwest::header::CONTENT_TYPE, "application/json") .header(reqwest::header::ACCEPT, "application/json") .header( @@ -426,6 +431,7 @@ impl Client { pub async fn subjects(&self) -> Result> { let resp: RpcResponse> = reqwest::Client::new() .get(self.rpc_url.as_str()) + .header(reqwest::header::USER_AGENT, &self.user_agent) .header(reqwest::header::CONTENT_TYPE, "application/json") .header(reqwest::header::ACCEPT, "application/json") .header( @@ -456,6 +462,7 @@ impl Client { pub async fn rooms(&self) -> Result> { let resp: RpcResponse> = reqwest::Client::new() .get(self.rpc_url.as_str()) + .header(reqwest::header::USER_AGENT, &self.user_agent) .header(reqwest::header::CONTENT_TYPE, "application/json") .header(reqwest::header::ACCEPT, "application/json") .header( @@ -486,6 +493,7 @@ impl Client { pub async fn departments(&self) -> Result> { let resp: RpcResponse> = reqwest::Client::new() .get(self.rpc_url.as_str()) + .header(reqwest::header::USER_AGENT, &self.user_agent) .header(reqwest::header::CONTENT_TYPE, "application/json") .header(reqwest::header::ACCEPT, "application/json") .header( @@ -516,6 +524,7 @@ impl Client { pub async fn holidays(&self) -> Result> { let resp: RpcResponse> = reqwest::Client::new() .get(self.rpc_url.as_str()) + .header(reqwest::header::USER_AGENT, &self.user_agent) .header(reqwest::header::CONTENT_TYPE, "application/json") .header(reqwest::header::ACCEPT, "application/json") .header( @@ -546,6 +555,7 @@ impl Client { pub async fn timegrid(&self) -> Result> { let resp: RpcResponse> = reqwest::Client::new() .get(self.rpc_url.as_str()) + .header(reqwest::header::USER_AGENT, &self.user_agent) .header(reqwest::header::CONTENT_TYPE, "application/json") .header(reqwest::header::ACCEPT, "application/json") .header( @@ -576,6 +586,7 @@ impl Client { pub async fn current_schoolyear(&self) -> Result { let resp: RpcResponse = reqwest::Client::new() .get(self.rpc_url.as_str()) + .header(reqwest::header::USER_AGENT, &self.user_agent) .header(reqwest::header::CONTENT_TYPE, "application/json") .header(reqwest::header::ACCEPT, "application/json") .header( @@ -606,6 +617,7 @@ impl Client { pub async fn schoolyears(&self) -> Result> { let resp: RpcResponse> = reqwest::Client::new() .get(self.rpc_url.as_str()) + .header(reqwest::header::USER_AGENT, &self.user_agent) .header(reqwest::header::CONTENT_TYPE, "application/json") .header(reqwest::header::ACCEPT, "application/json") .header( @@ -641,6 +653,7 @@ impl Client { ) -> Result> { let resp: RpcResponse> = reqwest::Client::new() .get(self.rpc_url.as_str()) + .header(reqwest::header::USER_AGENT, &self.user_agent) .header(reqwest::header::CONTENT_TYPE, "application/json") .header(reqwest::header::ACCEPT, "application/json") .header( @@ -679,6 +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")?) + .header(reqwest::header::USER_AGENT, &self.user_agent) .header(reqwest::header::ACCEPT, "application/json") .header( reqwest::header::COOKIE, @@ -701,6 +715,7 @@ impl Client { url.query_pairs_mut().append_pair("type", "2"); let resp: ApiTeachersResponse = reqwest::Client::new() .get(url) + .header(reqwest::header::USER_AGENT, &self.user_agent) .header(reqwest::header::ACCEPT, "application/json") .header( reqwest::header::COOKIE,