use crate::error::Result;
use crate::http::HttpClient;
use crate::types::pty::CreatePtyRequest;
use crate::types::pty::Pty;
use crate::types::pty::UpdatePtyRequest;
use reqwest::Method;
#[derive(Clone)]
pub struct PtyApi {
http: HttpClient,
}
impl PtyApi {
pub fn new(http: HttpClient) -> Self {
Self { http }
}
pub async fn list(&self) -> Result<Vec<Pty>> {
self.http.request_json(Method::GET, "/pty", None).await
}
pub async fn create(&self, req: &CreatePtyRequest) -> Result<Pty> {
let body = serde_json::to_value(req)?;
self.http
.request_json(Method::POST, "/pty", Some(body))
.await
}
pub async fn get(&self, id: &str) -> Result<Pty> {
self.http
.request_json(Method::GET, &format!("/pty/{id}"), None)
.await
}
pub async fn update(&self, id: &str, req: &UpdatePtyRequest) -> Result<Pty> {
let body = serde_json::to_value(req)?;
self.http
.request_json(Method::PUT, &format!("/pty/{id}"), Some(body))
.await
}
pub async fn delete(&self, id: &str) -> Result<bool> {
self.http
.request_json::<bool>(Method::DELETE, &format!("/pty/{id}"), None)
.await
}
}