use crate::context::GeoffreyContext; use crate::error::BotError; use geoffrey_models::models::parameters::{CommandRequest, GeoffreyParam}; use geoffrey_models::models::response::APIResponse; use reqwest::Method; use serde::de::DeserializeOwned; pub fn build_url(base_str: &str, end_point: &str) -> String { let slash = if !base_str.ends_with('/') { "/" } else { "" }; format!("{}{}{}", base_str, slash, end_point) } pub async fn run_api_query( ctx: &GeoffreyContext, param: &CommandRequest, method: Method, endpoint: &str, ) -> Result { let resp: APIResponse = ctx .http_client .request(method, build_url(&ctx.cfg.api.base_url, endpoint)) .json(param) .send() .await? .json() .await?; match resp { APIResponse::Response(resp) => Ok(resp), APIResponse::Error { error: e, .. } => Err(e.into()), } }