use reqwest::Client as ReqClient;
pub(crate) const API_URL: &str = "https://api.driftz.net";
#[derive(Debug, Clone)]
pub struct Client {
pub email: String,
pub client: ReqClient,
}
impl Client {
pub fn new<S>(email: S) -> Option<Self>
where
S: Into<String>,
{
let email = email.into();
if !email_address::EmailAddress::is_valid(&email) {
return None;
}
let client = ReqClient::new();
Some(Self { email, client })
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn valid_email() {
let correct_email = "y@iusearch.lol";
let client = Client::new(correct_email);
assert!(client.is_some())
}
#[test]
fn invalid_email() {
let incorrect_email = "y";
let client = Client::new(incorrect_email);
assert!(client.is_none())
}
}