forked from mirror/Riven
cleaning up unuseds
parent
ee75f75e0c
commit
2d105529b4
|
@ -1,5 +1,3 @@
|
||||||
#![allow(dead_code)] // TODO REMOVE
|
|
||||||
|
|
||||||
pub mod consts;
|
pub mod consts;
|
||||||
|
|
||||||
mod riot_api_config;
|
mod riot_api_config;
|
||||||
|
@ -16,12 +14,12 @@ mod tests {
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
const api_key: &'static str = "RGAPI-nothinghereowo";
|
const API_KEY: &'static str = "RGAPI-nothinghereowo";
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn it_works() {
|
fn it_works() {
|
||||||
let rt = Runtime::new().unwrap();
|
let rt = Runtime::new().unwrap();
|
||||||
let riot_api = RiotApi::with_key(api_key);
|
let riot_api = RiotApi::with_key(API_KEY);
|
||||||
|
|
||||||
// https://na1.api.riotgames.com/lol/champion-mastery/v4/scores/by-summoner/SBM8Ubipo4ge2yj7bhEzL7yvV0C9Oc1XA2l6v5okGMA_nCw
|
// https://na1.api.riotgames.com/lol/champion-mastery/v4/scores/by-summoner/SBM8Ubipo4ge2yj7bhEzL7yvV0C9Oc1XA2l6v5okGMA_nCw
|
||||||
let my_future = riot_api.get::<u32>("asdf", consts::Region::NA,
|
let my_future = riot_api.get::<u32>("asdf", consts::Region::NA,
|
||||||
|
|
|
@ -19,7 +19,6 @@ pub struct RateLimit {
|
||||||
// Buckets for this rate limit (synchronized).
|
// Buckets for this rate limit (synchronized).
|
||||||
// Almost always read, written only when rate limit rates are updated
|
// Almost always read, written only when rate limit rates are updated
|
||||||
// from API response.
|
// from API response.
|
||||||
// TODO: Question of writer starvation.
|
|
||||||
buckets: RwLock<Vec<VectorTokenBucket>>,
|
buckets: RwLock<Vec<VectorTokenBucket>>,
|
||||||
// Set to when we can retry if a retry-after header is received.
|
// Set to when we can retry if a retry-after header is received.
|
||||||
retry_after: Option<Instant>,
|
retry_after: Option<Instant>,
|
||||||
|
|
|
@ -106,12 +106,6 @@ impl<'a> RegionalRequester<'a> {
|
||||||
panic!("FAILED AFTER {} ATTEMPTS!", attempts);
|
panic!("FAILED AFTER {} ATTEMPTS!", attempts);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get2<T: 'a + serde::de::DeserializeOwned>(&'a self, method_id: &'a str, region: &'a Region<'_>, relative_url: &'a str,
|
|
||||||
query: &'a [(&'a str, &'a str)]) -> impl Future<Output = Result<Option<T>, reqwest::Error>> + 'a
|
|
||||||
{
|
|
||||||
self.get(method_id, region, relative_url, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_none_status_code(status: &StatusCode) -> bool {
|
fn is_none_status_code(status: &StatusCode) -> bool {
|
||||||
Self::NONE_STATUS_CODES.contains(&status.as_u16())
|
Self::NONE_STATUS_CODES.contains(&status.as_u16())
|
||||||
}
|
}
|
||||||
|
@ -120,9 +114,4 @@ impl<'a> RegionalRequester<'a> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn send_sync() {
|
|
||||||
fn is_send_sync<T: Send + Sync>() {}
|
|
||||||
is_send_sync::<RegionalRequester>();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ pub struct RequesterManager<'a> {
|
||||||
|
|
||||||
impl<'a> RequesterManager<'a> {
|
impl<'a> RequesterManager<'a> {
|
||||||
pub fn new(riot_api_config: RiotApiConfig<'a>) -> Self {
|
pub fn new(riot_api_config: RiotApiConfig<'a>) -> Self {
|
||||||
// TODO client.
|
// TODO configure client.
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
Self {
|
Self {
|
||||||
riot_api_config: riot_api_config,
|
riot_api_config: riot_api_config,
|
||||||
|
@ -34,7 +34,7 @@ impl<'a> RequesterManager<'a> {
|
||||||
&'a self, method_id: &'a str, region: &'a Region<'a>, relative_url: &'_ str,
|
&'a self, method_id: &'a str, region: &'a Region<'a>, relative_url: &'_ str,
|
||||||
query: &[(&'_ str, &'_ str)]) -> Result<Option<T>, reqwest::Error>
|
query: &[(&'_ str, &'_ str)]) -> Result<Option<T>, reqwest::Error>
|
||||||
{
|
{
|
||||||
// TODO: max concurrent requests?
|
// TODO: max concurrent requests? Or can configure client?
|
||||||
let regional_requester = self.regional_requesters
|
let regional_requester = self.regional_requesters
|
||||||
.get_or_insert_with(region, || RegionalRequester::new(&self.riot_api_config, &self.client));
|
.get_or_insert_with(region, || RegionalRequester::new(&self.riot_api_config, &self.client));
|
||||||
regional_requester.get(method_id, region, relative_url, query).await
|
regional_requester.get(method_id, region, relative_url, query).await
|
||||||
|
|
|
@ -97,13 +97,8 @@ impl TokenBucket for VectorTokenBucket {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn send_sync() {
|
// #[test]
|
||||||
fn is_send_sync<T: Send + Sync>() {}
|
// fn it_works() {
|
||||||
is_send_sync::<VectorTokenBucket>();
|
// assert_eq!(2 + 2, 4);
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn it_works() {
|
|
||||||
assert_eq!(2 + 2, 4);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,14 +17,14 @@ impl<K: Hash + Eq, V> InsertOnlyCHashMap<K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
// #[inline]
|
||||||
pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<Arc<V>>
|
// pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<Arc<V>>
|
||||||
where
|
// where
|
||||||
K: Borrow<Q>,
|
// K: Borrow<Q>,
|
||||||
Q: Hash + Eq,
|
// Q: Hash + Eq,
|
||||||
{
|
// {
|
||||||
self.base.lock().get(key).map(|v| Arc::clone(v))
|
// self.base.lock().get(key).map(|v| Arc::clone(v))
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_or_insert_with<F: FnOnce() -> V>(&self, key: K, default: F) -> Arc<V>
|
pub fn get_or_insert_with<F: FnOnce() -> V>(&self, key: K, default: F) -> Arc<V>
|
||||||
|
|
Loading…
Reference in New Issue