use std::sync::Arc;
use crate::{
async_impl::http::client,
common::{
errors,
switch::templates::{TemplateItem, TemplatesRequest},
},
};
#[derive(Debug)]
pub struct Templates<'a> {
api_key: &'a str,
client: Arc<client::HttpClient>,
}
impl<'a> Templates<'a> {
pub(crate) fn new(api_key: &'a str, client: Arc<client::HttpClient>) -> Templates<'a> {
Templates { api_key, client }
}
pub async fn send<T>(
&self,
mut payload: TemplatesRequest,
) -> Result<Vec<TemplateItem>, errors::HttpError> {
payload.set_api_key(self.api_key);
let response = self
.client
.post("send/templates", None, None, Some(payload))
.await?;
let template = response_or_error_text_async!(response, Vec<TemplateItem>);
Ok(template)
}
}