use serde::de::DeserializeOwned;
use crate::api::ApiClient;
use crate::error::Result;
pub struct CustomBuilder<'a> {
api_client: &'a ApiClient,
function: &'a str,
extras: Vec<(&'a str, &'a str)>,
}
impl<'a> CustomBuilder<'a> {
#[must_use]
pub fn new(api_client: &'a ApiClient, function: &'a str) -> Self {
Self {
api_client,
function,
extras: vec![],
}
}
pub fn extra_params(&mut self, key: &'a str, value: &'a str) -> &mut Self {
self.extras.push((key, value));
self
}
fn create_url(&self) -> String {
let mut path = format!("query?function={}", self.function);
for (key, value) in &self.extras {
path.push_str(format!("&{key}={value}").as_str());
}
path
}
pub async fn json<T>(&self) -> Result<T>
where
T: DeserializeOwned,
{
let url = self.create_url();
self.api_client.get_json(&url).await
}
}