1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use serde::de::DeserializeOwned;
use std::{collections::HashMap, future::Future};

#[cfg(feature = "reqwest-http-client")]
mod reqwest;
#[cfg(feature = "reqwest-http-client")]
pub use reqwest::{ReqwestHttpAsyncClient, ReqwestHttpAsyncClientConfiguration};

pub static GEO_API_URL: &str = "https://geoapi.qweather.com";
pub static WEATHER_API_URL: &str = "https://api.qweather.com";
pub static WEATHER_DEV_API_URL: &str = "https://devapi.qweather.com";

#[derive(Debug, Clone, Default)]
pub enum Api {
    Geo,
    #[default]
    Weather,
}

#[derive(Debug, Clone, Default)]
pub struct HttpRequest {
    pub api: Api,
    pub path: String,
    pub query: HashMap<String, String>,
}

pub trait AsyncHttpClient {
    type Error;
    fn get<T: DeserializeOwned>(
        &self,
        req: HttpRequest,
    ) -> impl Future<Output = Result<T, Self::Error>> + Send;
}