Reorganizing files
This commit is contained in:
parent
1c4077ffc3
commit
883a0669fe
11 changed files with 105 additions and 45 deletions
40
src/api/client.rs
Normal file
40
src/api/client.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use anyhow::Result;
|
||||
use reqwest::blocking::Client;
|
||||
|
||||
use crate::{
|
||||
api::endpoints::UptimeKumaEndpoints,
|
||||
data::{self, heartbeat::HeartbeatResponse, status_page::model::StatusPageResponse},
|
||||
};
|
||||
|
||||
pub struct UptimeKumaClient {
|
||||
client: Client,
|
||||
}
|
||||
|
||||
impl UptimeKumaClient {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
client: Client::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fetch_heartbeat(&self, endpoints: &UptimeKumaEndpoints) -> Result<HeartbeatResponse> {
|
||||
let response = self.client.get(endpoints.heartbeat_url()).send()?;
|
||||
|
||||
if response.status().is_success() {
|
||||
let json_text = response.text()?;
|
||||
data::heartbeat::parse_response(&json_text)
|
||||
} else {
|
||||
return Err(anyhow::anyhow!(response.status()));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fetch_status_page(&self, endpoints: &UptimeKumaEndpoints) -> Result<StatusPageResponse> {
|
||||
let response = self.client.get(endpoints.status_page_url()).send()?;
|
||||
if response.status().is_success() {
|
||||
let json_text = response.text()?;
|
||||
data::status_page::parse_response(&json_text)
|
||||
} else {
|
||||
return Err(anyhow::anyhow!(response.status()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue