Adding SpeedUnit and TempUnit

This commit is contained in:
2023-06-08 23:10:21 +02:00
parent 09df3cc6ed
commit cd04da0d91
9 changed files with 184 additions and 46 deletions
+13 -4
View File
@@ -1,9 +1,18 @@
use crate::{coords::Coordinates, current_weather::CurrentWeather};
use crate::{
coords::Coordinates,
current_weather::CurrentWeather,
speed_unit::{speed_to_string, SpeedUnit},
temp_unit::{temp_to_string, TempUnit},
};
pub fn request_current_weather(coords: &Coordinates) -> Result<CurrentWeather, ureq::Error> {
pub fn request_current_weather(
coords: &Coordinates,
temp_unit: &TempUnit,
speed_unit: &SpeedUnit,
) -> Result<CurrentWeather, ureq::Error> {
let url = format!(
"https://api.open-meteo.com/v1/forecast?latitude={}&longitude={}&current_weather=true",
coords.latitude, coords.longitude
"https://api.open-meteo.com/v1/forecast?latitude={}&longitude={}&temperature_unit={}&windspeed_unit={}&current_weather=true",
coords.latitude, coords.longitude, temp_to_string(temp_unit), speed_to_string(speed_unit)
);
let mut body: serde_json::Value = ureq::get(&url).call()?.into_json()?;
let current_weather = body["current_weather"].take();