use crate::client::{Client, ParamType};
use std::collections::HashMap;
use crate::services::AppwriteException;
use crate::models;
use serde_json::json;
use std::io::Read;
#[derive(Clone)]
pub struct Health {
client: Client
}
impl Health {
pub fn new(client: &Client) -> Self {
Self {
client: client.clone()
}
}
pub fn get(&self) -> Result<models::HealthStatus, AppwriteException> {
let path = "/health";
let headers: HashMap<String, String> = [
("content-type".to_string(), "application/json".to_string()),
].iter().cloned().collect();
let params: HashMap<String, ParamType> = [
].iter().cloned().collect();
let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
let processedResponse:models::HealthStatus = match response {
Ok(r) => {
match r.json() {
Ok(json) => json,
Err(e) => {
return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
}
}
}
Err(e) => {
return Err(e);
}
};
Ok(processedResponse)
}
pub fn get_antivirus(&self) -> Result<models::HealthAntivirus, AppwriteException> {
let path = "/health/anti-virus";
let headers: HashMap<String, String> = [
("content-type".to_string(), "application/json".to_string()),
].iter().cloned().collect();
let params: HashMap<String, ParamType> = [
].iter().cloned().collect();
let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
let processedResponse:models::HealthAntivirus = match response {
Ok(r) => {
match r.json() {
Ok(json) => json,
Err(e) => {
return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
}
}
}
Err(e) => {
return Err(e);
}
};
Ok(processedResponse)
}
pub fn get_cache(&self) -> Result<models::HealthStatus, AppwriteException> {
let path = "/health/cache";
let headers: HashMap<String, String> = [
("content-type".to_string(), "application/json".to_string()),
].iter().cloned().collect();
let params: HashMap<String, ParamType> = [
].iter().cloned().collect();
let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
let processedResponse:models::HealthStatus = match response {
Ok(r) => {
match r.json() {
Ok(json) => json,
Err(e) => {
return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
}
}
}
Err(e) => {
return Err(e);
}
};
Ok(processedResponse)
}
pub fn get_db(&self) -> Result<models::HealthStatus, AppwriteException> {
let path = "/health/db";
let headers: HashMap<String, String> = [
("content-type".to_string(), "application/json".to_string()),
].iter().cloned().collect();
let params: HashMap<String, ParamType> = [
].iter().cloned().collect();
let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
let processedResponse:models::HealthStatus = match response {
Ok(r) => {
match r.json() {
Ok(json) => json,
Err(e) => {
return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
}
}
}
Err(e) => {
return Err(e);
}
};
Ok(processedResponse)
}
pub fn get_queue_certificates(&self) -> Result<models::HealthQueue, AppwriteException> {
let path = "/health/queue/certificates";
let headers: HashMap<String, String> = [
("content-type".to_string(), "application/json".to_string()),
].iter().cloned().collect();
let params: HashMap<String, ParamType> = [
].iter().cloned().collect();
let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
let processedResponse:models::HealthQueue = match response {
Ok(r) => {
match r.json() {
Ok(json) => json,
Err(e) => {
return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
}
}
}
Err(e) => {
return Err(e);
}
};
Ok(processedResponse)
}
pub fn get_queue_functions(&self) -> Result<models::HealthQueue, AppwriteException> {
let path = "/health/queue/functions";
let headers: HashMap<String, String> = [
("content-type".to_string(), "application/json".to_string()),
].iter().cloned().collect();
let params: HashMap<String, ParamType> = [
].iter().cloned().collect();
let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
let processedResponse:models::HealthQueue = match response {
Ok(r) => {
match r.json() {
Ok(json) => json,
Err(e) => {
return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
}
}
}
Err(e) => {
return Err(e);
}
};
Ok(processedResponse)
}
pub fn get_queue_logs(&self) -> Result<models::HealthQueue, AppwriteException> {
let path = "/health/queue/logs";
let headers: HashMap<String, String> = [
("content-type".to_string(), "application/json".to_string()),
].iter().cloned().collect();
let params: HashMap<String, ParamType> = [
].iter().cloned().collect();
let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
let processedResponse:models::HealthQueue = match response {
Ok(r) => {
match r.json() {
Ok(json) => json,
Err(e) => {
return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
}
}
}
Err(e) => {
return Err(e);
}
};
Ok(processedResponse)
}
pub fn get_queue_usage(&self) -> Result<models::HealthQueue, AppwriteException> {
let path = "/health/queue/usage";
let headers: HashMap<String, String> = [
("content-type".to_string(), "application/json".to_string()),
].iter().cloned().collect();
let params: HashMap<String, ParamType> = [
].iter().cloned().collect();
let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
let processedResponse:models::HealthQueue = match response {
Ok(r) => {
match r.json() {
Ok(json) => json,
Err(e) => {
return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
}
}
}
Err(e) => {
return Err(e);
}
};
Ok(processedResponse)
}
pub fn get_queue_webhooks(&self) -> Result<models::HealthQueue, AppwriteException> {
let path = "/health/queue/webhooks";
let headers: HashMap<String, String> = [
("content-type".to_string(), "application/json".to_string()),
].iter().cloned().collect();
let params: HashMap<String, ParamType> = [
].iter().cloned().collect();
let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
let processedResponse:models::HealthQueue = match response {
Ok(r) => {
match r.json() {
Ok(json) => json,
Err(e) => {
return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
}
}
}
Err(e) => {
return Err(e);
}
};
Ok(processedResponse)
}
pub fn get_storage_local(&self) -> Result<models::HealthStatus, AppwriteException> {
let path = "/health/storage/local";
let headers: HashMap<String, String> = [
("content-type".to_string(), "application/json".to_string()),
].iter().cloned().collect();
let params: HashMap<String, ParamType> = [
].iter().cloned().collect();
let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
let processedResponse:models::HealthStatus = match response {
Ok(r) => {
match r.json() {
Ok(json) => json,
Err(e) => {
return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
}
}
}
Err(e) => {
return Err(e);
}
};
Ok(processedResponse)
}
pub fn get_time(&self) -> Result<models::HealthTime, AppwriteException> {
let path = "/health/time";
let headers: HashMap<String, String> = [
("content-type".to_string(), "application/json".to_string()),
].iter().cloned().collect();
let params: HashMap<String, ParamType> = [
].iter().cloned().collect();
let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
let processedResponse:models::HealthTime = match response {
Ok(r) => {
match r.json() {
Ok(json) => json,
Err(e) => {
return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
}
}
}
Err(e) => {
return Err(e);
}
};
Ok(processedResponse)
}
}