1use crate::error::Result;
6use crate::http::HttpClient;
7use crate::types::pty::{CreatePtyRequest, Pty, UpdatePtyRequest};
8use reqwest::Method;
9
10#[derive(Clone)]
12pub struct PtyApi {
13 http: HttpClient,
14}
15
16impl PtyApi {
17 pub fn new(http: HttpClient) -> Self {
19 Self { http }
20 }
21
22 pub async fn list(&self) -> Result<Vec<Pty>> {
28 self.http.request_json(Method::GET, "/pty", None).await
29 }
30
31 pub async fn create(&self, req: &CreatePtyRequest) -> Result<Pty> {
37 let body = serde_json::to_value(req)?;
38 self.http
39 .request_json(Method::POST, "/pty", Some(body))
40 .await
41 }
42
43 pub async fn get(&self, id: &str) -> Result<Pty> {
49 self.http
50 .request_json(Method::GET, &format!("/pty/{}", id), None)
51 .await
52 }
53
54 pub async fn update(&self, id: &str, req: &UpdatePtyRequest) -> Result<Pty> {
60 let body = serde_json::to_value(req)?;
61 self.http
62 .request_json(Method::PUT, &format!("/pty/{}", id), Some(body))
63 .await
64 }
65
66 pub async fn delete(&self, id: &str) -> Result<()> {
72 self.http
73 .request_empty(Method::DELETE, &format!("/pty/{}", id), None)
74 .await
75 }
76}