Files
open-meteo-cli/src/ip_api/ip_api.rs
T
2023-06-18 13:53:45 +02:00

10 lines
368 B
Rust

use crate::ip_api::ip_location::IpLocation;
pub fn extract_coords_and_city(ip: &str) -> Result<IpLocation, ureq::Error> {
let url = format!("http://ip-api.com/json/{}?fields=16592", ip);
let body: serde_json::Value = ureq::get(&url).call()?.into_json()?;
let current_weather: IpLocation = serde_json::from_value(body).unwrap();
Ok(current_weather)
}