use serde::{de::DeserializeOwned, Serialize}; use crate::settings::get_current_account; pub mod communities; pub mod community; pub mod post; pub mod posts; pub mod search; pub mod user; pub mod auth; pub mod moderation; pub mod comment; pub mod site; static API_VERSION: &str = "v3"; use reqwest::blocking::Client; use relm4::once_cell::sync::Lazy; pub static CLIENT: Lazy = Lazy::new(|| { Client::new() }); fn get_api_url() -> String { format!("{}/api/{}", get_current_account().instance_url, API_VERSION).to_string() } fn get_url(path: &str) -> String { format!("{}{}", get_api_url(), path) } fn get(path: &str, params: &Params) -> Result where T: DeserializeOwned, Params: Serialize + std::fmt::Debug, { CLIENT .get(&get_url(path)) .query(¶ms) .send()? .json() } fn post(path: &str, params: &Params) -> Result where T: DeserializeOwned, Params: Serialize + std::fmt::Debug, { CLIENT .post(&get_url(path)) .json(¶ms) .send()? .json() } fn put(path: &str, params: &Params) -> Result where T: DeserializeOwned, Params: Serialize + std::fmt::Debug, { CLIENT .put(&get_url(path)) .json(¶ms) .send()? .json() }