Refactor prom client

This commit is contained in:
Maxime Augier 2024-08-18 14:36:17 +02:00
parent 8e698e71c1
commit 769544b608

View File

@ -41,10 +41,19 @@ struct MatrixEntry {
values: Vec<(f64, String)>, values: Vec<(f64, String)>,
} }
pub fn current_power(base: &str) -> Result<(f64, f64, f64)> { pub struct PromClient {
let url = format!("{}{}", base, PROM_QUERY); base: String,
power_query_url: String
}
let reply: PromReply = ureq::get(&url).call()?.into_json()?; impl PromClient {
pub fn new(base: String) -> Self {
let power_query_url = format!("{}{}", &base, PROM_QUERY);
PromClient { base, power_query_url }
}
pub fn current_power(&self) -> Result<(f64, f64, f64)> {
let reply: PromReply = ureq::get(&self.power_query_url).call()?.into_json()?;
let PromReply::Success { let PromReply::Success {
data: PromData::Vector(v), data: PromData::Vector(v),
@ -71,3 +80,5 @@ pub fn current_power(base: &str) -> Result<(f64, f64, f64)> {
r.2.ok_or_else(|| anyhow!("Missing phase c"))?, r.2.ok_or_else(|| anyhow!("Missing phase c"))?,
)) ))
} }
}