Creating blank Monitor objects
This commit is contained in:
25
src/api.rs
25
src/api.rs
@@ -14,10 +14,18 @@ macro_rules! endpoints {
|
||||
($slug:expr) => { format!("{}/api/status-page/{}", crate::api::BASE_URL, $slug) }
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct HeartBeat {
|
||||
status: i64,
|
||||
time: String,
|
||||
msg: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct KumaMonitor {
|
||||
id: i64,
|
||||
name: String,
|
||||
heartbeats: Option<Vec<HeartBeat>>
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -28,15 +36,23 @@ pub struct KumaStatusPage {
|
||||
monitors: Vec<KumaMonitor>
|
||||
}
|
||||
|
||||
impl KumaMonitor {
|
||||
pub fn blank(val: &Value) -> Self {
|
||||
Self {
|
||||
id: val["id"].as_i64().unwrap_or(0),
|
||||
name: val["name"].to_string(),
|
||||
heartbeats: None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl KumaStatusPage {
|
||||
fn get_monitors(json: &Value) -> Vec<KumaMonitor> {
|
||||
let mut monitors = vec![];
|
||||
for group in json["publicGroupList"].as_array().unwrap_or(&vec![]) {
|
||||
for monitor in group["monitorList"].as_array().unwrap_or(&vec![]) {
|
||||
monitors.push(KumaMonitor {
|
||||
id: monitor["id"].as_i64().unwrap_or(0),
|
||||
name: monitor["name"].to_string()
|
||||
});
|
||||
monitors.push(KumaMonitor::blank(&monitor));
|
||||
}
|
||||
}
|
||||
return monitors;
|
||||
@@ -53,3 +69,4 @@ impl KumaStatusPage {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user