use std::time::Duration;
use reqwest::blocking::{Client, RequestBuilder};
use serde_json::Value;
use crate::api;
const TIMEOUT: Duration = Duration::from_millis(1400);
pub(super) fn get(path: &str, query: &[(&str, &str)]) -> Option<Value> {
call(path, |client, url| client.get(url).query(query))
}
pub(super) fn post(path: &str, body: &Value) -> Option<Value> {
call(path, |client, url| client.post(url).json(body))
}
fn call(path: &str, request: impl FnOnce(&Client, String) -> RequestBuilder) -> Option<Value> {
let client = api::client(TIMEOUT).ok()?;
let resp = request(&client, format!("{}{path}", api::base_url()))
.send()
.ok()?;
if !resp.status().is_success() {
return None;
}
resp.json().ok()
}