use governor::DefaultDirectRateLimiter;
#[cfg(feature = "blocking")]
use reqwest::blocking;
use serde::de::DeserializeOwned;
use std::future::Future;
use crate::error::IpApiError;
use crate::model::ip_response::{IpDefaultResponse, IpFullResponse};
pub trait IpApi {
fn get_api_key(&self) -> &Option<String>;
fn get_rate_limiter(&self) -> &Option<DefaultDirectRateLimiter>;
}
#[cfg(feature = "blocking")]
pub trait BlockingIpApi: IpApi {
fn query_api_default(&self, ip: &str) -> Result<IpDefaultResponse, IpApiError>;
fn query_api_fully(&self, ip: &str) -> Result<IpFullResponse, IpApiError>;
fn query_api<T>(&self, ip: &str) -> Result<T, IpApiError>
where
T: DeserializeOwned;
fn get_http_client(&self) -> &blocking::Client;
}
pub trait AsyncIpApi: IpApi {
fn query_api_default(&self, ip: &str) -> impl Future<Output = Result<IpDefaultResponse, IpApiError>> + Send;
fn query_api_fully(&self, ip: &str) -> impl Future<Output = Result<IpFullResponse, IpApiError>> + Send;
fn query_api<T>(&self, ip: &str) -> impl Future<Output = Result<T, IpApiError>> + Send
where
T: DeserializeOwned;
fn get_http_client(&self) -> &reqwest::Client;
}