use std::sync::Arc;
use crate::error::Result;
use crate::http::HttpClient;
use crate::types::{AppMonitor, CreateMonitorRequest, MonitorHistory};
#[derive(Clone)]
pub struct MonitorsResource {
pub(crate) http: Arc<HttpClient>,
}
impl MonitorsResource {
pub async fn list(&self, jwt: &str) -> Result<Vec<AppMonitor>> {
self.http.get("/monitors/app", Some(jwt)).await
}
pub async fn create(
&self,
request: CreateMonitorRequest,
jwt: &str,
) -> Result<AppMonitor> {
self.http.post("/monitors/app", &request, Some(jwt)).await
}
pub async fn get(&self, monitor_id: &str, jwt: &str) -> Result<AppMonitor> {
self.http
.get(&format!("/monitors/app/{monitor_id}"), Some(jwt))
.await
}
pub async fn delete(
&self,
monitor_id: &str,
jwt: &str,
) -> Result<serde_json::Value> {
self.http
.delete(&format!("/monitors/app/{monitor_id}"), Some(jwt))
.await
}
pub async fn history(&self, monitor_id: &str, jwt: &str) -> Result<Vec<MonitorHistory>> {
self.http
.get(&format!("/monitors/app/{monitor_id}/history"), Some(jwt))
.await
}
}