use crate::v1::{
api::Client,
error::APIError,
helpers::format_response,
resources::{
batch::{Batch, CreateBatchParameters},
shared::{ListResponse, SimpleListParameters},
},
};
pub struct Batches<'a> {
pub client: &'a Client,
}
impl Client {
pub fn batches(&self) -> Batches<'_> {
Batches { client: self }
}
}
impl Batches<'_> {
pub async fn create(&self, parameters: CreateBatchParameters) -> Result<Batch, APIError> {
let response = self.client.post("/batches", ¶meters, None).await?;
let response: Batch = format_response(response.data)?;
Ok(response)
}
pub async fn retrieve(&self, id: &str) -> Result<Batch, APIError> {
let response = self.client.get(&format!("/batches/{id}")).await?;
let response: Batch = format_response(response)?;
Ok(response)
}
pub async fn cancel(&self, id: &str) -> Result<Batch, APIError> {
let response = self
.client
.post(&format!("/batches/{id}/cancel"), &(), None)
.await?;
let response: Batch = format_response(response.data)?;
Ok(response)
}
pub async fn list(
&self,
query: Option<SimpleListParameters>,
) -> Result<ListResponse<Batch>, APIError> {
let response = self.client.get_with_query("/batches", &query).await?;
let response: ListResponse<Batch> = format_response(response)?;
Ok(response)
}
}