1mod owm;
2#[cfg(test)]
3mod tests;
4mod utils;
5
6pub mod owm_structs {
7 pub use crate::owm::geocoding::structures::*;
8 pub use crate::owm::weather::structures::*;
9}
10
11pub mod owm_api {
12 use crate::{owm, owm_structs};
13
14 pub async fn get_city_coordinates(
21 city_name: String,
22 api_key: String,
23 ) -> Result<owm_structs::Coordinates, reqwest::Error> {
24 owm::geocoding::api::get_coordinates_by_location_name(city_name, api_key).await
25 }
26
27 pub async fn get_weather_by_coordinates(
36 latitude: f32,
37 longitude: f32,
38 api_key: String,
39 ) -> Result<owm_structs::WeatherData, reqwest::Error> {
40 owm::weather::api::get_weather_for_coordinates(latitude, longitude, api_key).await
41 }
42
43 pub async fn get_weather_by_city(
50 city_name: String,
51 api_key: String,
52 ) -> Result<owm_structs::WeatherData, reqwest::Error> {
53 let coordinates: owm::geocoding::structures::Coordinates =
54 owm::geocoding::api::get_coordinates_by_location_name(city_name, api_key.clone())
55 .await?;
56 owm::weather::api::get_weather_for_coordinates(
57 coordinates.get_latitude(),
58 coordinates.get_longitude(),
59 api_key,
60 )
61 .await
62 }
63
64 pub mod blocking {
65 use crate::owm_structs;
66 use tokio::runtime::Runtime;
67
68 fn get_runtime() -> Runtime {
69 tokio::runtime::Builder::new_multi_thread()
70 .enable_all()
71 .build()
72 .expect("Could not build tokio instance.")
73 }
74
75 pub fn get_city_coordinates(
82 city_name: String,
83 api_key: String,
84 ) -> Result<owm_structs::Coordinates, reqwest::Error> {
85 get_runtime().block_on(async move {
86 crate::owm_api::get_city_coordinates(city_name, api_key).await
87 })
88 }
89
90 pub fn get_weather_by_coordinates(
99 latitude: f32,
100 longitude: f32,
101 api_key: String,
102 ) -> Result<owm_structs::WeatherData, reqwest::Error> {
103 get_runtime().block_on(async move {
104 crate::owm_api::get_weather_by_coordinates(latitude, longitude, api_key).await
105 })
106 }
107
108 pub fn get_weather_by_city(
115 city_name: String,
116 api_key: String,
117 ) -> Result<owm_structs::WeatherData, reqwest::Error> {
118 get_runtime().block_on(async move {
119 crate::owm_api::get_weather_by_city(city_name, api_key).await
120 })
121 }
122 }
123}
124
125pub mod owm_utils {
126 pub mod convert {
127 pub use crate::utils::convert::*;
128 }
129}
130
131pub mod prelude {
132 pub use crate::owm_api::*;
134 pub use crate::owm_structs::*;
135 #[cfg(feature = "utils")]
137 pub use crate::owm_utils::*;
138}