use std::sync::Arc;
use crate::batch::BatchSvc;
use crate::config::{Config, ConfigBuilder};
use crate::emails::EmailsSvc;
#[derive(Clone, Debug)]
pub struct JetEmail {
pub emails: EmailsSvc,
pub batch: BatchSvc,
}
impl JetEmail {
pub fn new(api_key: impl Into<String>) -> Self {
let config = ConfigBuilder::new(api_key).build();
Self::with_config(config)
}
#[cfg(not(feature = "blocking"))]
pub fn with_client(api_key: impl Into<String>, client: reqwest::Client) -> Self {
let config = ConfigBuilder::new(api_key).client(client).build();
Self::with_config(config)
}
#[cfg(feature = "blocking")]
pub fn with_client(api_key: impl Into<String>, client: reqwest::blocking::Client) -> Self {
let config = ConfigBuilder::new(api_key).client(client).build();
Self::with_config(config)
}
pub fn with_config(config: Config) -> Self {
let config = Arc::new(config);
Self {
emails: EmailsSvc(Arc::clone(&config)),
batch: BatchSvc(Arc::clone(&config)),
}
}
}
impl Default for JetEmail {
fn default() -> Self {
let api_key = std::env::var("JETEMAIL_API_KEY")
.expect("JETEMAIL_API_KEY environment variable must be set");
Self::new(api_key)
}
}