Refactor prom client
This commit is contained in:
parent
8e698e71c1
commit
769544b608
17
src/prom.rs
17
src/prom.rs
@ -41,10 +41,19 @@ struct MatrixEntry {
|
||||
values: Vec<(f64, String)>,
|
||||
}
|
||||
|
||||
pub fn current_power(base: &str) -> Result<(f64, f64, f64)> {
|
||||
let url = format!("{}{}", base, PROM_QUERY);
|
||||
pub struct PromClient {
|
||||
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 {
|
||||
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"))?,
|
||||
))
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user