13 lines
582 B
Rust
13 lines
582 B
Rust
|
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={}¤t_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)
|
||
|
}
|