use http::Method;
use serde_json::Value;
use crate::{Result, client::RequestOptions, types::path::PathParam};
#[cfg(feature = "blocking")]
use crate::client::BlockingClient;
#[cfg(feature = "async")]
use crate::client::Client;
#[cfg(feature = "async")]
#[derive(Clone)]
pub struct AlertService {
client: Client,
}
#[cfg(feature = "async")]
impl AlertService {
pub(crate) fn new(client: Client) -> Self {
Self { client }
}
pub async fn get(&self, query: Option<&Value>) -> Result<Value> {
let segments = ["api", "alert"];
self.client
.request_json(
Method::GET,
&segments,
query,
Option::<&()>::None,
RequestOptions::default(),
)
.await
}
pub async fn get_by_id(&self, id: impl Into<PathParam>) -> Result<Value> {
let id = id.into();
let segments = ["api", "alert", id.as_str()];
self.client
.request_json(
Method::GET,
&segments,
Option::<&()>::None,
Option::<&()>::None,
RequestOptions::default(),
)
.await
}
pub async fn delete_by_id_subscription(&self, id: impl Into<PathParam>) -> Result<Value> {
let id = id.into();
let segments = ["api", "alert", id.as_str(), "subscription"];
self.client
.request_json(
Method::DELETE,
&segments,
Option::<&()>::None,
Option::<&()>::None,
RequestOptions::default(),
)
.await
}
}
#[cfg(feature = "blocking")]
#[derive(Clone)]
pub struct BlockingAlertService {
client: BlockingClient,
}
#[cfg(feature = "blocking")]
impl BlockingAlertService {
pub(crate) fn new(client: BlockingClient) -> Self {
Self { client }
}
pub fn get(&self, query: Option<&Value>) -> Result<Value> {
let segments = ["api", "alert"];
self.client.request_json(
Method::GET,
&segments,
query,
Option::<&()>::None,
RequestOptions::default(),
)
}
pub fn get_by_id(&self, id: impl Into<PathParam>) -> Result<Value> {
let id = id.into();
let segments = ["api", "alert", id.as_str()];
self.client.request_json(
Method::GET,
&segments,
Option::<&()>::None,
Option::<&()>::None,
RequestOptions::default(),
)
}
pub fn delete_by_id_subscription(&self, id: impl Into<PathParam>) -> Result<Value> {
let id = id.into();
let segments = ["api", "alert", id.as_str(), "subscription"];
self.client.request_json(
Method::DELETE,
&segments,
Option::<&()>::None,
Option::<&()>::None,
RequestOptions::default(),
)
}
}