Gettign monitors from status page API
This commit is contained in:
18
src/api.rs
18
src/api.rs
@@ -30,14 +30,16 @@ pub struct KumaStatusPage {
|
||||
|
||||
impl KumaStatusPage {
|
||||
fn get_monitors(json: &Value) -> Vec<KumaMonitor> {
|
||||
let monitor_list = &json["publicGroupList"]["monitorList"];
|
||||
return match monitor_list.as_array() {
|
||||
Some(list) => list.iter().map(|mon| KumaMonitor {
|
||||
id: mon["id"].as_i64().unwrap_or(0),
|
||||
name: mon["name"].to_string()
|
||||
}).collect(),
|
||||
None => vec![]
|
||||
};
|
||||
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()
|
||||
});
|
||||
}
|
||||
}
|
||||
return monitors;
|
||||
}
|
||||
|
||||
pub async fn get(slug: &str) -> Result<Self, Error> {
|
||||
|
||||
Reference in New Issue
Block a user