2019-10-19 21:39:53 +00:00
|
|
|
use crate::*;
|
2019-10-17 23:00:04 +00:00
|
|
|
use crate::consts::Region;
|
|
|
|
use crate::req::RequesterManager;
|
|
|
|
|
|
|
|
pub struct RiotApi<'a> {
|
2019-10-19 21:39:53 +00:00
|
|
|
pub requester_manager: RequesterManager<'a>,
|
|
|
|
_private: (),
|
2019-10-17 23:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> RiotApi<'a> {
|
|
|
|
pub fn with_config(config: RiotApiConfig<'a>) -> Self {
|
2019-10-19 21:39:53 +00:00
|
|
|
let req_man = RequesterManager::new(config);
|
2019-10-17 23:00:04 +00:00
|
|
|
Self {
|
2019-10-19 21:39:53 +00:00
|
|
|
requester_manager: req_man,
|
|
|
|
_private: (),
|
2019-10-17 23:00:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_key(api_key: &'a str) -> Self {
|
|
|
|
Self::with_config(RiotApiConfig::with_key(api_key))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn get<T: serde::de::DeserializeOwned>(
|
2019-10-19 21:39:53 +00:00
|
|
|
&'a self, method_id: &'a str, region: Region, path: &str,
|
|
|
|
query: Option<&str>) -> Result<Option<T>, reqwest::Error>
|
2019-10-17 23:00:04 +00:00
|
|
|
{
|
2019-10-19 21:39:53 +00:00
|
|
|
self.requester_manager.get(method_id, region, path, query).await
|
2019-10-17 23:00:04 +00:00
|
|
|
}
|
|
|
|
}
|