open-meteo-cli/src/open_meteo.rs

13 lines
582 B
Rust
Raw Normal View History

use crate::{coords::Coordinates, current_weather::CurrentWeather};
pub fn request_current_weather(coords: &Coordinates) -> Result<CurrentWeather, ureq::Error> {
let url = format!(
"https://api.open-meteo.com/v1/forecast?latitude={}&longitude={}&current_weather=true",
coords.latitude, coords.longitude
);
let mut body: serde_json::Value = ureq::get(&url).call()?.into_json()?;
let current_weather = body["current_weather"].take();
let current_weather: CurrentWeather = serde_json::from_value(current_weather).unwrap();
Ok(current_weather)
}