feat: Reporting

This commit is contained in:
2026-02-09 17:00:22 +01:00
parent 7090595505
commit 7738043a80
2 changed files with 41 additions and 0 deletions

View File

@@ -1,3 +1,5 @@
use serde::Deserialize;
use crate::models::{ApiResponse, SuplError};
pub fn fetch_api(provider_url: &str) -> Result<ApiResponse, SuplError> {
@@ -14,3 +16,34 @@ pub fn fetch_api(provider_url: &str) -> Result<ApiResponse, SuplError> {
reason: e.to_string(),
})
}
#[derive(Deserialize)]
struct StatusResponse {
working: bool,
message: Option<String>,
}
pub fn test_api(provider_url: &str) -> Result<(), SuplError> {
let trimmed = provider_url.trim_end_matches('/');
let url = format!("{}/status", trimmed);
let status: StatusResponse = minreq::get(&url)
.send()
.map_err(|e| SuplError::NetworkError {
reason: e.to_string(),
})?
.json()
.map_err(|e| SuplError::ParseError {
reason: e.to_string(),
})?;
if status.working {
Ok(())
} else {
Err(SuplError::ParseError {
reason: status
.message
.unwrap_or_else(|| "Provider reported not working".to_string()),
})
}
}