use reqwest::Method;
use std::sync::Arc;
use crate::client::ClientInner;
use crate::error::Result;
use crate::types::{Container, CreateContainerRequest};
pub struct ContainerService {
client: Arc<ClientInner>,
}
impl ContainerService {
pub(crate) fn new(client: Arc<ClientInner>) -> Self {
Self { client }
}
pub async fn list(&self) -> Result<Vec<Container>> {
self.client.request(Method::GET, "/api/containers").await
}
pub async fn get(&self, id: &str) -> Result<Container> {
self.client
.request(Method::GET, &format!("/api/containers/{}", id))
.await
}
pub async fn create(&self, request: CreateContainerRequest) -> Result<Container> {
self.client
.request_with_body(Method::POST, "/api/containers", &request)
.await
}
pub async fn delete(&self, id: &str) -> Result<()> {
self.client
.request_empty(Method::DELETE, &format!("/api/containers/{}", id))
.await
}
pub async fn start(&self, id: &str) -> Result<()> {
self.client
.request_empty(Method::POST, &format!("/api/containers/{}/start", id))
.await
}
pub async fn stop(&self, id: &str) -> Result<()> {
self.client
.request_empty(Method::POST, &format!("/api/containers/{}/stop", id))
.await
}
}