use reqwest::Method;
use url::Url;
#[cfg(feature = "derive")]
pub use fav_derive::Api;
#[allow(missing_docs)]
pub enum DefaultApiKind {
Login,
QrLogin,
QrCheck,
Logout,
FetchResSet,
FetchRes,
PullRes,
}
pub trait ApiProvider<K> {
fn api(&self, api_kind: K) -> &dyn Api;
}
pub trait Api {
fn endpoint(&self) -> &'static str;
fn params(&self) -> &[&str];
fn cookie_keys(&self) -> &[&str] {
&[]
}
fn url(&self, params: &[&str]) -> Url {
Url::parse_with_params(self.endpoint(), self.params().iter().zip(params.iter())).unwrap()
}
fn method(&self) -> Method {
Method::GET
}
}
#[cfg(test)]
mod tests {
use super::*;
struct Remote;
impl ApiProvider<DefaultApiKind> for Remote {
fn api(&self, api_kind: DefaultApiKind) -> &dyn Api {
match api_kind {
DefaultApiKind::Login => todo!(),
_ => todo!(),
}
}
}
struct LoginApi;
impl Api for LoginApi {
fn endpoint(&self) -> &'static str {
"http://abc.com"
}
fn params(&self) -> &[&str] {
&["id", "pwd"]
}
}
}