Adding automatic IP address, some refactor and better texts. Upgrading version.
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user