use crate::api::{Client, seg};
use crate::error::Result;
use crate::transport::{Method, Request};
use crate::types::{ImageEntry, ImageInventory, ImageSweep};
use serde_json::json;
impl Client {
pub async fn images(&self) -> Result<ImageInventory> {
self.read(Request::new(Method::Get, "/images"), "image", "")
.await
}
pub async fn sweep_images(&self) -> Result<ImageSweep> {
self.read(Request::new(Method::Post, "/images/sweep"), "image", "")
.await
}
pub async fn offload_image(&self, name: &str) -> Result<ImageEntry> {
self.read(
Request::new(Method::Post, format!("/images/{}/offload", seg(name))),
"image",
name,
)
.await
}
pub async fn delete_image(&self, name: &str) -> Result<()> {
self.unit(
Request::new(Method::Delete, format!("/images/{}", seg(name))),
"image",
name,
)
.await
}
pub async fn pin_image(&self, name: &str, pinned: bool) -> Result<ImageEntry> {
self.read(
Request::new(Method::Patch, format!("/images/{}", seg(name)))
.json(json!({ "pinned": pinned })),
"image",
name,
)
.await
}
}