// SPDX-FileCopyrightText: 2024 Eilertsens Kodeknekkeri // SPDX-FileCopyrightText: 2024 Harald Eilertsen // // SPDX-License-Identifier: AGPL-3.0-or-later use serde::{Deserialize, Serialize}; use std::error::Error; pub struct Connection { pub url: String, pub jwt_token: String, } impl Connection { pub fn new>(url: T, jwt_token: T) -> Connection { Connection { url: url.into(), jwt_token: jwt_token.into(), } } pub fn get Deserialize<'de>>(&self, resource: &str) -> Result> { Ok(ureq::get(&format!("{}/{}", self.url, resource)) .set("Accept", "application/json") .call()? .into_json()?) } pub fn post(&self, resource: &str, data: &T) -> Result> { Ok(ureq::post(&format!("{}/{}", self.url, resource)) .set("Authorization", &format!("Bearer {}", self.jwt_token)) .set("Content-Type", "application/json") .send_json(&data)? .into_string()?) } }