Ordering some files
This commit is contained in:
9
src/open_meteo/current_weather.rs
Normal file
9
src/open_meteo/current_weather.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct CurrentWeather {
|
||||
pub is_day: i32,
|
||||
pub temperature: f64,
|
||||
pub windspeed: f64,
|
||||
pub winddirection: f64,
|
||||
}
|
21
src/open_meteo/open_meteo.rs
Normal file
21
src/open_meteo/open_meteo.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use crate::{
|
||||
coords::Coordinates,
|
||||
formats::speed_unit::{speed_to_string, SpeedUnit},
|
||||
formats::temp_unit::{temp_to_string, TempUnit},
|
||||
open_meteo::current_weather::CurrentWeather,
|
||||
};
|
||||
|
||||
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={}&temperature_unit={}&windspeed_unit={}¤t_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();
|
||||
let current_weather: CurrentWeather = serde_json::from_value(current_weather).unwrap();
|
||||
Ok(current_weather)
|
||||
}
|
Reference in New Issue
Block a user