use reqwest::Method;
use serde_json::Value;
use crate::NvisyRt;
#[cfg(feature = "tracing")]
use crate::TRACING_TARGET_SERVICE;
use crate::error::Result;
use crate::model::{Analytics, Health};
pub trait InfraService {
fn health(&self) -> impl Future<Output = Result<Health>> + Send;
fn analytics(&self) -> impl Future<Output = Result<Analytics>> + Send;
fn openapi_spec(&self) -> impl Future<Output = Result<Value>> + Send;
}
impl InfraService for NvisyRt {
async fn health(&self) -> Result<Health> {
#[cfg(feature = "tracing")]
tracing::debug!(target: TRACING_TARGET_SERVICE, "checking health");
let response = self.send(Method::GET, "/health").await?;
Ok(response.json().await?)
}
async fn analytics(&self) -> Result<Analytics> {
#[cfg(feature = "tracing")]
tracing::debug!(target: TRACING_TARGET_SERVICE, "getting analytics");
let response = self.send(Method::GET, "/api/v1/analytics").await?;
Ok(response.json().await?)
}
async fn openapi_spec(&self) -> Result<Value> {
#[cfg(feature = "tracing")]
tracing::debug!(target: TRACING_TARGET_SERVICE, "getting openapi spec");
let response = self.send(Method::GET, "/api/v1/openapi.json").await?;
Ok(response.json().await?)
}
}