use reqwest::Method;
use super::urlencode;
use crate::error::Result;
use crate::http::HttpTransport;
use crate::models::{CreateTemplate, Template, UpdateTemplate};
#[derive(Debug, Clone)]
pub struct Templates {
http: HttpTransport,
}
impl Templates {
pub(crate) fn new(http: HttpTransport) -> Self {
Self { http }
}
pub async fn list(&self) -> Result<Vec<Template>> {
self.http.request(Method::GET, "/v1/templates/").await
}
pub async fn create(&self, params: &CreateTemplate) -> Result<Template> {
self.http
.request_json(Method::POST, "/v1/templates/", params)
.await
}
pub async fn get(&self, id: &str) -> Result<Template> {
self.http
.request(Method::GET, &format!("/v1/templates/{}", urlencode(id)))
.await
}
pub async fn update(&self, id: &str, params: &UpdateTemplate) -> Result<Template> {
self.http
.request_json(
Method::PATCH,
&format!("/v1/templates/{}", urlencode(id)),
params,
)
.await
}
pub async fn delete(&self, id: &str) -> Result<()> {
self.http
.request_empty(Method::DELETE, &format!("/v1/templates/{}", urlencode(id)))
.await
}
pub async fn duplicate(&self, id: &str) -> Result<Template> {
self.http
.request(
Method::POST,
&format!("/v1/templates/{}/duplicate", urlencode(id)),
)
.await
}
}