pub mod client;
pub mod collection;
pub mod error;
pub mod services;
pub mod types;
pub mod webhook_signature;
use std::sync::Arc;
use client::{BaseClient, DEFAULT_BASE_URL};
use services::*;
pub use client::RawResponse;
pub use collection::Collection;
pub use error::{ApiError, Error};
pub use types::*;
pub use webhook_signature::{
HEADER_SIGNATURE, HEADER_TIMESTAMP, compute_webhook_signature, verify_webhook_signature,
};
pub type Result<T> = std::result::Result<T, Error>;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub struct Emailit {
pub emails: EmailService,
pub domains: DomainService,
pub api_keys: ApiKeyService,
pub audiences: AudienceService,
pub subscribers: SubscriberService,
pub templates: TemplateService,
pub suppressions: SuppressionService,
pub email_verifications: EmailVerificationService,
pub email_verification_lists: EmailVerificationListService,
pub webhooks: WebhookService,
pub contacts: ContactService,
pub events: EventService,
client: Arc<BaseClient>,
}
impl Emailit {
pub fn new(api_key: impl Into<String>) -> Self {
Self::with_base_url(api_key, DEFAULT_BASE_URL)
}
pub fn with_base_url(api_key: impl Into<String>, base_url: impl Into<String>) -> Self {
let api_key = api_key.into();
if api_key.is_empty() {
panic!("emailit: api_key is required");
}
let base_url = base_url.into().trim_end_matches('/').to_string();
let client = Arc::new(BaseClient::new(api_key, base_url));
Self {
emails: EmailService {
client: Arc::clone(&client),
},
domains: DomainService {
client: Arc::clone(&client),
},
api_keys: ApiKeyService {
client: Arc::clone(&client),
},
audiences: AudienceService {
client: Arc::clone(&client),
},
subscribers: SubscriberService {
client: Arc::clone(&client),
},
templates: TemplateService {
client: Arc::clone(&client),
},
suppressions: SuppressionService {
client: Arc::clone(&client),
},
email_verifications: EmailVerificationService {
client: Arc::clone(&client),
},
email_verification_lists: EmailVerificationListService {
client: Arc::clone(&client),
},
webhooks: WebhookService {
client: Arc::clone(&client),
},
contacts: ContactService {
client: Arc::clone(&client),
},
events: EventService {
client: Arc::clone(&client),
},
client,
}
}
pub fn api_key(&self) -> &str {
&self.client.api_key
}
pub fn base_url(&self) -> &str {
&self.client.base_url
}
}