forked from mirror/Riven
1
0
Fork 0
Riven/src/riot_api.rs

30 lines
822 B
Rust
Raw Normal View History

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
}
}