This commit is contained in:
Dominic Grimm 2022-12-20 18:44:55 +01:00
parent f0321d6409
commit 197b4e2ecf
No known key found for this signature in database
GPG key ID: 6F294212DEAAC530

View file

@ -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<String>,
@ -304,6 +305,7 @@ impl Client {
pub async fn login_rpc(&mut self) -> Result<RpcLogin> {
let resp: RpcResponse<RpcLogin> = 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<String> {
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<RpcEmptyResult> = 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<Vec<RpcClass>> {
let resp: RpcResponse<Vec<RpcClass>> = 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<Vec<RpcSubject>> {
let resp: RpcResponse<Vec<RpcSubject>> = 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<Vec<RpcRoom>> {
let resp: RpcResponse<Vec<RpcRoom>> = 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<Vec<RpcDepartment>> {
let resp: RpcResponse<Vec<RpcDepartment>> = 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<Vec<RpcHoliday>> {
let resp: RpcResponse<Vec<RpcHoliday>> = 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<Vec<RpcTimegridDay>> {
let resp: RpcResponse<Vec<RpcTimegridDay>> = 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<RpcSchoolyear> {
let resp: RpcResponse<RpcSchoolyear> = 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<Vec<RpcSchoolyear>> {
let resp: RpcResponse<Vec<RpcSchoolyear>> = 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<Vec<RpcSubstitution>> {
let resp: RpcResponse<Vec<RpcSubstitution>> = 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<ApiTenant> {
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,