Convert CRLF to LF

This commit is contained in:
Mingwei Samuel 2021-06-30 16:34:34 -07:00
parent 2989c4483e
commit 6307a0aa13
42 changed files with 4178 additions and 4178 deletions

12
LICENSE
View file

@ -1,7 +1,7 @@
Copyright 2019 Mingwei Samuel Copyright 2019 Mingwei Samuel
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

284
README.md
View file

@ -1,142 +1,142 @@
<h1 align="center"> <h1 align="center">
Riven<br> Riven<br>
</h1> </h1>
<p align="center"> <p align="center">
<a href="https://github.com/MingweiSamuel/Riven/"><img src="https://cdn.communitydragon.org/latest/champion/Riven/square" width="20" height="20" alt="Riven Github"></a> <a href="https://github.com/MingweiSamuel/Riven/"><img src="https://cdn.communitydragon.org/latest/champion/Riven/square" width="20" height="20" alt="Riven Github"></a>
<a href="https://crates.io/crates/riven"><img src="https://img.shields.io/crates/v/riven?style=flat-square&logo=rust" alt="Crates.io"></a> <a href="https://crates.io/crates/riven"><img src="https://img.shields.io/crates/v/riven?style=flat-square&logo=rust" alt="Crates.io"></a>
<a href="https://docs.rs/riven/"><img src="https://img.shields.io/badge/docs.rs-Riven-blue?style=flat-square&logo=read-the-docs&logoColor=white" alt="Docs.rs"></a> <a href="https://docs.rs/riven/"><img src="https://img.shields.io/badge/docs.rs-Riven-blue?style=flat-square&logo=read-the-docs&logoColor=white" alt="Docs.rs"></a>
<a href="https://travis-ci.com/MingweiSamuel/Riven"><img src="https://img.shields.io/travis/com/mingweisamuel/riven?style=flat-square" alt="Travis CI"></a> <a href="https://travis-ci.com/MingweiSamuel/Riven"><img src="https://img.shields.io/travis/com/mingweisamuel/riven?style=flat-square" alt="Travis CI"></a>
<a href="https://github.com/rust-secure-code/safety-dance/"><img src="https://img.shields.io/badge/unsafe-forbidden-green.svg?style=flat-square" alt="unsafe forbidden"></a> <a href="https://github.com/rust-secure-code/safety-dance/"><img src="https://img.shields.io/badge/unsafe-forbidden-green.svg?style=flat-square" alt="unsafe forbidden"></a>
</p> </p>
Rust Library for the [Riot Games API](https://developer.riotgames.com/). Rust Library for the [Riot Games API](https://developer.riotgames.com/).
Riven's goals are _speed_, _reliability_, and _maintainability_. Riven handles rate limits and large requests with ease. Riven's goals are _speed_, _reliability_, and _maintainability_. Riven handles rate limits and large requests with ease.
Data structs and endpoints are automatically generated from the Data structs and endpoints are automatically generated from the
[Riot API Reference](https://developer.riotgames.com/api-methods/) ([Swagger](http://www.mingweisamuel.com/riotapi-schema/tool/)). [Riot API Reference](https://developer.riotgames.com/api-methods/) ([Swagger](http://www.mingweisamuel.com/riotapi-schema/tool/)).
## Design ## Design
* Fast, asynchronous, thread-safe. * Fast, asynchronous, thread-safe.
* Automatically retries failed requests. * Automatically retries failed requests.
* TFT API Support. * TFT API Support.
## Usage ## Usage
```rust ```rust
use riven::RiotApi; use riven::RiotApi;
use riven::consts::PlatformRoute; use riven::consts::PlatformRoute;
// Enter tokio async runtime. // Enter tokio async runtime.
let mut rt = tokio::runtime::Runtime::new().unwrap(); let mut rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async { rt.block_on(async {
// Create RiotApi instance from key string. // Create RiotApi instance from key string.
let api_key = "RGAPI-01234567-89ab-cdef-0123-456789abcdef"; let api_key = "RGAPI-01234567-89ab-cdef-0123-456789abcdef";
# /* (doc testing) */ let api_key = std::env!("RGAPI_KEY"); # /* (doc testing) */ let api_key = std::env!("RGAPI_KEY");
let riot_api = RiotApi::with_key(api_key); let riot_api = RiotApi::with_key(api_key);
// Get summoner data. // Get summoner data.
let summoner = riot_api.summoner_v4() let summoner = riot_api.summoner_v4()
.get_by_summoner_name(PlatformRoute::NA1, "잘 못").await .get_by_summoner_name(PlatformRoute::NA1, "잘 못").await
.expect("Get summoner failed.") .expect("Get summoner failed.")
.expect("There is no summoner with that name."); .expect("There is no summoner with that name.");
// Print summoner name. // Print summoner name.
println!("{} Champion Masteries:", summoner.name); println!("{} Champion Masteries:", summoner.name);
// Get champion mastery data. // Get champion mastery data.
let masteries = riot_api.champion_mastery_v4() let masteries = riot_api.champion_mastery_v4()
.get_all_champion_masteries(PlatformRoute::NA1, &summoner.id).await .get_all_champion_masteries(PlatformRoute::NA1, &summoner.id).await
.expect("Get champion masteries failed."); .expect("Get champion masteries failed.");
// Print champioon masteries. // Print champioon masteries.
for (i, mastery) in masteries.iter().take(10).enumerate() { for (i, mastery) in masteries.iter().take(10).enumerate() {
println!("{: >2}) {: <9} {: >7} ({})", i + 1, println!("{: >2}) {: <9} {: >7} ({})", i + 1,
mastery.champion_id.to_string(), mastery.champion_id.to_string(),
mastery.champion_points, mastery.champion_level); mastery.champion_points, mastery.champion_level);
} }
}); });
``` ```
Output: Output:
```text ```text
잘 못 Champion Masteries: 잘 못 Champion Masteries:
1) Riven 1219895 (7) 1) Riven 1219895 (7)
2) Fiora 229714 (5) 2) Fiora 229714 (5)
3) Katarina 175985 (5) 3) Katarina 175985 (5)
4) Lee Sin 150546 (7) 4) Lee Sin 150546 (7)
5) Jax 100509 (5) 5) Jax 100509 (5)
6) Gnar 76373 (6) 6) Gnar 76373 (6)
7) Kai'Sa 64271 (5) 7) Kai'Sa 64271 (5)
8) Caitlyn 46479 (5) 8) Caitlyn 46479 (5)
9) Irelia 46465 (5) 9) Irelia 46465 (5)
10) Vladimir 37176 (5) 10) Vladimir 37176 (5)
``` ```
### Nightly vs Stable ### Nightly vs Stable
Enable the `nightly` feature to use nightly-only functionality. Mainly enables Enable the `nightly` feature to use nightly-only functionality. Mainly enables
[nightly optimizations in the `parking_lot` crate](https://github.com/Amanieu/parking_lot#nightly-vs-stable). [nightly optimizations in the `parking_lot` crate](https://github.com/Amanieu/parking_lot#nightly-vs-stable).
Also required for running async integration tests. Also required for running async integration tests.
### Docs ### Docs
[On docs.rs](https://docs.rs/riven/). [On docs.rs](https://docs.rs/riven/).
### Error Handling ### Error Handling
Riven returns either `Result<T>` or `Result<Option<T>>` within futures. Riven returns either `Result<T>` or `Result<Option<T>>` within futures.
If the `Result` is errored, this indicates that the API request failed to If the `Result` is errored, this indicates that the API request failed to
complete successfully, which may be due to bad user input, Riot server errors, complete successfully, which may be due to bad user input, Riot server errors,
incorrect API key, etc. incorrect API key, etc.
If the `Option` is `None`, this indicates that the request completed If the `Option` is `None`, this indicates that the request completed
successfully but no data was returned. This happens in several situations, such successfully but no data was returned. This happens in several situations, such
as getting a summoner (by name) or match (by id) that doesn't exist, or getting as getting a summoner (by name) or match (by id) that doesn't exist, or getting
spectator data for a summoner who is not in-game. spectator data for a summoner who is not in-game.
Specifically, the API returned a 404 HTTP status code in this situation. Specifically, the API returned a 404 HTTP status code in this situation.
The error type used by Riven is `riven::RiotApiError`. It provides some basic The error type used by Riven is `riven::RiotApiError`. It provides some basic
diagnostic information, such as the source Reqwest error, the number of retries diagnostic information, such as the source Reqwest error, the number of retries
attempted, and the Reqwest `Response` object. attempted, and the Reqwest `Response` object.
You can configure the number of time Riven retries using You can configure the number of time Riven retries using
`RiotApiConfig::set_retries(...)` and the `RiotApi::with_config(config)` `RiotApiConfig::set_retries(...)` and the `RiotApi::with_config(config)`
constructor. By default, Riven retries up to 3 times (4 requests total). constructor. By default, Riven retries up to 3 times (4 requests total).
Some errors, such as 400 client errors, are not retried as they would Some errors, such as 400 client errors, are not retried as they would
inevitably fail again. inevitably fail again.
### Semantic Versioning ### Semantic Versioning
This package follows semantic versioning to an extent. However, the Riot API This package follows semantic versioning to an extent. However, the Riot API
itself changes often and does not follow semantic versioning, which makes itself changes often and does not follow semantic versioning, which makes
things difficult. Out-of-date versions will slowly partially cease to work due things difficult. Out-of-date versions will slowly partially cease to work due
to this. to this.
When the API changes, this may result in breaking changes in the `models` When the API changes, this may result in breaking changes in the `models`
module, `endpoints` module, and some of the `consts` module. "Handle accessor" module, `endpoints` module, and some of the `consts` module. "Handle accessor"
methods may be removed from `RiotApi` if the corresponding endpoint is removed methods may be removed from `RiotApi` if the corresponding endpoint is removed
from the Riot API. These breaking changes will increment the **MINOR** version, from the Riot API. These breaking changes will increment the **MINOR** version,
not the major version. not the major version.
Parts of Riven that do not depend on Riot API changes do follow semantic Parts of Riven that do not depend on Riot API changes do follow semantic
versioning. versioning.
### Additional Help ### Additional Help
Feel free to [make an issue](https://github.com/MingweiSamuel/Riven/issues/new) Feel free to [make an issue](https://github.com/MingweiSamuel/Riven/issues/new)
if you are have any questions or trouble with Riven. if you are have any questions or trouble with Riven.
## Development ## Development
NodeJS is used to generate code for Riven. The NodeJS is used to generate code for Riven. The
[`srcgen/`](https://github.com/MingweiSamuel/Riven/tree/master/srcgen) [`srcgen/`](https://github.com/MingweiSamuel/Riven/tree/master/srcgen)
folder contains the code and [doT.js](https://olado.github.io/doT/index.html) folder contains the code and [doT.js](https://olado.github.io/doT/index.html)
templates. `index.js` lists the JSON files downloaded and used to generate the templates. `index.js` lists the JSON files downloaded and used to generate the
code. code.
To set up the srcgen, you will first need to install NodeJS. Then enter the To set up the srcgen, you will first need to install NodeJS. Then enter the
srcgen folder and run `npm ci` (or `npm install`) to install dependencies. srcgen folder and run `npm ci` (or `npm install`) to install dependencies.
To run the srcgen use `node srcgen` from the main folder. To run the srcgen use `node srcgen` from the main folder.

View file

@ -1,213 +1,213 @@
//! Configuration of RiotApi. //! Configuration of RiotApi.
use std::time::Duration; use std::time::Duration;
use reqwest::ClientBuilder; use reqwest::ClientBuilder;
use reqwest::header::{ HeaderMap, HeaderValue }; use reqwest::header::{ HeaderMap, HeaderValue };
/// Configuration for instantiating RiotApi. /// Configuration for instantiating RiotApi.
/// ///
/// ///
#[derive(Debug)] #[derive(Debug)]
pub struct RiotApiConfig { pub struct RiotApiConfig {
pub(crate) base_url: String, pub(crate) base_url: String,
pub(crate) retries: u8, pub(crate) retries: u8,
pub(crate) burst_pct: f32, pub(crate) burst_pct: f32,
pub(crate) duration_overhead: Duration, pub(crate) duration_overhead: Duration,
pub(crate) client_builder: Option<ClientBuilder>, pub(crate) client_builder: Option<ClientBuilder>,
} }
impl RiotApiConfig { impl RiotApiConfig {
/// Request header name for the Riot API key. /// Request header name for the Riot API key.
/// ///
/// When using `set_client_builder`, the supplied builder should include /// When using `set_client_builder`, the supplied builder should include
/// this default header with the Riot API key as the value. /// this default header with the Riot API key as the value.
const RIOT_KEY_HEADER: &'static str = "X-Riot-Token"; const RIOT_KEY_HEADER: &'static str = "X-Riot-Token";
/// `"https://{}.api.riotgames.com"` /// `"https://{}.api.riotgames.com"`
/// ///
/// Default base URL, including `{}` placeholder for region platform. /// Default base URL, including `{}` placeholder for region platform.
pub const DEFAULT_BASE_URL: &'static str = "https://{}.api.riotgames.com"; pub const DEFAULT_BASE_URL: &'static str = "https://{}.api.riotgames.com";
/// `3` /// `3`
/// ///
/// Default number of retries. /// Default number of retries.
pub const DEFAULT_RETRIES: u8 = 3; pub const DEFAULT_RETRIES: u8 = 3;
/// `0.99` /// `0.99`
/// ///
/// Default `burst_pct`, also used by `preconfig_burst`. /// Default `burst_pct`, also used by `preconfig_burst`.
pub const PRECONFIG_BURST_BURST_PCT: f32 = 0.99; pub const PRECONFIG_BURST_BURST_PCT: f32 = 0.99;
/// `989` ms /// `989` ms
/// ///
/// Default `duration_overhead`, also used by `preconfig_burst`. /// Default `duration_overhead`, also used by `preconfig_burst`.
pub const PRECONFIG_BURST_DURATION_OVERHEAD: Duration = Duration::from_millis(989); pub const PRECONFIG_BURST_DURATION_OVERHEAD: Duration = Duration::from_millis(989);
/// `0.47` /// `0.47`
/// ///
/// `burst_pct` used by `preconfig_throughput`. /// `burst_pct` used by `preconfig_throughput`.
pub const PRECONFIG_THROUGHPUT_BURST_PCT: f32 = 0.47; pub const PRECONFIG_THROUGHPUT_BURST_PCT: f32 = 0.47;
/// `10` ms. /// `10` ms.
/// ///
/// `duration_overhead` used by `preconfig_throughput`. /// `duration_overhead` used by `preconfig_throughput`.
pub const PRECONFIG_THROUGHPUT_DURATION_OVERHEAD: Duration = Duration::from_millis(10); pub const PRECONFIG_THROUGHPUT_DURATION_OVERHEAD: Duration = Duration::from_millis(10);
/// Creates a new `RiotApiConfig` with the given `api_key` with the following /// Creates a new `RiotApiConfig` with the given `api_key` with the following
/// configuration: /// configuration:
/// ///
/// * `retries = 3` (`RiotApiConfig::DEFAULT_RETRIES`). /// * `retries = 3` (`RiotApiConfig::DEFAULT_RETRIES`).
/// * `purst_pct = 0.99` (`preconfig_burst`). /// * `purst_pct = 0.99` (`preconfig_burst`).
/// * `duration_overhead = 989 ms` (`preconfig_burst`). /// * `duration_overhead = 989 ms` (`preconfig_burst`).
/// ///
/// `api_key` should be a Riot Games API key from /// `api_key` should be a Riot Games API key from
/// [https://developer.riotgames.com/](https://developer.riotgames.com/), /// [https://developer.riotgames.com/](https://developer.riotgames.com/),
/// and should look like `"RGAPI-01234567-89ab-cdef-0123-456789abcdef"`. /// and should look like `"RGAPI-01234567-89ab-cdef-0123-456789abcdef"`.
pub fn with_key(api_key: impl AsRef<[u8]>) -> Self { pub fn with_key(api_key: impl AsRef<[u8]>) -> Self {
let mut default_headers = HeaderMap::new(); let mut default_headers = HeaderMap::new();
default_headers.insert( default_headers.insert(
Self::RIOT_KEY_HEADER, Self::RIOT_KEY_HEADER,
HeaderValue::from_bytes(api_key.as_ref()).unwrap() HeaderValue::from_bytes(api_key.as_ref()).unwrap()
); );
Self { Self {
base_url: Self::DEFAULT_BASE_URL.into(), base_url: Self::DEFAULT_BASE_URL.into(),
retries: Self::DEFAULT_RETRIES, retries: Self::DEFAULT_RETRIES,
burst_pct: Self::PRECONFIG_BURST_BURST_PCT, burst_pct: Self::PRECONFIG_BURST_BURST_PCT,
duration_overhead: Self::PRECONFIG_BURST_DURATION_OVERHEAD, duration_overhead: Self::PRECONFIG_BURST_DURATION_OVERHEAD,
client_builder: Some( client_builder: Some(
ClientBuilder::new() ClientBuilder::new()
.default_headers(default_headers) .default_headers(default_headers)
), ),
} }
} }
/// Creates a new `RiotApiConfig` with the given client builder. /// Creates a new `RiotApiConfig` with the given client builder.
/// ///
/// The client builder default headers should include a value for /// The client builder default headers should include a value for
/// `RiotApiConfig::RIOT_KEY_HEADER`, otherwise authentication will fail. /// `RiotApiConfig::RIOT_KEY_HEADER`, otherwise authentication will fail.
/// ///
/// * `retries = 3` (`RiotApiConfig::DEFAULT_RETRIES`). /// * `retries = 3` (`RiotApiConfig::DEFAULT_RETRIES`).
/// * `purst_pct = 0.99` (`preconfig_burst`). /// * `purst_pct = 0.99` (`preconfig_burst`).
/// * `duration_overhead = 989 ms` (`preconfig_burst`). /// * `duration_overhead = 989 ms` (`preconfig_burst`).
pub fn with_client_builder(client_builder: ClientBuilder) -> Self { pub fn with_client_builder(client_builder: ClientBuilder) -> Self {
Self { Self {
base_url: Self::DEFAULT_BASE_URL.to_owned(), base_url: Self::DEFAULT_BASE_URL.to_owned(),
retries: Self::DEFAULT_RETRIES, retries: Self::DEFAULT_RETRIES,
burst_pct: Self::PRECONFIG_BURST_BURST_PCT, burst_pct: Self::PRECONFIG_BURST_BURST_PCT,
duration_overhead: Self::PRECONFIG_BURST_DURATION_OVERHEAD, duration_overhead: Self::PRECONFIG_BURST_DURATION_OVERHEAD,
client_builder: Some(client_builder), client_builder: Some(client_builder),
} }
} }
/// Sets rate limiting settings to preconfigured values optimized for burst, /// Sets rate limiting settings to preconfigured values optimized for burst,
/// low latency: /// low latency:
/// ///
/// * `burst_pct = 0.99` (`PRECONFIG_BURST_BURST_PCT`). /// * `burst_pct = 0.99` (`PRECONFIG_BURST_BURST_PCT`).
/// * `duration_overhead = 989 ms` (`PRECONFIG_BURST_DURATION_OVERHEAD_MILLIS`). /// * `duration_overhead = 989 ms` (`PRECONFIG_BURST_DURATION_OVERHEAD_MILLIS`).
/// ///
/// # Returns /// # Returns
/// `self`, for chaining. /// `self`, for chaining.
pub fn preconfig_burst(mut self) -> Self { pub fn preconfig_burst(mut self) -> Self {
self.burst_pct = Self::PRECONFIG_BURST_BURST_PCT; self.burst_pct = Self::PRECONFIG_BURST_BURST_PCT;
self.duration_overhead = Self::PRECONFIG_BURST_DURATION_OVERHEAD; self.duration_overhead = Self::PRECONFIG_BURST_DURATION_OVERHEAD;
self self
} }
/// Sets the rate limiting settings to preconfigured values optimized for /// Sets the rate limiting settings to preconfigured values optimized for
/// high throughput: /// high throughput:
/// ///
/// * `burst_pct = 0.47` (`PRECONFIG_THROUGHPUT_BURST_PCT`). /// * `burst_pct = 0.47` (`PRECONFIG_THROUGHPUT_BURST_PCT`).
/// * `duration_overhead = 10 ms` (`PRECONFIG_THROUGHPUT_DURATION_OVERHEAD_MILLIS`). /// * `duration_overhead = 10 ms` (`PRECONFIG_THROUGHPUT_DURATION_OVERHEAD_MILLIS`).
/// ///
/// # Returns /// # Returns
/// `self`, for chaining. /// `self`, for chaining.
pub fn preconfig_throughput(mut self) -> Self { pub fn preconfig_throughput(mut self) -> Self {
self.burst_pct = Self::PRECONFIG_THROUGHPUT_BURST_PCT; self.burst_pct = Self::PRECONFIG_THROUGHPUT_BURST_PCT;
self.duration_overhead = Self::PRECONFIG_THROUGHPUT_DURATION_OVERHEAD; self.duration_overhead = Self::PRECONFIG_THROUGHPUT_DURATION_OVERHEAD;
self self
} }
/// Set the base url for requests. The string should contain a `"{}"` /// Set the base url for requests. The string should contain a `"{}"`
/// literal which will be replaced with the region platform name. (However /// literal which will be replaced with the region platform name. (However
/// multiple or zero `"{}"`s may be included if needed). /// multiple or zero `"{}"`s may be included if needed).
/// ///
/// # Returns /// # Returns
/// `self`, for chaining. /// `self`, for chaining.
pub fn set_base_url(mut self, base_url: impl Into<String>) -> Self { pub fn set_base_url(mut self, base_url: impl Into<String>) -> Self {
self.base_url = base_url.into(); self.base_url = base_url.into();
self self
} }
/// Set number of times to retry requests. Naturally, only retryable requests /// Set number of times to retry requests. Naturally, only retryable requests
/// will be retried: responses with status codes 5xx or 429 (after waiting /// will be retried: responses with status codes 5xx or 429 (after waiting
/// for retry-after headers). A value of `0` means one request will be sent /// for retry-after headers). A value of `0` means one request will be sent
/// and it will not be retried if it fails. /// and it will not be retried if it fails.
/// ///
/// # Returns /// # Returns
/// `self`, for chaining. /// `self`, for chaining.
pub fn set_retries(mut self, retries: u8) -> Self { pub fn set_retries(mut self, retries: u8) -> Self {
self.retries = retries; self.retries = retries;
self self
} }
/// Burst percentage controls how many burst requests are allowed and /// Burst percentage controls how many burst requests are allowed and
/// therefore how requests are spread out. Higher equals more burst, /// therefore how requests are spread out. Higher equals more burst,
/// less spread. Lower equals less burst, more spread. /// less spread. Lower equals less burst, more spread.
/// ///
/// The value must be in the range (0, 1]; /// The value must be in the range (0, 1];
/// Between 0, exclusive, and 1, inclusive. However values should generally /// Between 0, exclusive, and 1, inclusive. However values should generally
/// be larger than 0.25. /// be larger than 0.25.
/// ///
/// Burst percentage behaves as follows:<br> /// Burst percentage behaves as follows:<br>
/// A burst percentage of x% means, for each token bucket, "x% of the /// A burst percentage of x% means, for each token bucket, "x% of the
/// tokens can be used in x% of the bucket duration." So, for example, if x /// tokens can be used in x% of the bucket duration." So, for example, if x
/// is 90%, a bucket would allow 90% of the requests to be made without /// is 90%, a bucket would allow 90% of the requests to be made without
/// any delay. Then, after waiting 90% of the bucket's duration, the /// any delay. Then, after waiting 90% of the bucket's duration, the
/// remaining 10% of requests could be made. /// remaining 10% of requests could be made.
/// ///
/// A burst percentage of 100% results in no request spreading, which would /// A burst percentage of 100% results in no request spreading, which would
/// allow for the largest bursts and lowest latency, but could result in /// allow for the largest bursts and lowest latency, but could result in
/// 429s as bucket boundaries occur. /// 429s as bucket boundaries occur.
/// ///
/// A burst percentage of near 0% results in high spreading causing /// A burst percentage of near 0% results in high spreading causing
/// temporally equidistant requests. This prevents 429s but has the highest /// temporally equidistant requests. This prevents 429s but has the highest
/// latency. Additionally, if the number of tokens is high, this may lower /// latency. Additionally, if the number of tokens is high, this may lower
/// the overall throughput due to the rate at which requests can be /// the overall throughput due to the rate at which requests can be
/// scheduled. /// scheduled.
/// ///
/// Therefore, for interactive applications like summoner & match history /// Therefore, for interactive applications like summoner & match history
/// lookup, a higher percentage may be better. For data-collection apps /// lookup, a higher percentage may be better. For data-collection apps
/// like champion winrate aggregation, a medium-low percentage may be /// like champion winrate aggregation, a medium-low percentage may be
/// better. /// better.
/// ///
/// # Panics /// # Panics
/// If `burst_pct` is not in range (0, 1]. /// If `burst_pct` is not in range (0, 1].
/// ///
/// # Returns /// # Returns
/// `self`, for chaining. /// `self`, for chaining.
pub fn set_burst_pct(mut self, burst_pct: f32) -> Self { pub fn set_burst_pct(mut self, burst_pct: f32) -> Self {
// Use inverted check to handle NaN. // Use inverted check to handle NaN.
if 0.0 < burst_pct && burst_pct < 1.0 { if 0.0 < burst_pct && burst_pct < 1.0 {
self.burst_pct = burst_pct; self.burst_pct = burst_pct;
return self; return self;
} }
panic!("burst_pct \"{}\" not in range (0, 1].", burst_pct); panic!("burst_pct \"{}\" not in range (0, 1].", burst_pct);
} }
/// Sets the additional bucket duration to consider when rate limiting. /// Sets the additional bucket duration to consider when rate limiting.
/// Increasing this value will decrease the chances of 429s, but will lower /// Increasing this value will decrease the chances of 429s, but will lower
/// the overall throughput. /// the overall throughput.
/// ///
/// In a sense, the `duration_overhead` is how much to "widen" the temporal /// In a sense, the `duration_overhead` is how much to "widen" the temporal
/// width of buckets. /// width of buckets.
/// ///
/// Given a particular Riot Game API rate limit bucket that allows N requests /// Given a particular Riot Game API rate limit bucket that allows N requests
/// per D duration, when counting requests this library will consider requests /// per D duration, when counting requests this library will consider requests
/// sent in the past `D + duration_overhead` duration. /// sent in the past `D + duration_overhead` duration.
/// ///
/// # Returns /// # Returns
/// `self`, for chaining. /// `self`, for chaining.
pub fn set_duration_overhead(mut self, duration_overhead: Duration) -> Self { pub fn set_duration_overhead(mut self, duration_overhead: Duration) -> Self {
self.duration_overhead = duration_overhead; self.duration_overhead = duration_overhead;
self self
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -1,60 +1,60 @@
use std::cmp::Ordering; use std::cmp::Ordering;
use num_enum::{ IntoPrimitive, TryFromPrimitive }; use num_enum::{ IntoPrimitive, TryFromPrimitive };
use strum::IntoEnumIterator; use strum::IntoEnumIterator;
use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr }; use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr };
/// LoL and TFT rank divisions, I, II, III, IV, and (deprecated) V. /// LoL and TFT rank divisions, I, II, III, IV, and (deprecated) V.
/// ///
/// Ordered such that "higher" divisions are greater than "lower" ones: `Division::I > Division::IV`. /// Ordered such that "higher" divisions are greater than "lower" ones: `Division::I > Division::IV`.
/// ///
/// Repr'd as equivalent numeric values, (1, 2, 3, 4, 5). /// Repr'd as equivalent numeric values, (1, 2, 3, 4, 5).
/// ///
/// Implements [IntoEnumIterator](super::IntoEnumIterator). Iterator excludes deprecated `Division::V`. /// Implements [IntoEnumIterator](super::IntoEnumIterator). Iterator excludes deprecated `Division::V`.
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash)] #[derive(Eq, PartialEq, Hash)]
#[derive(EnumString, Display, AsRefStr, IntoStaticStr)] #[derive(EnumString, Display, AsRefStr, IntoStaticStr)]
#[derive(IntoPrimitive, TryFromPrimitive)] #[derive(IntoPrimitive, TryFromPrimitive)]
#[repr(u8)] #[repr(u8)]
pub enum Division { pub enum Division {
I = 1, I = 1,
II = 2, II = 2,
III = 3, III = 3,
IV = 4, IV = 4,
#[deprecated(note="Removed for 2019.")] #[deprecated(note="Removed for 2019.")]
V = 5, V = 5,
} }
serde_string!(Division); serde_string!(Division);
/// Returns a DoubleEndedIterator of I, II, III, IV. /// Returns a DoubleEndedIterator of I, II, III, IV.
/// Ordered from high rank (I) to low (IV). /// Ordered from high rank (I) to low (IV).
/// Excludes V, which is deprecated. /// Excludes V, which is deprecated.
impl IntoEnumIterator for Division { impl IntoEnumIterator for Division {
type Iterator = std::iter::Copied<std::slice::Iter<'static, Self>>; type Iterator = std::iter::Copied<std::slice::Iter<'static, Self>>;
fn iter() -> Self::Iterator { fn iter() -> Self::Iterator {
[ Self::I, Self::II, Self::III, Self::IV ].iter().copied() [ Self::I, Self::II, Self::III, Self::IV ].iter().copied()
} }
} }
impl Ord for Division { impl Ord for Division {
fn cmp(&self, other: &Self) -> Ordering { fn cmp(&self, other: &Self) -> Ordering {
u8::from(*self).cmp(&u8::from(*other)).reverse() u8::from(*self).cmp(&u8::from(*other)).reverse()
} }
} }
impl PartialOrd for Division { impl PartialOrd for Division {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other)) Some(self.cmp(other))
} }
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
#[test] #[test]
fn sort() { fn sort() {
assert!(Division::IV < Division::I); assert!(Division::IV < Division::I);
} }
} }

View file

@ -1,65 +1,65 @@
/////////////////////////////////////////////// ///////////////////////////////////////////////
// // // //
// ! // // ! //
// This file is automatically generated! // // This file is automatically generated! //
// Do not directly edit! // // Do not directly edit! //
// // // //
/////////////////////////////////////////////// ///////////////////////////////////////////////
use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr }; use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr };
/// League of Legends game mode, such as Classic, /// League of Legends game mode, such as Classic,
/// ARAM, URF, One For All, Ascension, etc. /// ARAM, URF, One For All, Ascension, etc.
#[non_exhaustive] #[non_exhaustive]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash)] #[derive(Eq, PartialEq, Hash)]
#[derive(EnumString, Display, AsRefStr, IntoStaticStr)] #[derive(EnumString, Display, AsRefStr, IntoStaticStr)]
#[repr(u8)] #[repr(u8)]
pub enum GameMode { pub enum GameMode {
/// ARAM games /// ARAM games
ARAM, ARAM,
/// All Random Summoner's Rift games /// All Random Summoner's Rift games
ARSR, ARSR,
/// Ascension games /// Ascension games
ASCENSION, ASCENSION,
/// Blood Hunt Assassin games /// Blood Hunt Assassin games
ASSASSINATE, ASSASSINATE,
/// Classic Summoner's Rift and Twisted Treeline games /// Classic Summoner's Rift and Twisted Treeline games
CLASSIC, CLASSIC,
/// Dark Star: Singularity games /// Dark Star: Singularity games
DARKSTAR, DARKSTAR,
/// Doom Bot games /// Doom Bot games
DOOMBOTSTEEMO, DOOMBOTSTEEMO,
/// Snowdown Showdown games /// Snowdown Showdown games
FIRSTBLOOD, FIRSTBLOOD,
/// Nexus Blitz games, deprecated in patch 9.2 in favor of gameMode NEXUSBLITZ. /// Nexus Blitz games, deprecated in patch 9.2 in favor of gameMode NEXUSBLITZ.
GAMEMODEX, GAMEMODEX,
/// Legend of the Poro King games /// Legend of the Poro King games
KINGPORO, KINGPORO,
/// Nexus Blitz games. /// Nexus Blitz games.
NEXUSBLITZ, NEXUSBLITZ,
/// Dominion/Crystal Scar games /// Dominion/Crystal Scar games
ODIN, ODIN,
/// Odyssey: Extraction games /// Odyssey: Extraction games
ODYSSEY, ODYSSEY,
/// One for All games /// One for All games
ONEFORALL, ONEFORALL,
/// PROJECT: Hunters games /// PROJECT: Hunters games
PROJECT, PROJECT,
/// Nexus Siege games /// Nexus Siege games
SIEGE, SIEGE,
/// Star Guardian Invasion games /// Star Guardian Invasion games
STARGUARDIAN, STARGUARDIAN,
/// Tutorial games /// Tutorial games
TUTORIAL, TUTORIAL,
/// Tutorial: Welcome to League. /// Tutorial: Welcome to League.
TUTORIAL_MODULE_1, TUTORIAL_MODULE_1,
/// Tutorial: Power Up. /// Tutorial: Power Up.
TUTORIAL_MODULE_2, TUTORIAL_MODULE_2,
/// Tutorial: Shop for Gear. /// Tutorial: Shop for Gear.
TUTORIAL_MODULE_3, TUTORIAL_MODULE_3,
/// URF games /// URF games
URF, URF,
} }
serde_string!(GameMode); serde_string!(GameMode);

View file

@ -1,25 +1,25 @@
/////////////////////////////////////////////// ///////////////////////////////////////////////
// // // //
// ! // // ! //
// This file is automatically generated! // // This file is automatically generated! //
// Do not directly edit! // // Do not directly edit! //
// // // //
/////////////////////////////////////////////// ///////////////////////////////////////////////
use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr }; use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr };
/// League of Legends game type: matched game, custom game, or tutorial game. /// League of Legends game type: matched game, custom game, or tutorial game.
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash)] #[derive(Eq, PartialEq, Hash)]
#[derive(EnumString, Display, AsRefStr, IntoStaticStr)] #[derive(EnumString, Display, AsRefStr, IntoStaticStr)]
#[repr(u8)] #[repr(u8)]
pub enum GameType { pub enum GameType {
/// Custom games /// Custom games
CUSTOM_GAME, CUSTOM_GAME,
/// all other games /// all other games
MATCHED_GAME, MATCHED_GAME,
/// Tutorial games /// Tutorial games
TUTORIAL_GAME, TUTORIAL_GAME,
} }
serde_string!(GameType); serde_string!(GameType);

View file

@ -1,23 +1,23 @@
#![macro_use] #![macro_use]
macro_rules! serde_string { macro_rules! serde_string {
( $x:ty ) => { ( $x:ty ) => {
impl<'de> serde::de::Deserialize<'de> for $x impl<'de> serde::de::Deserialize<'de> for $x
{ {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where where
D: serde::de::Deserializer<'de> D: serde::de::Deserializer<'de>
{ {
let s = String::deserialize(deserializer)?; let s = String::deserialize(deserializer)?;
s.parse().map_err(serde::de::Error::custom) s.parse().map_err(serde::de::Error::custom)
} }
} }
impl serde::ser::Serialize for $x { impl serde::ser::Serialize for $x {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where where
S: serde::ser::Serializer, S: serde::ser::Serializer,
{ {
serializer.serialize_str(self.as_ref()) serializer.serialize_str(self.as_ref())
} }
} }
}; };
} }

View file

@ -1,65 +1,65 @@
/////////////////////////////////////////////// ///////////////////////////////////////////////
// // // //
// ! // // ! //
// This file is automatically generated! // // This file is automatically generated! //
// Do not directly edit! // // Do not directly edit! //
// // // //
/////////////////////////////////////////////// ///////////////////////////////////////////////
use serde_repr::{ Serialize_repr, Deserialize_repr }; use serde_repr::{ Serialize_repr, Deserialize_repr };
use num_enum::{ IntoPrimitive, TryFromPrimitive }; use num_enum::{ IntoPrimitive, TryFromPrimitive };
/// League of Legends maps. /// League of Legends maps.
#[non_exhaustive] #[non_exhaustive]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash, PartialOrd, Ord)] #[derive(Eq, PartialEq, Hash, PartialOrd, Ord)]
#[derive(Serialize_repr, Deserialize_repr)] #[derive(Serialize_repr, Deserialize_repr)]
#[derive(IntoPrimitive, TryFromPrimitive)] #[derive(IntoPrimitive, TryFromPrimitive)]
#[repr(u8)] #[repr(u8)]
pub enum Map { pub enum Map {
/// Summoner's Rift /// Summoner's Rift
/// Original Summer variant /// Original Summer variant
SUMMONERS_RIFT_ORIGINAL_SUMMER_VARIANT = 1, SUMMONERS_RIFT_ORIGINAL_SUMMER_VARIANT = 1,
/// Summoner's Rift /// Summoner's Rift
/// Original Autumn variant /// Original Autumn variant
SUMMONERS_RIFT_ORIGINAL_AUTUMN_VARIANT = 2, SUMMONERS_RIFT_ORIGINAL_AUTUMN_VARIANT = 2,
/// The Proving Grounds /// The Proving Grounds
/// Tutorial Map /// Tutorial Map
THE_PROVING_GROUNDS = 3, THE_PROVING_GROUNDS = 3,
/// Twisted Treeline /// Twisted Treeline
/// Original Version /// Original Version
TWISTED_TREELINE_ORIGINAL_VERSION = 4, TWISTED_TREELINE_ORIGINAL_VERSION = 4,
/// The Crystal Scar /// The Crystal Scar
/// Dominion map /// Dominion map
THE_CRYSTAL_SCAR = 8, THE_CRYSTAL_SCAR = 8,
/// Twisted Treeline /// Twisted Treeline
/// Last TT map /// Last TT map
TWISTED_TREELINE = 10, TWISTED_TREELINE = 10,
/// Summoner's Rift /// Summoner's Rift
/// Current Version /// Current Version
SUMMONERS_RIFT = 11, SUMMONERS_RIFT = 11,
/// Howling Abyss /// Howling Abyss
/// ARAM map /// ARAM map
HOWLING_ABYSS = 12, HOWLING_ABYSS = 12,
/// Butcher's Bridge /// Butcher's Bridge
/// Alternate ARAM map /// Alternate ARAM map
BUTCHERS_BRIDGE = 14, BUTCHERS_BRIDGE = 14,
/// Cosmic Ruins /// Cosmic Ruins
/// Dark Star: Singularity map /// Dark Star: Singularity map
COSMIC_RUINS = 16, COSMIC_RUINS = 16,
/// Valoran City Park /// Valoran City Park
/// Star Guardian Invasion map /// Star Guardian Invasion map
VALORAN_CITY_PARK = 18, VALORAN_CITY_PARK = 18,
/// Substructure 43 /// Substructure 43
/// PROJECT: Hunters map /// PROJECT: Hunters map
SUBSTRUCTURE_43 = 19, SUBSTRUCTURE_43 = 19,
/// Crash Site /// Crash Site
/// Odyssey: Extraction map /// Odyssey: Extraction map
CRASH_SITE = 20, CRASH_SITE = 20,
/// Nexus Blitz /// Nexus Blitz
/// Nexus Blitz map /// Nexus Blitz map
NEXUS_BLITZ = 21, NEXUS_BLITZ = 21,
/// Convergence /// Convergence
/// Teamfight Tactics map /// Teamfight Tactics map
CONVERGENCE = 22, CONVERGENCE = 22,
} }

View file

@ -1,50 +1,50 @@
//! Constant data and Enums used with the Riot Games API. //! Constant data and Enums used with the Riot Games API.
//! //!
//! This module uses SCREAMING_SNAKE_CASE for enum variants, as enums in this //! This module uses SCREAMING_SNAKE_CASE for enum variants, as enums in this
//! crate should be considered collections of constants. //! crate should be considered collections of constants.
#![allow(deprecated)] #![allow(deprecated)]
#![allow(non_camel_case_types)] #![allow(non_camel_case_types)]
mod macro_serde_string; mod macro_serde_string;
mod champion; mod champion;
pub use champion::*; pub use champion::*;
mod division; mod division;
pub use division::*; pub use division::*;
mod game_mode; mod game_mode;
pub use game_mode::*; pub use game_mode::*;
mod game_type; mod game_type;
pub use game_type::*; pub use game_type::*;
mod map; mod map;
pub use map::*; pub use map::*;
mod queue_type; mod queue_type;
pub use queue_type::*; pub use queue_type::*;
mod queue; mod queue;
pub use queue::*; pub use queue::*;
pub mod ranks; pub mod ranks;
mod route; mod route;
pub use route::*; pub use route::*;
mod season; mod season;
pub use season::*; pub use season::*;
/// Trait allowing iteration of enum types, implemented by several enums in this module. /// Trait allowing iteration of enum types, implemented by several enums in this module.
/// Re-exported from strum. /// Re-exported from strum.
/// ///
/// ///
pub use strum::IntoEnumIterator; pub use strum::IntoEnumIterator;
mod team; mod team;
pub use team::*; pub use team::*;
mod tier; mod tier;
pub use tier::*; pub use tier::*;

View file

@ -1,250 +1,250 @@
/////////////////////////////////////////////// ///////////////////////////////////////////////
// // // //
// ! // // ! //
// This file is automatically generated! // // This file is automatically generated! //
// Do not directly edit! // // Do not directly edit! //
// // // //
/////////////////////////////////////////////// ///////////////////////////////////////////////
use serde_repr::{ Serialize_repr, Deserialize_repr }; use serde_repr::{ Serialize_repr, Deserialize_repr };
use num_enum::{ IntoPrimitive, TryFromPrimitive }; use num_enum::{ IntoPrimitive, TryFromPrimitive };
/// League of Legends matchmaking queue. /// League of Legends matchmaking queue.
#[non_exhaustive] #[non_exhaustive]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq)] #[derive(Eq, PartialEq)]
#[derive(Serialize_repr, Deserialize_repr)] #[derive(Serialize_repr, Deserialize_repr)]
#[derive(IntoPrimitive, TryFromPrimitive)] #[derive(IntoPrimitive, TryFromPrimitive)]
#[repr(u16)] #[repr(u16)]
pub enum Queue { pub enum Queue {
/// Games on Custom games /// Games on Custom games
CUSTOM = 0, CUSTOM = 0,
/// 5v5 Blind Pick games on Summoner's Rift /// 5v5 Blind Pick games on Summoner's Rift
/// Deprecated in patch 7.19 in favor of queueId 430 /// Deprecated in patch 7.19 in favor of queueId 430
#[deprecated(note="Deprecated in patch 7.19 in favor of queueId 430")] #[deprecated(note="Deprecated in patch 7.19 in favor of queueId 430")]
SUMMONERS_RIFT_5V5_BLIND_PICK_DEPRECATED_2 = 2, SUMMONERS_RIFT_5V5_BLIND_PICK_DEPRECATED_2 = 2,
/// 5v5 Ranked Solo games on Summoner's Rift /// 5v5 Ranked Solo games on Summoner's Rift
/// Deprecated in favor of queueId 420 /// Deprecated in favor of queueId 420
#[deprecated(note="Deprecated in favor of queueId 420")] #[deprecated(note="Deprecated in favor of queueId 420")]
SUMMONERS_RIFT_5V5_RANKED_SOLO_DEPRECATED_4 = 4, SUMMONERS_RIFT_5V5_RANKED_SOLO_DEPRECATED_4 = 4,
/// 5v5 Ranked Premade games on Summoner's Rift /// 5v5 Ranked Premade games on Summoner's Rift
/// Game mode deprecated /// Game mode deprecated
#[deprecated(note="Game mode deprecated")] #[deprecated(note="Game mode deprecated")]
SUMMONERS_RIFT_5V5_RANKED_PREMADE = 6, SUMMONERS_RIFT_5V5_RANKED_PREMADE = 6,
/// Co-op vs AI games on Summoner's Rift /// Co-op vs AI games on Summoner's Rift
/// Deprecated in favor of queueId 32 and 33 /// Deprecated in favor of queueId 32 and 33
#[deprecated(note="Deprecated in favor of queueId 32 and 33")] #[deprecated(note="Deprecated in favor of queueId 32 and 33")]
SUMMONERS_RIFT_CO_OP_VS_AI = 7, SUMMONERS_RIFT_CO_OP_VS_AI = 7,
/// 3v3 Normal games on Twisted Treeline /// 3v3 Normal games on Twisted Treeline
/// Deprecated in patch 7.19 in favor of queueId 460 /// Deprecated in patch 7.19 in favor of queueId 460
#[deprecated(note="Deprecated in patch 7.19 in favor of queueId 460")] #[deprecated(note="Deprecated in patch 7.19 in favor of queueId 460")]
TWISTED_TREELINE_3V3_NORMAL = 8, TWISTED_TREELINE_3V3_NORMAL = 8,
/// 3v3 Ranked Flex games on Twisted Treeline /// 3v3 Ranked Flex games on Twisted Treeline
/// Deprecated in patch 7.19 in favor of queueId 470 /// Deprecated in patch 7.19 in favor of queueId 470
#[deprecated(note="Deprecated in patch 7.19 in favor of queueId 470")] #[deprecated(note="Deprecated in patch 7.19 in favor of queueId 470")]
TWISTED_TREELINE_3V3_RANKED_FLEX_DEPRECATED_9 = 9, TWISTED_TREELINE_3V3_RANKED_FLEX_DEPRECATED_9 = 9,
/// 5v5 Draft Pick games on Summoner's Rift /// 5v5 Draft Pick games on Summoner's Rift
/// Deprecated in favor of queueId 400 /// Deprecated in favor of queueId 400
#[deprecated(note="Deprecated in favor of queueId 400")] #[deprecated(note="Deprecated in favor of queueId 400")]
SUMMONERS_RIFT_5V5_DRAFT_PICK_DEPRECATED_14 = 14, SUMMONERS_RIFT_5V5_DRAFT_PICK_DEPRECATED_14 = 14,
/// 5v5 Dominion Blind Pick games on Crystal Scar /// 5v5 Dominion Blind Pick games on Crystal Scar
/// Game mode deprecated /// Game mode deprecated
#[deprecated(note="Game mode deprecated")] #[deprecated(note="Game mode deprecated")]
CRYSTAL_SCAR_5V5_DOMINION_BLIND_PICK = 16, CRYSTAL_SCAR_5V5_DOMINION_BLIND_PICK = 16,
/// 5v5 Dominion Draft Pick games on Crystal Scar /// 5v5 Dominion Draft Pick games on Crystal Scar
/// Game mode deprecated /// Game mode deprecated
#[deprecated(note="Game mode deprecated")] #[deprecated(note="Game mode deprecated")]
CRYSTAL_SCAR_5V5_DOMINION_DRAFT_PICK = 17, CRYSTAL_SCAR_5V5_DOMINION_DRAFT_PICK = 17,
/// Dominion Co-op vs AI games on Crystal Scar /// Dominion Co-op vs AI games on Crystal Scar
/// Game mode deprecated /// Game mode deprecated
#[deprecated(note="Game mode deprecated")] #[deprecated(note="Game mode deprecated")]
CRYSTAL_SCAR_DOMINION_CO_OP_VS_AI = 25, CRYSTAL_SCAR_DOMINION_CO_OP_VS_AI = 25,
/// Co-op vs AI Intro Bot games on Summoner's Rift /// Co-op vs AI Intro Bot games on Summoner's Rift
/// Deprecated in patch 7.19 in favor of queueId 830 /// Deprecated in patch 7.19 in favor of queueId 830
#[deprecated(note="Deprecated in patch 7.19 in favor of queueId 830")] #[deprecated(note="Deprecated in patch 7.19 in favor of queueId 830")]
SUMMONERS_RIFT_CO_OP_VS_AI_INTRO_BOT_DEPRECATED_31 = 31, SUMMONERS_RIFT_CO_OP_VS_AI_INTRO_BOT_DEPRECATED_31 = 31,
/// Co-op vs AI Beginner Bot games on Summoner's Rift /// Co-op vs AI Beginner Bot games on Summoner's Rift
/// Deprecated in patch 7.19 in favor of queueId 840 /// Deprecated in patch 7.19 in favor of queueId 840
#[deprecated(note="Deprecated in patch 7.19 in favor of queueId 840")] #[deprecated(note="Deprecated in patch 7.19 in favor of queueId 840")]
SUMMONERS_RIFT_CO_OP_VS_AI_BEGINNER_BOT_DEPRECATED_32 = 32, SUMMONERS_RIFT_CO_OP_VS_AI_BEGINNER_BOT_DEPRECATED_32 = 32,
/// Co-op vs AI Intermediate Bot games on Summoner's Rift /// Co-op vs AI Intermediate Bot games on Summoner's Rift
/// Deprecated in patch 7.19 in favor of queueId 850 /// Deprecated in patch 7.19 in favor of queueId 850
#[deprecated(note="Deprecated in patch 7.19 in favor of queueId 850")] #[deprecated(note="Deprecated in patch 7.19 in favor of queueId 850")]
SUMMONERS_RIFT_CO_OP_VS_AI_INTERMEDIATE_BOT_DEPRECATED_33 = 33, SUMMONERS_RIFT_CO_OP_VS_AI_INTERMEDIATE_BOT_DEPRECATED_33 = 33,
/// 3v3 Ranked Team games on Twisted Treeline /// 3v3 Ranked Team games on Twisted Treeline
/// Game mode deprecated /// Game mode deprecated
#[deprecated(note="Game mode deprecated")] #[deprecated(note="Game mode deprecated")]
TWISTED_TREELINE_3V3_RANKED_TEAM = 41, TWISTED_TREELINE_3V3_RANKED_TEAM = 41,
/// 5v5 Ranked Team games on Summoner's Rift /// 5v5 Ranked Team games on Summoner's Rift
/// Game mode deprecated /// Game mode deprecated
#[deprecated(note="Game mode deprecated")] #[deprecated(note="Game mode deprecated")]
SUMMONERS_RIFT_5V5_RANKED_TEAM = 42, SUMMONERS_RIFT_5V5_RANKED_TEAM = 42,
/// Co-op vs AI games on Twisted Treeline /// Co-op vs AI games on Twisted Treeline
/// Deprecated in patch 7.19 in favor of queueId 800 /// Deprecated in patch 7.19 in favor of queueId 800
#[deprecated(note="Deprecated in patch 7.19 in favor of queueId 800")] #[deprecated(note="Deprecated in patch 7.19 in favor of queueId 800")]
TWISTED_TREELINE_CO_OP_VS_AI = 52, TWISTED_TREELINE_CO_OP_VS_AI = 52,
/// 5v5 Team Builder games on Summoner's Rift /// 5v5 Team Builder games on Summoner's Rift
/// Game mode deprecated /// Game mode deprecated
#[deprecated(note="Game mode deprecated")] #[deprecated(note="Game mode deprecated")]
SUMMONERS_RIFT_5V5_TEAM_BUILDER = 61, SUMMONERS_RIFT_5V5_TEAM_BUILDER = 61,
/// 5v5 ARAM games on Howling Abyss /// 5v5 ARAM games on Howling Abyss
/// Deprecated in patch 7.19 in favor of queueId 450 /// Deprecated in patch 7.19 in favor of queueId 450
#[deprecated(note="Deprecated in patch 7.19 in favor of queueId 450")] #[deprecated(note="Deprecated in patch 7.19 in favor of queueId 450")]
HOWLING_ABYSS_5V5_ARAM_DEPRECATED_65 = 65, HOWLING_ABYSS_5V5_ARAM_DEPRECATED_65 = 65,
/// ARAM Co-op vs AI games on Howling Abyss /// ARAM Co-op vs AI games on Howling Abyss
/// Game mode deprecated /// Game mode deprecated
#[deprecated(note="Game mode deprecated")] #[deprecated(note="Game mode deprecated")]
HOWLING_ABYSS_ARAM_CO_OP_VS_AI = 67, HOWLING_ABYSS_ARAM_CO_OP_VS_AI = 67,
/// One for All games on Summoner's Rift /// One for All games on Summoner's Rift
/// Deprecated in patch 8.6 in favor of queueId 1020 /// Deprecated in patch 8.6 in favor of queueId 1020
#[deprecated(note="Deprecated in patch 8.6 in favor of queueId 1020")] #[deprecated(note="Deprecated in patch 8.6 in favor of queueId 1020")]
SUMMONERS_RIFT_ONE_FOR_ALL_DEPRECATED_70 = 70, SUMMONERS_RIFT_ONE_FOR_ALL_DEPRECATED_70 = 70,
/// 1v1 Snowdown Showdown games on Howling Abyss /// 1v1 Snowdown Showdown games on Howling Abyss
HOWLING_ABYSS_1V1_SNOWDOWN_SHOWDOWN = 72, HOWLING_ABYSS_1V1_SNOWDOWN_SHOWDOWN = 72,
/// 2v2 Snowdown Showdown games on Howling Abyss /// 2v2 Snowdown Showdown games on Howling Abyss
HOWLING_ABYSS_2V2_SNOWDOWN_SHOWDOWN = 73, HOWLING_ABYSS_2V2_SNOWDOWN_SHOWDOWN = 73,
/// 6v6 Hexakill games on Summoner's Rift /// 6v6 Hexakill games on Summoner's Rift
SUMMONERS_RIFT_6V6_HEXAKILL = 75, SUMMONERS_RIFT_6V6_HEXAKILL = 75,
/// Ultra Rapid Fire games on Summoner's Rift /// Ultra Rapid Fire games on Summoner's Rift
SUMMONERS_RIFT_ULTRA_RAPID_FIRE = 76, SUMMONERS_RIFT_ULTRA_RAPID_FIRE = 76,
/// One For All: Mirror Mode games on Howling Abyss /// One For All: Mirror Mode games on Howling Abyss
HOWLING_ABYSS_ONE_FOR_ALL_MIRROR_MODE = 78, HOWLING_ABYSS_ONE_FOR_ALL_MIRROR_MODE = 78,
/// Co-op vs AI Ultra Rapid Fire games on Summoner's Rift /// Co-op vs AI Ultra Rapid Fire games on Summoner's Rift
SUMMONERS_RIFT_CO_OP_VS_AI_ULTRA_RAPID_FIRE = 83, SUMMONERS_RIFT_CO_OP_VS_AI_ULTRA_RAPID_FIRE = 83,
/// Doom Bots Rank 1 games on Summoner's Rift /// Doom Bots Rank 1 games on Summoner's Rift
/// Deprecated in patch 7.19 in favor of queueId 950 /// Deprecated in patch 7.19 in favor of queueId 950
#[deprecated(note="Deprecated in patch 7.19 in favor of queueId 950")] #[deprecated(note="Deprecated in patch 7.19 in favor of queueId 950")]
SUMMONERS_RIFT_DOOM_BOTS_RANK_1 = 91, SUMMONERS_RIFT_DOOM_BOTS_RANK_1 = 91,
/// Doom Bots Rank 2 games on Summoner's Rift /// Doom Bots Rank 2 games on Summoner's Rift
/// Deprecated in patch 7.19 in favor of queueId 950 /// Deprecated in patch 7.19 in favor of queueId 950
#[deprecated(note="Deprecated in patch 7.19 in favor of queueId 950")] #[deprecated(note="Deprecated in patch 7.19 in favor of queueId 950")]
SUMMONERS_RIFT_DOOM_BOTS_RANK_2 = 92, SUMMONERS_RIFT_DOOM_BOTS_RANK_2 = 92,
/// Doom Bots Rank 5 games on Summoner's Rift /// Doom Bots Rank 5 games on Summoner's Rift
/// Deprecated in patch 7.19 in favor of queueId 950 /// Deprecated in patch 7.19 in favor of queueId 950
#[deprecated(note="Deprecated in patch 7.19 in favor of queueId 950")] #[deprecated(note="Deprecated in patch 7.19 in favor of queueId 950")]
SUMMONERS_RIFT_DOOM_BOTS_RANK_5 = 93, SUMMONERS_RIFT_DOOM_BOTS_RANK_5 = 93,
/// Ascension games on Crystal Scar /// Ascension games on Crystal Scar
/// Deprecated in patch 7.19 in favor of queueId 910 /// Deprecated in patch 7.19 in favor of queueId 910
#[deprecated(note="Deprecated in patch 7.19 in favor of queueId 910")] #[deprecated(note="Deprecated in patch 7.19 in favor of queueId 910")]
CRYSTAL_SCAR_ASCENSION_DEPRECATED_96 = 96, CRYSTAL_SCAR_ASCENSION_DEPRECATED_96 = 96,
/// 6v6 Hexakill games on Twisted Treeline /// 6v6 Hexakill games on Twisted Treeline
TWISTED_TREELINE_6V6_HEXAKILL = 98, TWISTED_TREELINE_6V6_HEXAKILL = 98,
/// 5v5 ARAM games on Butcher's Bridge /// 5v5 ARAM games on Butcher's Bridge
BUTCHERS_BRIDGE_5V5_ARAM = 100, BUTCHERS_BRIDGE_5V5_ARAM = 100,
/// Legend of the Poro King games on Howling Abyss /// Legend of the Poro King games on Howling Abyss
/// Deprecated in patch 7.19 in favor of queueId 920 /// Deprecated in patch 7.19 in favor of queueId 920
#[deprecated(note="Deprecated in patch 7.19 in favor of queueId 920")] #[deprecated(note="Deprecated in patch 7.19 in favor of queueId 920")]
HOWLING_ABYSS_LEGEND_OF_THE_PORO_KING_DEPRECATED_300 = 300, HOWLING_ABYSS_LEGEND_OF_THE_PORO_KING_DEPRECATED_300 = 300,
/// Nemesis games on Summoner's Rift /// Nemesis games on Summoner's Rift
SUMMONERS_RIFT_NEMESIS = 310, SUMMONERS_RIFT_NEMESIS = 310,
/// Black Market Brawlers games on Summoner's Rift /// Black Market Brawlers games on Summoner's Rift
SUMMONERS_RIFT_BLACK_MARKET_BRAWLERS = 313, SUMMONERS_RIFT_BLACK_MARKET_BRAWLERS = 313,
/// Nexus Siege games on Summoner's Rift /// Nexus Siege games on Summoner's Rift
/// Deprecated in patch 7.19 in favor of queueId 940 /// Deprecated in patch 7.19 in favor of queueId 940
#[deprecated(note="Deprecated in patch 7.19 in favor of queueId 940")] #[deprecated(note="Deprecated in patch 7.19 in favor of queueId 940")]
SUMMONERS_RIFT_NEXUS_SIEGE_DEPRECATED_315 = 315, SUMMONERS_RIFT_NEXUS_SIEGE_DEPRECATED_315 = 315,
/// Definitely Not Dominion games on Crystal Scar /// Definitely Not Dominion games on Crystal Scar
CRYSTAL_SCAR_DEFINITELY_NOT_DOMINION = 317, CRYSTAL_SCAR_DEFINITELY_NOT_DOMINION = 317,
/// ARURF games on Summoner's Rift /// ARURF games on Summoner's Rift
/// Deprecated in patch 7.19 in favor of queueId 900 /// Deprecated in patch 7.19 in favor of queueId 900
#[deprecated(note="Deprecated in patch 7.19 in favor of queueId 900")] #[deprecated(note="Deprecated in patch 7.19 in favor of queueId 900")]
SUMMONERS_RIFT_ARURF = 318, SUMMONERS_RIFT_ARURF = 318,
/// All Random games on Summoner's Rift /// All Random games on Summoner's Rift
SUMMONERS_RIFT_ALL_RANDOM = 325, SUMMONERS_RIFT_ALL_RANDOM = 325,
/// 5v5 Draft Pick games on Summoner's Rift /// 5v5 Draft Pick games on Summoner's Rift
SUMMONERS_RIFT_5V5_DRAFT_PICK = 400, SUMMONERS_RIFT_5V5_DRAFT_PICK = 400,
/// 5v5 Ranked Dynamic games on Summoner's Rift /// 5v5 Ranked Dynamic games on Summoner's Rift
/// Game mode deprecated in patch 6.22 /// Game mode deprecated in patch 6.22
#[deprecated(note="Game mode deprecated in patch 6.22")] #[deprecated(note="Game mode deprecated in patch 6.22")]
SUMMONERS_RIFT_5V5_RANKED_DYNAMIC = 410, SUMMONERS_RIFT_5V5_RANKED_DYNAMIC = 410,
/// 5v5 Ranked Solo games on Summoner's Rift /// 5v5 Ranked Solo games on Summoner's Rift
SUMMONERS_RIFT_5V5_RANKED_SOLO = 420, SUMMONERS_RIFT_5V5_RANKED_SOLO = 420,
/// 5v5 Blind Pick games on Summoner's Rift /// 5v5 Blind Pick games on Summoner's Rift
SUMMONERS_RIFT_5V5_BLIND_PICK = 430, SUMMONERS_RIFT_5V5_BLIND_PICK = 430,
/// 5v5 Ranked Flex games on Summoner's Rift /// 5v5 Ranked Flex games on Summoner's Rift
SUMMONERS_RIFT_5V5_RANKED_FLEX = 440, SUMMONERS_RIFT_5V5_RANKED_FLEX = 440,
/// 5v5 ARAM games on Howling Abyss /// 5v5 ARAM games on Howling Abyss
HOWLING_ABYSS_5V5_ARAM = 450, HOWLING_ABYSS_5V5_ARAM = 450,
/// 3v3 Blind Pick games on Twisted Treeline /// 3v3 Blind Pick games on Twisted Treeline
/// Deprecated in patch 9.23 /// Deprecated in patch 9.23
#[deprecated(note="Deprecated in patch 9.23")] #[deprecated(note="Deprecated in patch 9.23")]
TWISTED_TREELINE_3V3_BLIND_PICK = 460, TWISTED_TREELINE_3V3_BLIND_PICK = 460,
/// 3v3 Ranked Flex games on Twisted Treeline /// 3v3 Ranked Flex games on Twisted Treeline
/// Deprecated in patch 9.23 /// Deprecated in patch 9.23
#[deprecated(note="Deprecated in patch 9.23")] #[deprecated(note="Deprecated in patch 9.23")]
TWISTED_TREELINE_3V3_RANKED_FLEX_DEPRECATED_470 = 470, TWISTED_TREELINE_3V3_RANKED_FLEX_DEPRECATED_470 = 470,
/// Blood Hunt Assassin games on Summoner's Rift /// Blood Hunt Assassin games on Summoner's Rift
SUMMONERS_RIFT_BLOOD_HUNT_ASSASSIN = 600, SUMMONERS_RIFT_BLOOD_HUNT_ASSASSIN = 600,
/// Dark Star: Singularity games on Cosmic Ruins /// Dark Star: Singularity games on Cosmic Ruins
COSMIC_RUINS_DARK_STAR_SINGULARITY = 610, COSMIC_RUINS_DARK_STAR_SINGULARITY = 610,
/// Clash games on Summoner's Rift /// Clash games on Summoner's Rift
SUMMONERS_RIFT_CLASH = 700, SUMMONERS_RIFT_CLASH = 700,
/// Co-op vs. AI Intermediate Bot games on Twisted Treeline /// Co-op vs. AI Intermediate Bot games on Twisted Treeline
/// Deprecated in patch 9.23 /// Deprecated in patch 9.23
#[deprecated(note="Deprecated in patch 9.23")] #[deprecated(note="Deprecated in patch 9.23")]
TWISTED_TREELINE_CO_OP_VS_AI_INTERMEDIATE_BOT = 800, TWISTED_TREELINE_CO_OP_VS_AI_INTERMEDIATE_BOT = 800,
/// Co-op vs. AI Intro Bot games on Twisted Treeline /// Co-op vs. AI Intro Bot games on Twisted Treeline
/// Deprecated in patch 9.23 /// Deprecated in patch 9.23
#[deprecated(note="Deprecated in patch 9.23")] #[deprecated(note="Deprecated in patch 9.23")]
TWISTED_TREELINE_CO_OP_VS_AI_INTRO_BOT = 810, TWISTED_TREELINE_CO_OP_VS_AI_INTRO_BOT = 810,
/// Co-op vs. AI Beginner Bot games on Twisted Treeline /// Co-op vs. AI Beginner Bot games on Twisted Treeline
TWISTED_TREELINE_CO_OP_VS_AI_BEGINNER_BOT = 820, TWISTED_TREELINE_CO_OP_VS_AI_BEGINNER_BOT = 820,
/// Co-op vs. AI Intro Bot games on Summoner's Rift /// Co-op vs. AI Intro Bot games on Summoner's Rift
SUMMONERS_RIFT_CO_OP_VS_AI_INTRO_BOT = 830, SUMMONERS_RIFT_CO_OP_VS_AI_INTRO_BOT = 830,
/// Co-op vs. AI Beginner Bot games on Summoner's Rift /// Co-op vs. AI Beginner Bot games on Summoner's Rift
SUMMONERS_RIFT_CO_OP_VS_AI_BEGINNER_BOT = 840, SUMMONERS_RIFT_CO_OP_VS_AI_BEGINNER_BOT = 840,
/// Co-op vs. AI Intermediate Bot games on Summoner's Rift /// Co-op vs. AI Intermediate Bot games on Summoner's Rift
SUMMONERS_RIFT_CO_OP_VS_AI_INTERMEDIATE_BOT = 850, SUMMONERS_RIFT_CO_OP_VS_AI_INTERMEDIATE_BOT = 850,
/// URF games on Summoner's Rift /// URF games on Summoner's Rift
SUMMONERS_RIFT_URF = 900, SUMMONERS_RIFT_URF = 900,
/// Ascension games on Crystal Scar /// Ascension games on Crystal Scar
CRYSTAL_SCAR_ASCENSION = 910, CRYSTAL_SCAR_ASCENSION = 910,
/// Legend of the Poro King games on Howling Abyss /// Legend of the Poro King games on Howling Abyss
HOWLING_ABYSS_LEGEND_OF_THE_PORO_KING = 920, HOWLING_ABYSS_LEGEND_OF_THE_PORO_KING = 920,
/// Nexus Siege games on Summoner's Rift /// Nexus Siege games on Summoner's Rift
SUMMONERS_RIFT_NEXUS_SIEGE = 940, SUMMONERS_RIFT_NEXUS_SIEGE = 940,
/// Doom Bots Voting games on Summoner's Rift /// Doom Bots Voting games on Summoner's Rift
SUMMONERS_RIFT_DOOM_BOTS_VOTING = 950, SUMMONERS_RIFT_DOOM_BOTS_VOTING = 950,
/// Doom Bots Standard games on Summoner's Rift /// Doom Bots Standard games on Summoner's Rift
SUMMONERS_RIFT_DOOM_BOTS_STANDARD = 960, SUMMONERS_RIFT_DOOM_BOTS_STANDARD = 960,
/// Star Guardian Invasion: Normal games on Valoran City Park /// Star Guardian Invasion: Normal games on Valoran City Park
VALORAN_CITY_PARK_STAR_GUARDIAN_INVASION_NORMAL = 980, VALORAN_CITY_PARK_STAR_GUARDIAN_INVASION_NORMAL = 980,
/// Star Guardian Invasion: Onslaught games on Valoran City Park /// Star Guardian Invasion: Onslaught games on Valoran City Park
VALORAN_CITY_PARK_STAR_GUARDIAN_INVASION_ONSLAUGHT = 990, VALORAN_CITY_PARK_STAR_GUARDIAN_INVASION_ONSLAUGHT = 990,
/// PROJECT: Hunters games on Overcharge /// PROJECT: Hunters games on Overcharge
OVERCHARGE_PROJECT_HUNTERS = 1000, OVERCHARGE_PROJECT_HUNTERS = 1000,
/// Snow ARURF games on Summoner's Rift /// Snow ARURF games on Summoner's Rift
SUMMONERS_RIFT_SNOW_ARURF = 1010, SUMMONERS_RIFT_SNOW_ARURF = 1010,
/// One for All games on Summoner's Rift /// One for All games on Summoner's Rift
SUMMONERS_RIFT_ONE_FOR_ALL = 1020, SUMMONERS_RIFT_ONE_FOR_ALL = 1020,
/// Odyssey Extraction: Intro games on Crash Site /// Odyssey Extraction: Intro games on Crash Site
CRASH_SITE_ODYSSEY_EXTRACTION_INTRO = 1030, CRASH_SITE_ODYSSEY_EXTRACTION_INTRO = 1030,
/// Odyssey Extraction: Cadet games on Crash Site /// Odyssey Extraction: Cadet games on Crash Site
CRASH_SITE_ODYSSEY_EXTRACTION_CADET = 1040, CRASH_SITE_ODYSSEY_EXTRACTION_CADET = 1040,
/// Odyssey Extraction: Crewmember games on Crash Site /// Odyssey Extraction: Crewmember games on Crash Site
CRASH_SITE_ODYSSEY_EXTRACTION_CREWMEMBER = 1050, CRASH_SITE_ODYSSEY_EXTRACTION_CREWMEMBER = 1050,
/// Odyssey Extraction: Captain games on Crash Site /// Odyssey Extraction: Captain games on Crash Site
CRASH_SITE_ODYSSEY_EXTRACTION_CAPTAIN = 1060, CRASH_SITE_ODYSSEY_EXTRACTION_CAPTAIN = 1060,
/// Odyssey Extraction: Onslaught games on Crash Site /// Odyssey Extraction: Onslaught games on Crash Site
CRASH_SITE_ODYSSEY_EXTRACTION_ONSLAUGHT = 1070, CRASH_SITE_ODYSSEY_EXTRACTION_ONSLAUGHT = 1070,
/// Teamfight Tactics games on Convergence /// Teamfight Tactics games on Convergence
CONVERGENCE_TEAMFIGHT_TACTICS = 1090, CONVERGENCE_TEAMFIGHT_TACTICS = 1090,
/// Ranked Teamfight Tactics games on Convergence /// Ranked Teamfight Tactics games on Convergence
CONVERGENCE_RANKED_TEAMFIGHT_TACTICS = 1100, CONVERGENCE_RANKED_TEAMFIGHT_TACTICS = 1100,
/// Teamfight Tactics Tutorial games on Convergence /// Teamfight Tactics Tutorial games on Convergence
CONVERGENCE_TEAMFIGHT_TACTICS_TUTORIAL = 1110, CONVERGENCE_TEAMFIGHT_TACTICS_TUTORIAL = 1110,
/// Teamfight Tactics 1v0 testing games on Convergence /// Teamfight Tactics 1v0 testing games on Convergence
CONVERGENCE_TEAMFIGHT_TACTICS_1V0_TESTING = 1111, CONVERGENCE_TEAMFIGHT_TACTICS_1V0_TESTING = 1111,
/// Nexus Blitz games on Nexus Blitz /// Nexus Blitz games on Nexus Blitz
/// Deprecated in patch 9.2 in favor of queueId 1300 /// Deprecated in patch 9.2 in favor of queueId 1300
#[deprecated(note="Deprecated in patch 9.2 in favor of queueId 1300")] #[deprecated(note="Deprecated in patch 9.2 in favor of queueId 1300")]
NEXUS_BLITZ_NEXUS_BLITZ_DEPRECATED_1200 = 1200, NEXUS_BLITZ_NEXUS_BLITZ_DEPRECATED_1200 = 1200,
/// Nexus Blitz games on Nexus Blitz /// Nexus Blitz games on Nexus Blitz
NEXUS_BLITZ_NEXUS_BLITZ = 1300, NEXUS_BLITZ_NEXUS_BLITZ = 1300,
/// Tutorial 1 games on Summoner's Rift /// Tutorial 1 games on Summoner's Rift
SUMMONERS_RIFT_TUTORIAL_1 = 2000, SUMMONERS_RIFT_TUTORIAL_1 = 2000,
/// Tutorial 2 games on Summoner's Rift /// Tutorial 2 games on Summoner's Rift
SUMMONERS_RIFT_TUTORIAL_2 = 2010, SUMMONERS_RIFT_TUTORIAL_2 = 2010,
/// Tutorial 3 games on Summoner's Rift /// Tutorial 3 games on Summoner's Rift
SUMMONERS_RIFT_TUTORIAL_3 = 2020, SUMMONERS_RIFT_TUTORIAL_3 = 2020,
} }

View file

@ -1,41 +1,41 @@
use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr }; use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr };
/// LoL or TFT ranked queue types. /// LoL or TFT ranked queue types.
#[non_exhaustive] #[non_exhaustive]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash)] #[derive(Eq, PartialEq, Hash)]
#[derive(EnumString, Display, AsRefStr, IntoStaticStr)] #[derive(EnumString, Display, AsRefStr, IntoStaticStr)]
pub enum QueueType { pub enum QueueType {
// League of Legends, Summoner's Rift (5v5), Ranked Solo Queue. // League of Legends, Summoner's Rift (5v5), Ranked Solo Queue.
RANKED_SOLO_5x5, RANKED_SOLO_5x5,
// League of Legends, Summoner's Rift (5v5), Flex Queue. // League of Legends, Summoner's Rift (5v5), Flex Queue.
RANKED_FLEX_SR, RANKED_FLEX_SR,
// League of Legends, Twisted Treeline (3v3), Flex Queue. // League of Legends, Twisted Treeline (3v3), Flex Queue.
RANKED_FLEX_TT, RANKED_FLEX_TT,
// Ranked Teamfight Tactics. // Ranked Teamfight Tactics.
RANKED_TFT, RANKED_TFT,
// Ranked Teamfight Tactics, Hyper Roll gamemode. // Ranked Teamfight Tactics, Hyper Roll gamemode.
RANKED_TFT_TURBO, RANKED_TFT_TURBO,
} }
serde_string!(QueueType); serde_string!(QueueType);
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
#[test] #[test]
fn check_as_ref() { fn check_as_ref() {
assert_eq!("RANKED_SOLO_5x5", QueueType::RANKED_SOLO_5x5.as_ref()); assert_eq!("RANKED_SOLO_5x5", QueueType::RANKED_SOLO_5x5.as_ref());
} }
#[test] #[test]
fn check_to_string() { fn check_to_string() {
assert_eq!("RANKED_SOLO_5x5", QueueType::RANKED_SOLO_5x5.to_string()); assert_eq!("RANKED_SOLO_5x5", QueueType::RANKED_SOLO_5x5.to_string());
} }
#[test] #[test]
fn check_from_string() { fn check_from_string() {
assert_eq!(Some(QueueType::RANKED_SOLO_5x5), "RANKED_SOLO_5x5".parse().ok()); assert_eq!(Some(QueueType::RANKED_SOLO_5x5), "RANKED_SOLO_5x5".parse().ok());
} }
} }

View file

@ -1,36 +1,36 @@
/////////////////////////////////////////////// ///////////////////////////////////////////////
// // // //
// ! // // ! //
// This file is automatically generated! // // This file is automatically generated! //
// Do not directly edit! // // Do not directly edit! //
// // // //
/////////////////////////////////////////////// ///////////////////////////////////////////////
use serde_repr::{ Serialize_repr, Deserialize_repr }; use serde_repr::{ Serialize_repr, Deserialize_repr };
use num_enum::{ IntoPrimitive, TryFromPrimitive }; use num_enum::{ IntoPrimitive, TryFromPrimitive };
/// League of Legends matchmaking seasons. /// League of Legends matchmaking seasons.
#[non_exhaustive] #[non_exhaustive]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash, PartialOrd, Ord)] #[derive(Eq, PartialEq, Hash, PartialOrd, Ord)]
#[derive(Serialize_repr, Deserialize_repr)] #[derive(Serialize_repr, Deserialize_repr)]
#[derive(IntoPrimitive, TryFromPrimitive)] #[derive(IntoPrimitive, TryFromPrimitive)]
#[repr(u8)] #[repr(u8)]
pub enum Season { pub enum Season {
PRESEASON_3 = 0, PRESEASON_3 = 0,
SEASON_3 = 1, SEASON_3 = 1,
PRESEASON_2014 = 2, PRESEASON_2014 = 2,
SEASON_2014 = 3, SEASON_2014 = 3,
PRESEASON_2015 = 4, PRESEASON_2015 = 4,
SEASON_2015 = 5, SEASON_2015 = 5,
PRESEASON_2016 = 6, PRESEASON_2016 = 6,
SEASON_2016 = 7, SEASON_2016 = 7,
PRESEASON_2017 = 8, PRESEASON_2017 = 8,
SEASON_2017 = 9, SEASON_2017 = 9,
PRESEASON_2018 = 10, PRESEASON_2018 = 10,
SEASON_2018 = 11, SEASON_2018 = 11,
PRESEASON_2019 = 12, PRESEASON_2019 = 12,
SEASON_2019 = 13, SEASON_2019 = 13,
PRESEASON_2020 = 14, PRESEASON_2020 = 14,
SEASON_2020 = 15, SEASON_2020 = 15,
} }

View file

@ -1,15 +1,15 @@
use serde_repr::{ Serialize_repr, Deserialize_repr }; use serde_repr::{ Serialize_repr, Deserialize_repr };
use num_enum::{ IntoPrimitive, TryFromPrimitive }; use num_enum::{ IntoPrimitive, TryFromPrimitive };
/// League of Legends team. /// League of Legends team.
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash, Ord, PartialOrd)] #[derive(Eq, PartialEq, Hash, Ord, PartialOrd)]
#[derive(Serialize_repr, Deserialize_repr)] #[derive(Serialize_repr, Deserialize_repr)]
#[derive(IntoPrimitive, TryFromPrimitive)] #[derive(IntoPrimitive, TryFromPrimitive)]
#[repr(u8)] #[repr(u8)]
pub enum Team { pub enum Team {
/// Blue team (bottom left on Summoner's Rift). /// Blue team (bottom left on Summoner's Rift).
BLUE = 100, BLUE = 100,
/// Red team (top right on Summoner's Rift). /// Red team (top right on Summoner's Rift).
RED = 200, RED = 200,
} }

View file

@ -1,189 +1,189 @@
use strum::IntoEnumIterator; use strum::IntoEnumIterator;
use num_enum::{ IntoPrimitive, TryFromPrimitive }; use num_enum::{ IntoPrimitive, TryFromPrimitive };
use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr }; use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr };
/// LoL and TFT ranked tiers, such as gold, diamond, challenger, etc. /// LoL and TFT ranked tiers, such as gold, diamond, challenger, etc.
/// ///
/// Sorts from lowest rank to highest rank. /// Sorts from lowest rank to highest rank.
/// ///
/// Repr'd as arbitrary `u8` values. /// Repr'd as arbitrary `u8` values.
/// ///
/// Implements [IntoEnumIterator](super::IntoEnumIterator). /// Implements [IntoEnumIterator](super::IntoEnumIterator).
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash, PartialOrd, Ord)] #[derive(Eq, PartialEq, Hash, PartialOrd, Ord)]
#[derive(IntoPrimitive, TryFromPrimitive)] #[derive(IntoPrimitive, TryFromPrimitive)]
#[derive(EnumString, Display, AsRefStr, IntoStaticStr)] #[derive(EnumString, Display, AsRefStr, IntoStaticStr)]
#[repr(u8)] #[repr(u8)]
pub enum Tier { pub enum Tier {
/// Challenger, the highest tier, an apex tier. Repr: `220_u8`. /// Challenger, the highest tier, an apex tier. Repr: `220_u8`.
CHALLENGER = 220, CHALLENGER = 220,
/// Grand Master, an apex tier. Repr: `200_u8`. /// Grand Master, an apex tier. Repr: `200_u8`.
GRANDMASTER = 200, GRANDMASTER = 200,
/// Master, an apex tier. Repr: `180_u8`. /// Master, an apex tier. Repr: `180_u8`.
MASTER = 180, MASTER = 180,
/// Diamond, the higest non-apex tier. Repr: `140_u8`. /// Diamond, the higest non-apex tier. Repr: `140_u8`.
DIAMOND = 140, DIAMOND = 140,
/// Platinum. Repr: `120_u8`. /// Platinum. Repr: `120_u8`.
PLATINUM = 120, PLATINUM = 120,
/// Gold. Repr: `100_u8`. /// Gold. Repr: `100_u8`.
GOLD = 100, GOLD = 100,
/// Silver. Repr: `80_u8`. /// Silver. Repr: `80_u8`.
SILVER = 80, SILVER = 80,
/// Bronze. Repr: `60_u8`. /// Bronze. Repr: `60_u8`.
BRONZE = 60, BRONZE = 60,
/// Iron, the lowest tier. Repr: `40_u8`. /// Iron, the lowest tier. Repr: `40_u8`.
IRON = 40, IRON = 40,
/// Unranked, no tier. Repr: `0_u8`. /// Unranked, no tier. Repr: `0_u8`.
UNRANKED = 0, UNRANKED = 0,
} }
serde_string!(Tier); serde_string!(Tier);
impl Tier { impl Tier {
/// If this tier is an apex tier: master, grandmaster, or challenger. /// If this tier is an apex tier: master, grandmaster, or challenger.
/// Returns false for unranked. /// Returns false for unranked.
/// ///
/// These tiers are NOT queryable by LeagueV4Endpoints::get_league_entries(...). /// These tiers are NOT queryable by LeagueV4Endpoints::get_league_entries(...).
pub const fn is_apex(self) -> bool { pub const fn is_apex(self) -> bool {
// Casts needed for const. // Casts needed for const.
(Self::MASTER as u8) <= (self as u8) (Self::MASTER as u8) <= (self as u8)
} }
/// If this tier is a "standard" tier: iron through diamond. /// If this tier is a "standard" tier: iron through diamond.
/// Returns false for unranked. /// Returns false for unranked.
/// ///
/// ONLY these tiers are queryable by LeagueV4Endpoints::get_league_entries(...). /// ONLY these tiers are queryable by LeagueV4Endpoints::get_league_entries(...).
pub fn is_standard(self) -> bool { pub fn is_standard(self) -> bool {
// Casts needed for const. // Casts needed for const.
((Self::UNRANKED as u8) < (self as u8)) && ((self as u8) < (Self::MASTER as u8)) ((Self::UNRANKED as u8) < (self as u8)) && ((self as u8) < (Self::MASTER as u8))
} }
/// If this tier is ranked. Returns true for iron through challenger, false for unranked. /// If this tier is ranked. Returns true for iron through challenger, false for unranked.
pub const fn is_ranked(self) -> bool { pub const fn is_ranked(self) -> bool {
// Casts needed for const. // Casts needed for const.
(Self::UNRANKED as u8) < (self as u8) (Self::UNRANKED as u8) < (self as u8)
} }
/// If this tier is unranked (`Tier::UNRANKED`). /// If this tier is unranked (`Tier::UNRANKED`).
/// ///
/// UNRANKED is returned by `Participant.highest_achieved_season_tier`. /// UNRANKED is returned by `Participant.highest_achieved_season_tier`.
pub const fn is_unranked(self) -> bool { pub const fn is_unranked(self) -> bool {
// Casts needed for const. // Casts needed for const.
(self as u8) <= (Self::UNRANKED as u8) (self as u8) <= (Self::UNRANKED as u8)
} }
/// Converts UNRANKED to None and all ranked tiers to Some(...). /// Converts UNRANKED to None and all ranked tiers to Some(...).
pub fn to_ranked(self) -> Option<Self> { pub fn to_ranked(self) -> Option<Self> {
if self.is_unranked() { None } else { Some(self) } if self.is_unranked() { None } else { Some(self) }
} }
} }
/// Returns a DoubleEndedIterator of I, II, III, IV. /// Returns a DoubleEndedIterator of I, II, III, IV.
/// Ordered from high rank (I) to low (IV). /// Ordered from high rank (I) to low (IV).
/// Excludes V, which is deprecated. /// Excludes V, which is deprecated.
impl IntoEnumIterator for Tier { impl IntoEnumIterator for Tier {
type Iterator = std::iter::Copied<std::slice::Iter<'static, Self>>; type Iterator = std::iter::Copied<std::slice::Iter<'static, Self>>;
fn iter() -> Self::Iterator { fn iter() -> Self::Iterator {
[ [
Self::CHALLENGER, Self::GRANDMASTER, Self::MASTER, Self::CHALLENGER, Self::GRANDMASTER, Self::MASTER,
Self::DIAMOND, Self::PLATINUM, Self::GOLD, Self::DIAMOND, Self::PLATINUM, Self::GOLD,
Self::SILVER, Self::BRONZE, Self::IRON Self::SILVER, Self::BRONZE, Self::IRON
].iter().copied() ].iter().copied()
} }
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
#[test] #[test]
fn ord() { fn ord() {
assert!(Tier::GOLD < Tier::DIAMOND); assert!(Tier::GOLD < Tier::DIAMOND);
assert!(Tier::UNRANKED < Tier::IRON); assert!(Tier::UNRANKED < Tier::IRON);
} }
#[test] #[test]
fn is_apex() { fn is_apex() {
assert!(Tier::GRANDMASTER.is_apex()); assert!(Tier::GRANDMASTER.is_apex());
assert!(!Tier::DIAMOND.is_apex()); assert!(!Tier::DIAMOND.is_apex());
assert!(!Tier::UNRANKED.is_apex()); assert!(!Tier::UNRANKED.is_apex());
} }
#[test] #[test]
fn is_ranked() { fn is_ranked() {
assert!(Tier::GRANDMASTER.is_ranked()); assert!(Tier::GRANDMASTER.is_ranked());
assert!(Tier::DIAMOND.is_ranked()); assert!(Tier::DIAMOND.is_ranked());
assert!(!Tier::UNRANKED.is_ranked()); assert!(!Tier::UNRANKED.is_ranked());
} }
#[test] #[test]
fn is_unranked() { fn is_unranked() {
assert!(!Tier::GRANDMASTER.is_unranked()); assert!(!Tier::GRANDMASTER.is_unranked());
assert!(!Tier::DIAMOND.is_unranked()); assert!(!Tier::DIAMOND.is_unranked());
assert!(Tier::UNRANKED.is_unranked()); assert!(Tier::UNRANKED.is_unranked());
} }
#[test] #[test]
fn to_ranked() { fn to_ranked() {
assert_eq!(Some(Tier::GRANDMASTER), Tier::GRANDMASTER.to_ranked()); assert_eq!(Some(Tier::GRANDMASTER), Tier::GRANDMASTER.to_ranked());
assert_eq!(Some(Tier::DIAMOND), Tier::DIAMOND.to_ranked()); assert_eq!(Some(Tier::DIAMOND), Tier::DIAMOND.to_ranked());
assert_eq!(None, Tier::UNRANKED.to_ranked()); assert_eq!(None, Tier::UNRANKED.to_ranked());
} }
#[test] #[test]
fn is_standard() { fn is_standard() {
assert!(!Tier::GRANDMASTER.is_standard()); assert!(!Tier::GRANDMASTER.is_standard());
assert!(Tier::DIAMOND.is_standard()); assert!(Tier::DIAMOND.is_standard());
assert!(!Tier::UNRANKED.is_standard()); assert!(!Tier::UNRANKED.is_standard());
} }
#[test] #[test]
fn to_string() { fn to_string() {
assert_eq!("GRANDMASTER", Tier::GRANDMASTER.as_ref()); assert_eq!("GRANDMASTER", Tier::GRANDMASTER.as_ref());
assert_eq!("GRANDMASTER", Tier::GRANDMASTER.to_string()); assert_eq!("GRANDMASTER", Tier::GRANDMASTER.to_string());
assert_eq!("UNRANKED", Tier::UNRANKED.as_ref()); assert_eq!("UNRANKED", Tier::UNRANKED.as_ref());
assert_eq!("UNRANKED", Tier::UNRANKED.to_string()); assert_eq!("UNRANKED", Tier::UNRANKED.to_string());
} }
#[test] #[test]
fn from_string() { fn from_string() {
assert_eq!(Ok(Tier::GRANDMASTER), "GRANDMASTER".parse()); assert_eq!(Ok(Tier::GRANDMASTER), "GRANDMASTER".parse());
assert_eq!(Ok(Tier::UNRANKED), "UNRANKED".parse()); assert_eq!(Ok(Tier::UNRANKED), "UNRANKED".parse());
} }
#[test] #[test]
fn iter() { fn iter() {
use strum::IntoEnumIterator; use strum::IntoEnumIterator;
let mut iter = Tier::iter(); let mut iter = Tier::iter();
assert_eq!(Some(Tier::CHALLENGER), iter.next()); assert_eq!(Some(Tier::CHALLENGER), iter.next());
iter.next(); iter.next();
iter.next(); iter.next();
assert_eq!(Some(Tier::DIAMOND), iter.next()); assert_eq!(Some(Tier::DIAMOND), iter.next());
iter.next(); iter.next();
iter.next(); iter.next();
iter.next(); iter.next();
iter.next(); iter.next();
assert_eq!(Some(Tier::IRON), iter.next()); assert_eq!(Some(Tier::IRON), iter.next());
assert_eq!(None, iter.next()); assert_eq!(None, iter.next());
assert_eq!(None, iter.next_back()); assert_eq!(None, iter.next_back());
let mut iter = Tier::iter().rev(); let mut iter = Tier::iter().rev();
assert_eq!(Some(Tier::IRON), iter.next()); assert_eq!(Some(Tier::IRON), iter.next());
iter.next(); iter.next();
iter.next(); iter.next();
iter.next(); iter.next();
iter.next(); iter.next();
assert_eq!(Some(Tier::DIAMOND), iter.next()); assert_eq!(Some(Tier::DIAMOND), iter.next());
iter.next(); iter.next();
iter.next(); iter.next();
assert_eq!(Some(Tier::CHALLENGER), iter.next()); assert_eq!(Some(Tier::CHALLENGER), iter.next());
assert_eq!(None, iter.next()); assert_eq!(None, iter.next());
assert_eq!(None, iter.next_back()); assert_eq!(None, iter.next_back());
let mut iter = Tier::iter(); let mut iter = Tier::iter();
assert_eq!(Some(Tier::CHALLENGER), iter.next()); assert_eq!(Some(Tier::CHALLENGER), iter.next());
assert_eq!(Some(Tier::IRON), iter.next_back()); assert_eq!(Some(Tier::IRON), iter.next_back());
} }
} }

View file

@ -1,65 +1,65 @@
use std::error::Error as StdError; use std::error::Error as StdError;
use std::fmt; use std::fmt;
use reqwest::{ Error, Response, StatusCode }; use reqwest::{ Error, Response, StatusCode };
/// Result containing RiotApiError on failure. /// Result containing RiotApiError on failure.
pub type Result<T> = std::result::Result<T, RiotApiError>; pub type Result<T> = std::result::Result<T, RiotApiError>;
/// An error that occurred while processing a Riot API request. /// An error that occurred while processing a Riot API request.
/// ///
/// Although Riven may make multiple requests due to retries, this will always /// Although Riven may make multiple requests due to retries, this will always
/// contain exactly one reqwest::Error for the final request which failed. /// contain exactly one reqwest::Error for the final request which failed.
#[derive(Debug)] #[derive(Debug)]
pub struct RiotApiError { pub struct RiotApiError {
reqwest_error: Error, reqwest_error: Error,
retries: u8, retries: u8,
response: Option<Response>, response: Option<Response>,
status_code: Option<StatusCode>, status_code: Option<StatusCode>,
} }
impl RiotApiError { impl RiotApiError {
pub(crate) fn new(reqwest_error: Error, retries: u8, response: Option<Response>, status_code: Option<StatusCode>) -> Self { pub(crate) fn new(reqwest_error: Error, retries: u8, response: Option<Response>, status_code: Option<StatusCode>) -> Self {
Self { Self {
reqwest_error: reqwest_error, reqwest_error: reqwest_error,
retries: retries, retries: retries,
response: response, response: response,
status_code: status_code, status_code: status_code,
} }
} }
/// The reqwest::Error for the final failed request. /// The reqwest::Error for the final failed request.
pub fn source_reqwest_error(&self) -> &Error { pub fn source_reqwest_error(&self) -> &Error {
&self.reqwest_error &self.reqwest_error
} }
/// The number of retires attempted. Zero means exactly one request, zero retries. /// The number of retires attempted. Zero means exactly one request, zero retries.
pub fn retries(&self) -> u8 { pub fn retries(&self) -> u8 {
self.retries self.retries
} }
/// The failed response. /// The failed response.
/// `Some(&reqwest::Response)` if the request was sent and failed. /// `Some(&reqwest::Response)` if the request was sent and failed.
/// `None` if the request was not sent, OR if parsing the response JSON failed. /// `None` if the request was not sent, OR if parsing the response JSON failed.
pub fn response(&self) -> Option<&Response> { pub fn response(&self) -> Option<&Response> {
self.response.as_ref() self.response.as_ref()
} }
/// The failed response. /// The failed response.
/// `Some(reqwest::Response)` if the request was sent and failed. /// `Some(reqwest::Response)` if the request was sent and failed.
/// `None` if the request was not sent, OR if parsing the response JSON failed. /// `None` if the request was not sent, OR if parsing the response JSON failed.
pub fn take_response(&mut self) -> Option<Response> { pub fn take_response(&mut self) -> Option<Response> {
self.response.take() self.response.take()
} }
/// The failed response's HTTP status code. /// The failed response's HTTP status code.
/// `Some(reqwest::StatusCode)` if the request was sent and failed, OR if parsing the response JSON failed. /// `Some(reqwest::StatusCode)` if the request was sent and failed, OR if parsing the response JSON failed.
/// `None` if the request was not sent. /// `None` if the request was not sent.
pub fn status_code(&self) -> Option<StatusCode> { pub fn status_code(&self) -> Option<StatusCode> {
self.status_code self.status_code
} }
} }
impl fmt::Display for RiotApiError { impl fmt::Display for RiotApiError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:#?}", self) write!(f, "{:#?}", self)
} }
} }
impl StdError for RiotApiError { impl StdError for RiotApiError {
fn source(&self) -> Option<&(dyn StdError + 'static)> { fn source(&self) -> Option<&(dyn StdError + 'static)> {
Some(&self.reqwest_error) Some(&self.reqwest_error)
} }
} }

View file

@ -1,18 +1,18 @@
//! Module containing rate limiting and requesting types. //! Module containing rate limiting and requesting types.
mod rate_limit; mod rate_limit;
pub use rate_limit::*; pub use rate_limit::*;
mod rate_limit_type; mod rate_limit_type;
pub use rate_limit_type::*; pub use rate_limit_type::*;
use std::time::Instant; // Hack for token_bucket_test.rs. use std::time::Instant; // Hack for token_bucket_test.rs.
mod token_bucket; mod token_bucket;
pub use token_bucket::*; pub use token_bucket::*;
mod regional_requester; mod regional_requester;
pub use regional_requester::*; pub use regional_requester::*;
#[cfg(test)] #[cfg(test)]
#[path = "token_bucket.test.rs"] #[path = "token_bucket.test.rs"]
mod token_bucket_test; mod token_bucket_test;

View file

@ -1,204 +1,204 @@
use std::cmp; use std::cmp;
use std::time::{ Duration, Instant }; use std::time::{ Duration, Instant };
use log; use log;
use parking_lot::{ RwLock, RwLockUpgradableReadGuard }; use parking_lot::{ RwLock, RwLockUpgradableReadGuard };
use reqwest::{ StatusCode, Response }; use reqwest::{ StatusCode, Response };
use scan_fmt::scan_fmt; use scan_fmt::scan_fmt;
use crate::RiotApiConfig; use crate::RiotApiConfig;
use super::{ TokenBucket, VectorTokenBucket }; use super::{ TokenBucket, VectorTokenBucket };
use super::RateLimitType; use super::RateLimitType;
pub struct RateLimit { pub struct RateLimit {
rate_limit_type: RateLimitType, rate_limit_type: RateLimitType,
// 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.
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: RwLock<Option<Instant>>, retry_after: RwLock<Option<Instant>>,
} }
impl RateLimit { impl RateLimit {
/// Header specifying which RateLimitType caused a 429. /// Header specifying which RateLimitType caused a 429.
const HEADER_XRATELIMITTYPE: &'static str = "X-Rate-Limit-Type"; const HEADER_XRATELIMITTYPE: &'static str = "X-Rate-Limit-Type";
pub fn new(rate_limit_type: RateLimitType) -> Self { pub fn new(rate_limit_type: RateLimitType) -> Self {
let initial_bucket = VectorTokenBucket::new( let initial_bucket = VectorTokenBucket::new(
Duration::from_secs(1), 1, Duration::new(0, 0), 1.0); Duration::from_secs(1), 1, Duration::new(0, 0), 1.0);
RateLimit { RateLimit {
rate_limit_type: rate_limit_type, rate_limit_type: rate_limit_type,
// Rate limit before getting from response: 1/s. // Rate limit before getting from response: 1/s.
buckets: RwLock::new(vec![initial_bucket]), buckets: RwLock::new(vec![initial_bucket]),
retry_after: RwLock::new(None), retry_after: RwLock::new(None),
} }
} }
pub fn get_both_or_delay(app_rate_limit: &Self, method_rate_limit: &Self) -> Option<Duration> { pub fn get_both_or_delay(app_rate_limit: &Self, method_rate_limit: &Self) -> Option<Duration> {
// Check retry after. // Check retry after.
{ {
let retry_after_delay = app_rate_limit.get_retry_after_delay() let retry_after_delay = app_rate_limit.get_retry_after_delay()
.and_then(|a| method_rate_limit.get_retry_after_delay().map(|m| cmp::max(a, m))); .and_then(|a| method_rate_limit.get_retry_after_delay().map(|m| cmp::max(a, m)));
if retry_after_delay.is_some() { if retry_after_delay.is_some() {
return retry_after_delay return retry_after_delay
} }
} }
// Check buckets. // Check buckets.
let app_buckets = app_rate_limit.buckets.read(); let app_buckets = app_rate_limit.buckets.read();
let method_buckets = method_rate_limit.buckets.read(); let method_buckets = method_rate_limit.buckets.read();
for bucket in app_buckets.iter().chain(method_buckets.iter()) { for bucket in app_buckets.iter().chain(method_buckets.iter()) {
let delay = bucket.get_delay(); let delay = bucket.get_delay();
if delay.is_some() { if delay.is_some() {
return delay; return delay;
} }
} }
// Success. // Success.
for bucket in app_buckets.iter().chain(method_buckets.iter()) { for bucket in app_buckets.iter().chain(method_buckets.iter()) {
bucket.get_tokens(1); bucket.get_tokens(1);
} }
log::trace!("Tokens obtained, buckets: APP {:?} METHOD {:?}", app_buckets, method_buckets); log::trace!("Tokens obtained, buckets: APP {:?} METHOD {:?}", app_buckets, method_buckets);
None None
} }
pub fn get_retry_after_delay(&self) -> Option<Duration> { pub fn get_retry_after_delay(&self) -> Option<Duration> {
self.retry_after.read().and_then(|i| Instant::now().checked_duration_since(i)) self.retry_after.read().and_then(|i| Instant::now().checked_duration_since(i))
} }
pub fn on_response(&self, config: &RiotApiConfig, response: &Response) { pub fn on_response(&self, config: &RiotApiConfig, response: &Response) {
self.on_response_retry_after(response); self.on_response_retry_after(response);
self.on_response_rate_limits(config, response); self.on_response_rate_limits(config, response);
} }
/// `on_response` helper for retry after check. /// `on_response` helper for retry after check.
#[inline] #[inline]
fn on_response_retry_after(&self, response: &Response) { fn on_response_retry_after(&self, response: &Response) {
if let Some(retry_after) = || -> Option<Instant> { if let Some(retry_after) = || -> Option<Instant> {
// Only care about 429s. // Only care about 429s.
if StatusCode::TOO_MANY_REQUESTS != response.status() { if StatusCode::TOO_MANY_REQUESTS != response.status() {
return None; return None;
} }
{ {
// Check if the header that indicates the relevant RateLimit is present. // Check if the header that indicates the relevant RateLimit is present.
let header_opt = response.headers() let header_opt = response.headers()
.get(RateLimit::HEADER_XRATELIMITTYPE) .get(RateLimit::HEADER_XRATELIMITTYPE)
.or_else(|| { .or_else(|| {
log::info!("429 response missing {} header.", RateLimit::HEADER_XRATELIMITTYPE); log::info!("429 response missing {} header.", RateLimit::HEADER_XRATELIMITTYPE);
None None
}) })
.and_then(|header_value| header_value.to_str() .and_then(|header_value| header_value.to_str()
.map_err(|e| log::info!("429 response, failed to parse {} header as string: {}.", .map_err(|e| log::info!("429 response, failed to parse {} header as string: {}.",
RateLimit::HEADER_XRATELIMITTYPE, e)) RateLimit::HEADER_XRATELIMITTYPE, e))
.ok()); .ok());
match header_opt { match header_opt {
None => { None => {
// Take default responsibility, or ignore. // Take default responsibility, or ignore.
if !self.rate_limit_type.default_responsibility() { if !self.rate_limit_type.default_responsibility() {
return None; return None;
} }
log::warn!("429 response has missing or invalid {} header, {} rate limit taking responsibility.", log::warn!("429 response has missing or invalid {} header, {} rate limit taking responsibility.",
RateLimit::HEADER_XRATELIMITTYPE, self.rate_limit_type.type_name()); RateLimit::HEADER_XRATELIMITTYPE, self.rate_limit_type.type_name());
} }
Some(header_value) => { Some(header_value) => {
// Ignore if header's value does not match us. // Ignore if header's value does not match us.
if self.rate_limit_type.type_name() != header_value.to_lowercase() { if self.rate_limit_type.type_name() != header_value.to_lowercase() {
return None; return None;
} }
} }
} }
} }
// Get retry after header. Only care if it exists. // Get retry after header. Only care if it exists.
let retry_after_header = response.headers() let retry_after_header = response.headers()
.get(reqwest::header::RETRY_AFTER)?.to_str() .get(reqwest::header::RETRY_AFTER)?.to_str()
.expect("Failed to read retry-after header as string."); .expect("Failed to read retry-after header as string.");
log::info!("429 response, rate limit {}, retry-after {} secs.", self.rate_limit_type.type_name(), retry_after_header); log::info!("429 response, rate limit {}, retry-after {} secs.", self.rate_limit_type.type_name(), retry_after_header);
// Header currently only returns ints, but float is more general. Can be zero. // Header currently only returns ints, but float is more general. Can be zero.
let retry_after_secs: f32 = retry_after_header.parse() let retry_after_secs: f32 = retry_after_header.parse()
.expect("Failed to parse retry-after header as f32."); .expect("Failed to parse retry-after header as f32.");
// Add 0.5 seconds to account for rounding, cases when response is zero. // Add 0.5 seconds to account for rounding, cases when response is zero.
let delay = Duration::from_secs_f32(0.5 + retry_after_secs); let delay = Duration::from_secs_f32(0.5 + retry_after_secs);
return Some(Instant::now() + delay); return Some(Instant::now() + delay);
}() { }() {
*self.retry_after.write() = Some(retry_after); *self.retry_after.write() = Some(retry_after);
} }
} }
#[inline] #[inline]
fn on_response_rate_limits(&self, config: &RiotApiConfig, response: &Response) { fn on_response_rate_limits(&self, config: &RiotApiConfig, response: &Response) {
// Check if rate limits changed. // Check if rate limits changed.
let headers = response.headers(); let headers = response.headers();
let limit_header_opt = headers.get(self.rate_limit_type.limit_header()) let limit_header_opt = headers.get(self.rate_limit_type.limit_header())
.map(|h| h.to_str().expect("Failed to read limit header as string.")); .map(|h| h.to_str().expect("Failed to read limit header as string."));
let count_header_opt = headers.get(self.rate_limit_type.count_header()) let count_header_opt = headers.get(self.rate_limit_type.count_header())
.map(|h| h.to_str().expect("Failed to read count header as string.")); .map(|h| h.to_str().expect("Failed to read count header as string."));
// https://github.com/rust-lang/rust/issues/53667 // https://github.com/rust-lang/rust/issues/53667
if let Some(limit_header) = limit_header_opt { if let Some(limit_header) = limit_header_opt {
if let Some(count_header) = count_header_opt { if let Some(count_header) = count_header_opt {
let buckets = self.buckets.upgradable_read(); let buckets = self.buckets.upgradable_read();
if !buckets_require_updating(limit_header, &*buckets) { if !buckets_require_updating(limit_header, &*buckets) {
return; return;
} }
// Buckets require updating. Upgrade to write lock. // Buckets require updating. Upgrade to write lock.
let mut buckets = RwLockUpgradableReadGuard::upgrade(buckets); let mut buckets = RwLockUpgradableReadGuard::upgrade(buckets);
*buckets = buckets_from_header(config, limit_header, count_header) *buckets = buckets_from_header(config, limit_header, count_header)
}} }}
} }
} }
fn buckets_require_updating(limit_header: &str, buckets: &Vec<VectorTokenBucket>) -> bool { fn buckets_require_updating(limit_header: &str, buckets: &Vec<VectorTokenBucket>) -> bool {
if buckets.len() != limit_header.split(",").count() { if buckets.len() != limit_header.split(",").count() {
return true; return true;
} }
for (limit_header_entry, bucket) in limit_header.split(",").zip(&*buckets) { for (limit_header_entry, bucket) in limit_header.split(",").zip(&*buckets) {
// limit_header_entry "100:60" means 100 req per 60 sec. // limit_header_entry "100:60" means 100 req per 60 sec.
let bucket_entry = format!("{}:{}", bucket.get_total_limit(), bucket.get_bucket_duration().as_secs()); let bucket_entry = format!("{}:{}", bucket.get_total_limit(), bucket.get_bucket_duration().as_secs());
if limit_header_entry != bucket_entry { if limit_header_entry != bucket_entry {
return true; return true;
} }
} }
false false
} }
fn buckets_from_header(config: &RiotApiConfig, limit_header: &str, count_header: &str) -> Vec<VectorTokenBucket> { fn buckets_from_header(config: &RiotApiConfig, limit_header: &str, count_header: &str) -> Vec<VectorTokenBucket> {
// Limits: "20000:10,1200000:600" // Limits: "20000:10,1200000:600"
// Counts: "7:10,58:600" // Counts: "7:10,58:600"
let size = limit_header.split(",").count(); let size = limit_header.split(",").count();
debug_assert!(size == count_header.split(",").count()); debug_assert!(size == count_header.split(",").count());
let mut out = Vec::with_capacity(size); let mut out = Vec::with_capacity(size);
for (limit_entry, count_entry) in limit_header.split(",").zip(count_header.split(",")) { for (limit_entry, count_entry) in limit_header.split(",").zip(count_header.split(",")) {
let (limit, limit_secs) = scan_fmt!(limit_entry, "{d}:{d}", usize, u64) let (limit, limit_secs) = scan_fmt!(limit_entry, "{d}:{d}", usize, u64)
.unwrap_or_else(|_| panic!("Failed to parse limit entry \"{}\".", limit_entry)); .unwrap_or_else(|_| panic!("Failed to parse limit entry \"{}\".", limit_entry));
let (count, count_secs) = scan_fmt!(count_entry, "{d}:{d}", usize, u64) let (count, count_secs) = scan_fmt!(count_entry, "{d}:{d}", usize, u64)
.unwrap_or_else(|_| panic!("Failed to parse count entry \"{}\".", count_entry)); .unwrap_or_else(|_| panic!("Failed to parse count entry \"{}\".", count_entry));
debug_assert!(limit_secs == count_secs); debug_assert!(limit_secs == count_secs);
let limit_f32 = limit as f32; let limit_f32 = limit as f32;
let scaled_burst_pct = config.burst_pct * limit_f32 / (limit_f32 + 1.0); let scaled_burst_pct = config.burst_pct * limit_f32 / (limit_f32 + 1.0);
let bucket = VectorTokenBucket::new(Duration::from_secs(limit_secs), limit, let bucket = VectorTokenBucket::new(Duration::from_secs(limit_secs), limit,
config.duration_overhead, scaled_burst_pct); config.duration_overhead, scaled_burst_pct);
bucket.get_tokens(count); bucket.get_tokens(count);
out.push(bucket); out.push(bucket);
} }
log::debug!("Set buckets to {} limit, {} count.", limit_header, count_header); log::debug!("Set buckets to {} limit, {} count.", limit_header, count_header);
out out
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
// use super::*; // use super::*;
// fn send_sync() { // fn send_sync() {
// fn is_send_sync<T: Send + Sync>() {} // fn is_send_sync<T: Send + Sync>() {}
// is_send_sync::<RateLimit>(); // is_send_sync::<RateLimit>();
// } // }
} }

View file

@ -1,37 +1,37 @@
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub enum RateLimitType { pub enum RateLimitType {
Application, Application,
Method, Method,
} }
impl RateLimitType { impl RateLimitType {
pub fn type_name(self) -> &'static str { pub fn type_name(self) -> &'static str {
match self { match self {
Self::Application => "application", Self::Application => "application",
Self::Method => "method", Self::Method => "method",
} }
} }
pub fn limit_header(self) -> &'static str { pub fn limit_header(self) -> &'static str {
match self { match self {
Self::Application => "X-App-Rate-Limit", Self::Application => "X-App-Rate-Limit",
Self::Method => "X-Method-Rate-Limit", Self::Method => "X-Method-Rate-Limit",
} }
} }
pub fn count_header(self) -> &'static str { pub fn count_header(self) -> &'static str {
match self { match self {
Self::Application => "X-App-Rate-Limit-Count", Self::Application => "X-App-Rate-Limit-Count",
Self::Method => "X-Method-Rate-Limit-Count", Self::Method => "X-Method-Rate-Limit-Count",
} }
} }
/// Return if this RateLimitType should take responsibility for responses /// Return if this RateLimitType should take responsibility for responses
/// which are lacking a "X-Rate-Limit-Type" header. /// which are lacking a "X-Rate-Limit-Type" header.
pub fn default_responsibility(self) -> bool { pub fn default_responsibility(self) -> bool {
match self { match self {
Self::Application => true, Self::Application => true,
Self::Method => false, Self::Method => false,
} }
} }
} }

View file

@ -1,97 +1,97 @@
use std::future::Future; use std::future::Future;
use std::sync::Arc; use std::sync::Arc;
use log; use log;
use reqwest::{ StatusCode, RequestBuilder }; use reqwest::{ StatusCode, RequestBuilder };
use crate::Result; use crate::Result;
use crate::ResponseInfo; use crate::ResponseInfo;
use crate::RiotApiError; use crate::RiotApiError;
use crate::RiotApiConfig; use crate::RiotApiConfig;
use crate::util::InsertOnlyCHashMap; use crate::util::InsertOnlyCHashMap;
use super::RateLimit; use super::RateLimit;
use super::RateLimitType; use super::RateLimitType;
pub struct RegionalRequester { pub struct RegionalRequester {
/// The app rate limit. /// The app rate limit.
app_rate_limit: RateLimit, app_rate_limit: RateLimit,
/// Method rate limits. /// Method rate limits.
method_rate_limits: InsertOnlyCHashMap<&'static str, RateLimit>, method_rate_limits: InsertOnlyCHashMap<&'static str, RateLimit>,
} }
impl RegionalRequester { impl RegionalRequester {
/// HTTP status codes which are considered a success but will results in `None`. /// HTTP status codes which are considered a success but will results in `None`.
const NONE_STATUS_CODES: [StatusCode; 2] = [ const NONE_STATUS_CODES: [StatusCode; 2] = [
StatusCode::NO_CONTENT, // 204 StatusCode::NO_CONTENT, // 204
StatusCode::NOT_FOUND, // 404 StatusCode::NOT_FOUND, // 404
]; ];
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
app_rate_limit: RateLimit::new(RateLimitType::Application), app_rate_limit: RateLimit::new(RateLimitType::Application),
method_rate_limits: InsertOnlyCHashMap::new(), method_rate_limits: InsertOnlyCHashMap::new(),
} }
} }
pub fn execute<'a>(self: Arc<Self>, pub fn execute<'a>(self: Arc<Self>,
config: &'a RiotApiConfig, config: &'a RiotApiConfig,
method_id: &'static str, request: RequestBuilder) method_id: &'static str, request: RequestBuilder)
-> impl Future<Output = Result<ResponseInfo>> + 'a -> impl Future<Output = Result<ResponseInfo>> + 'a
{ {
async move { async move {
let mut retries: u8 = 0; let mut retries: u8 = 0;
loop { loop {
let method_rate_limit: Arc<RateLimit> = self.method_rate_limits let method_rate_limit: Arc<RateLimit> = self.method_rate_limits
.get_or_insert_with(method_id, || RateLimit::new(RateLimitType::Method)); .get_or_insert_with(method_id, || RateLimit::new(RateLimitType::Method));
// Rate limiting. // Rate limiting.
while let Some(delay) = RateLimit::get_both_or_delay(&self.app_rate_limit, &*method_rate_limit) { while let Some(delay) = RateLimit::get_both_or_delay(&self.app_rate_limit, &*method_rate_limit) {
tokio::time::sleep(delay).await; tokio::time::sleep(delay).await;
} }
// Send request. // Send request.
let request_clone = request.try_clone().expect("Failed to clone request."); let request_clone = request.try_clone().expect("Failed to clone request.");
let response = request_clone.send().await let response = request_clone.send().await
.map_err(|e| RiotApiError::new(e, retries, None, None))?; .map_err(|e| RiotApiError::new(e, retries, None, None))?;
// Maybe update rate limits (based on response headers). // Maybe update rate limits (based on response headers).
self.app_rate_limit.on_response(&config, &response); self.app_rate_limit.on_response(&config, &response);
method_rate_limit.on_response(&config, &response); method_rate_limit.on_response(&config, &response);
let status = response.status(); let status = response.status();
// Handle normal success / failure cases. // Handle normal success / failure cases.
let status_none = Self::NONE_STATUS_CODES.contains(&status); let status_none = Self::NONE_STATUS_CODES.contains(&status);
// Success case. // Success case.
if status.is_success() || status_none { if status.is_success() || status_none {
log::trace!("Response {} (retried {} times), success, returning result.", status, retries); log::trace!("Response {} (retried {} times), success, returning result.", status, retries);
break Ok(ResponseInfo { break Ok(ResponseInfo {
response: response, response: response,
retries: retries, retries: retries,
status_none: status_none, status_none: status_none,
}); });
} }
let err = response.error_for_status_ref().err().unwrap_or_else( let err = response.error_for_status_ref().err().unwrap_or_else(
|| panic!("Unhandlable response status code, neither success nor failure: {}.", status)); || panic!("Unhandlable response status code, neither success nor failure: {}.", status));
// Failure, may or may not be retryable. // Failure, may or may not be retryable.
// Not-retryable: no more retries or 4xx or ? (3xx, redirects exceeded). // Not-retryable: no more retries or 4xx or ? (3xx, redirects exceeded).
// Retryable: retries remaining, and 429 or 5xx. // Retryable: retries remaining, and 429 or 5xx.
if retries >= config.retries || if retries >= config.retries ||
(StatusCode::TOO_MANY_REQUESTS != status (StatusCode::TOO_MANY_REQUESTS != status
&& !status.is_server_error()) && !status.is_server_error())
{ {
log::debug!("Response {} (retried {} times), failure, returning error.", status, retries); log::debug!("Response {} (retried {} times), failure, returning error.", status, retries);
break Err(RiotApiError::new(err, retries, Some(response), Some(status))); break Err(RiotApiError::new(err, retries, Some(response), Some(status)));
} }
log::debug!("Response {} (retried {} times), retrying.", status, retries); log::debug!("Response {} (retried {} times), retrying.", status, retries);
retries += 1; retries += 1;
} }
} }
} }
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
// use super::*; // use super::*;
} }

View file

@ -1,156 +1,156 @@
use std::fmt; use std::fmt;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::time::Duration; use std::time::Duration;
use parking_lot::{Mutex, MutexGuard}; use parking_lot::{Mutex, MutexGuard};
use super::Instant; // Hack for token_bucket_test.rs. use super::Instant; // Hack for token_bucket_test.rs.
/// A `TokenBucket` keeps track of number of requests allowed per duration of /// A `TokenBucket` keeps track of number of requests allowed per duration of
/// time. /// time.
/// ///
/// Respone headers contain descriptions of rate limits such as /// Respone headers contain descriptions of rate limits such as
/// `"X-App-Rate-Limit": "20:1,100:120"`. Each `TokenBucket` corresponds to a /// `"X-App-Rate-Limit": "20:1,100:120"`. Each `TokenBucket` corresponds to a
/// single `"100:120"` (100 requests per 120 seconds). /// single `"100:120"` (100 requests per 120 seconds).
pub trait TokenBucket { pub trait TokenBucket {
/// Get the duration til the next available token, or None if a token /// Get the duration til the next available token, or None if a token
/// is available. /// is available.
/// # Returns /// # Returns
/// Duration or 0 duration. /// Duration or 0 duration.
fn get_delay(&self) -> Option<Duration>; fn get_delay(&self) -> Option<Duration>;
/// Gets n tokens, regardless of whether they are available. /// Gets n tokens, regardless of whether they are available.
/// # Parameters /// # Parameters
/// * `n` - Number of tokens to take. /// * `n` - Number of tokens to take.
/// # Returns /// # Returns
/// True if the tokens were obtained without violating limits, false /// True if the tokens were obtained without violating limits, false
/// otherwise. /// otherwise.
fn get_tokens(&self, n: usize) -> bool; fn get_tokens(&self, n: usize) -> bool;
/// Get the duration of this bucket. /// Get the duration of this bucket.
/// # Returns /// # Returns
/// Duration of the bucket. /// Duration of the bucket.
fn get_bucket_duration(&self) -> Duration; fn get_bucket_duration(&self) -> Duration;
/// Get the total limit of this bucket per timespan. /// Get the total limit of this bucket per timespan.
/// # Returns /// # Returns
/// Total limit per timespan. /// Total limit per timespan.
fn get_total_limit(&self) -> usize; fn get_total_limit(&self) -> usize;
} }
pub struct VectorTokenBucket { pub struct VectorTokenBucket {
/// Duration of this TokenBucket. /// Duration of this TokenBucket.
duration: Duration, duration: Duration,
// Total tokens available from this TokenBucket. // Total tokens available from this TokenBucket.
total_limit: usize, total_limit: usize,
/// Extra duration to be considered on top of `duration`, to account for /// Extra duration to be considered on top of `duration`, to account for
/// varying network latency. /// varying network latency.
duration_overhead: Duration, duration_overhead: Duration,
/// Duration considered for burst factor. /// Duration considered for burst factor.
burst_duration: Duration, burst_duration: Duration,
/// Limit allowed per burst_duration, for burst factor. /// Limit allowed per burst_duration, for burst factor.
burst_limit: usize, burst_limit: usize,
/// Record of timestamps (synchronized). /// Record of timestamps (synchronized).
timestamps: Mutex<VecDeque<Instant>>, timestamps: Mutex<VecDeque<Instant>>,
} }
impl VectorTokenBucket { impl VectorTokenBucket {
pub fn new(duration: Duration, total_limit: usize, pub fn new(duration: Duration, total_limit: usize,
duration_overhead: Duration, burst_pct: f32) -> Self duration_overhead: Duration, burst_pct: f32) -> Self
{ {
debug_assert!(0.0 < burst_pct && burst_pct <= 1.0, debug_assert!(0.0 < burst_pct && burst_pct <= 1.0,
"BAD burst_pct {}.", burst_pct); "BAD burst_pct {}.", burst_pct);
// Float ops may lose precision, but nothing should be that precise. // Float ops may lose precision, but nothing should be that precise.
// API always uses round numbers, burst_pct is frac of 256. // API always uses round numbers, burst_pct is frac of 256.
// Effective duration. // Effective duration.
let d_eff = duration + duration_overhead; let d_eff = duration + duration_overhead;
let burst_duration = Duration::new( let burst_duration = Duration::new(
(d_eff.as_secs() as f32 * burst_pct).ceil() as u64, (d_eff.as_secs() as f32 * burst_pct).ceil() as u64,
(d_eff.subsec_nanos() as f32 * burst_pct).ceil() as u32); (d_eff.subsec_nanos() as f32 * burst_pct).ceil() as u32);
let burst_limit = std::cmp::max(1, let burst_limit = std::cmp::max(1,
(total_limit as f32 * burst_pct).floor() as usize); (total_limit as f32 * burst_pct).floor() as usize);
debug_assert!(burst_limit <= total_limit); debug_assert!(burst_limit <= total_limit);
VectorTokenBucket { VectorTokenBucket {
duration: duration, duration: duration,
total_limit: total_limit, total_limit: total_limit,
duration_overhead: duration_overhead, duration_overhead: duration_overhead,
burst_duration: burst_duration, burst_duration: burst_duration,
burst_limit: burst_limit, burst_limit: burst_limit,
timestamps: Mutex::new(VecDeque::with_capacity(total_limit)), timestamps: Mutex::new(VecDeque::with_capacity(total_limit)),
} }
} }
fn update_get_timestamps(&self) -> MutexGuard<VecDeque<Instant>> { fn update_get_timestamps(&self) -> MutexGuard<VecDeque<Instant>> {
let mut timestamps = self.timestamps.lock(); let mut timestamps = self.timestamps.lock();
let cutoff = Instant::now() - self.duration - self.duration_overhead; let cutoff = Instant::now() - self.duration - self.duration_overhead;
// We only need to trim the end of the queue to not leak memory. // We only need to trim the end of the queue to not leak memory.
// We could do it lazily somehow if we wanted to be really fancy. // We could do it lazily somehow if we wanted to be really fancy.
while timestamps.back().map_or(false, |ts| *ts < cutoff) { while timestamps.back().map_or(false, |ts| *ts < cutoff) {
timestamps.pop_back(); timestamps.pop_back();
} }
return timestamps; return timestamps;
} }
} }
impl TokenBucket for VectorTokenBucket { impl TokenBucket for VectorTokenBucket {
fn get_delay(&self) -> Option<Duration> { fn get_delay(&self) -> Option<Duration> {
let timestamps = self.update_get_timestamps(); let timestamps = self.update_get_timestamps();
// The "?" means: // The "?" means:
// `if timestamps.len() < self.total_limit { return None }` // `if timestamps.len() < self.total_limit { return None }`
// Timestamp that needs to be popped before // Timestamp that needs to be popped before
// we can enter another timestamp. // we can enter another timestamp.
// Full rate limit. // Full rate limit.
if let Some(ts) = timestamps.get(self.total_limit - 1) { if let Some(ts) = timestamps.get(self.total_limit - 1) {
// Return amount of time needed for timestamp `ts` to go away. // Return amount of time needed for timestamp `ts` to go away.
Instant::now().checked_duration_since(*ts) Instant::now().checked_duration_since(*ts)
.and_then(|passed_dur| (self.duration + self.duration_overhead) .and_then(|passed_dur| (self.duration + self.duration_overhead)
.checked_sub(passed_dur)) .checked_sub(passed_dur))
} }
// Otherwise burst rate limit. // Otherwise burst rate limit.
else if let Some(ts) = timestamps.get(self.burst_limit - 1) { else if let Some(ts) = timestamps.get(self.burst_limit - 1) {
// Return amount of time needed for timestamp `ts` to go away. // Return amount of time needed for timestamp `ts` to go away.
Instant::now().checked_duration_since(*ts) Instant::now().checked_duration_since(*ts)
.and_then(|passed_dur| self.burst_duration.checked_sub(passed_dur)) .and_then(|passed_dur| self.burst_duration.checked_sub(passed_dur))
} }
// No delay needed. // No delay needed.
else { else {
None None
} }
} }
fn get_tokens(&self, n: usize) -> bool { fn get_tokens(&self, n: usize) -> bool {
let mut timestamps = self.update_get_timestamps(); let mut timestamps = self.update_get_timestamps();
let now = Instant::now(); let now = Instant::now();
timestamps.reserve(n); timestamps.reserve(n);
for _ in 0..n { for _ in 0..n {
timestamps.push_front(now); timestamps.push_front(now);
} }
timestamps.len() <= self.total_limit timestamps.len() <= self.total_limit
} }
fn get_bucket_duration(&self) -> Duration { fn get_bucket_duration(&self) -> Duration {
self.duration self.duration
} }
fn get_total_limit(&self) -> usize { fn get_total_limit(&self) -> usize {
self.total_limit self.total_limit
} }
} }
impl fmt::Debug for VectorTokenBucket { impl fmt::Debug for VectorTokenBucket {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "({}/{}:{})", self.timestamps.lock().len(), self.total_limit, self.duration.as_secs()) write!(f, "({}/{}:{})", self.timestamps.lock().len(), self.total_limit, self.duration.as_secs())
} }
} }

View file

@ -1,110 +1,110 @@
#![cfg(test)] #![cfg(test)]
use fake_instant::FakeClock as Instant; use fake_instant::FakeClock as Instant;
/// This is a hack to test token bucket, substituting FakeClock for Instant. /// This is a hack to test token bucket, substituting FakeClock for Instant.
mod token_bucket { mod token_bucket {
include!("token_bucket.rs"); include!("token_bucket.rs");
mod tests { mod tests {
use super::*; use super::*;
use lazy_static::lazy_static; use lazy_static::lazy_static;
lazy_static! { lazy_static! {
pub static ref D00: Duration = Duration::new(0, 0); pub static ref D00: Duration = Duration::new(0, 0);
} }
#[test] #[test]
fn test_basic() { fn test_basic() {
Instant::set_time(50_000); Instant::set_time(50_000);
let bucket = VectorTokenBucket::new(Duration::from_millis(1000), 100, *D00, 0.95); let bucket = VectorTokenBucket::new(Duration::from_millis(1000), 100, *D00, 0.95);
assert!(bucket.get_tokens(50), "Should have not violated limit."); assert!(bucket.get_tokens(50), "Should have not violated limit.");
assert_eq!(None, bucket.get_delay(), "Can get stuff."); assert_eq!(None, bucket.get_delay(), "Can get stuff.");
assert!(!bucket.get_tokens(51), "Should have violated limit."); assert!(!bucket.get_tokens(51), "Should have violated limit.");
} }
#[test] #[test]
fn test_internal_constructor() { fn test_internal_constructor() {
let bucket = VectorTokenBucket::new(Duration::from_millis(1000), 100, *D00, 1.0); let bucket = VectorTokenBucket::new(Duration::from_millis(1000), 100, *D00, 1.0);
assert_eq!(100, bucket.burst_limit); assert_eq!(100, bucket.burst_limit);
let bucket = VectorTokenBucket::new(Duration::from_millis(1000), 100, *D00, 1e-6); let bucket = VectorTokenBucket::new(Duration::from_millis(1000), 100, *D00, 1e-6);
assert_eq!(1, bucket.burst_limit); assert_eq!(1, bucket.burst_limit);
} }
#[test] #[test]
fn test_saturated_100_burst() { fn test_saturated_100_burst() {
let bucket = VectorTokenBucket::new(Duration::from_millis(1000), 100, *D00, 1.00); let bucket = VectorTokenBucket::new(Duration::from_millis(1000), 100, *D00, 1.00);
Instant::set_time(50_000); Instant::set_time(50_000);
assert!(bucket.get_tokens(100), "All tokens should be immediately available."); assert!(bucket.get_tokens(100), "All tokens should be immediately available.");
assert_ne!(None, bucket.get_delay(), "Bucket should have delay."); assert_ne!(None, bucket.get_delay(), "Bucket should have delay.");
Instant::advance_time(1001); // Extra buffer for Duration(0). Instant::advance_time(1001); // Extra buffer for Duration(0).
assert!(bucket.get_tokens(100), "All tokens should be available after a bucket duration."); assert!(bucket.get_tokens(100), "All tokens should be available after a bucket duration.");
assert_ne!(None, bucket.get_delay(), "Bucket should have delay."); assert_ne!(None, bucket.get_delay(), "Bucket should have delay.");
} }
#[test] #[test]
fn test_saturated_95_burst() { fn test_saturated_95_burst() {
let bucket = VectorTokenBucket::new(Duration::from_millis(1000), 100, *D00, 0.50); let bucket = VectorTokenBucket::new(Duration::from_millis(1000), 100, *D00, 0.50);
Instant::set_time(50_000); Instant::set_time(50_000);
assert!(bucket.get_tokens(95), "95 tokens should be immediately available."); assert!(bucket.get_tokens(95), "95 tokens should be immediately available.");
assert_ne!(None, bucket.get_delay(), "Bucket should have delay."); assert_ne!(None, bucket.get_delay(), "Bucket should have delay.");
Instant::advance_time(475); // Total 951. Instant::advance_time(475); // Total 951.
assert_ne!(None, bucket.get_delay(), "Bucket should have delay."); assert_ne!(None, bucket.get_delay(), "Bucket should have delay.");
Instant::advance_time(476); // Extra buffer for Duration(0). Instant::advance_time(476); // Extra buffer for Duration(0).
assert!(bucket.get_tokens(5), "Last 5 tokens should be available."); assert!(bucket.get_tokens(5), "Last 5 tokens should be available.");
assert_ne!(None, bucket.get_delay(), "Bucket should have delay."); assert_ne!(None, bucket.get_delay(), "Bucket should have delay.");
Instant::advance_time(51); Instant::advance_time(51);
assert!(bucket.get_tokens(95), "95 tokens should be available."); assert!(bucket.get_tokens(95), "95 tokens should be available.");
assert_ne!(None, bucket.get_delay(), "Bucket should have delay."); assert_ne!(None, bucket.get_delay(), "Bucket should have delay.");
Instant::advance_time(951); Instant::advance_time(951);
assert!(bucket.get_tokens(5), "Last 5 tokens should be available."); assert!(bucket.get_tokens(5), "Last 5 tokens should be available.");
assert_ne!(None, bucket.get_delay(), "Bucket should have delay."); assert_ne!(None, bucket.get_delay(), "Bucket should have delay.");
} }
#[test] #[test]
fn test_saturated_50_burst() { fn test_saturated_50_burst() {
let bucket = VectorTokenBucket::new(Duration::from_millis(1000), 100, *D00, 0.5); let bucket = VectorTokenBucket::new(Duration::from_millis(1000), 100, *D00, 0.5);
Instant::set_time(50_000); Instant::set_time(50_000);
assert!(bucket.get_tokens(50), "Half the tokens should be immediately available."); assert!(bucket.get_tokens(50), "Half the tokens should be immediately available.");
assert_ne!(None, bucket.get_delay(), "Bucket should have delay."); assert_ne!(None, bucket.get_delay(), "Bucket should have delay.");
Instant::advance_time(501); // Extra buffer for Duration(0). Instant::advance_time(501); // Extra buffer for Duration(0).
assert!(bucket.get_tokens(50), "Half the tokens should be available after a half bucket duration."); assert!(bucket.get_tokens(50), "Half the tokens should be available after a half bucket duration.");
assert_ne!(None, bucket.get_delay(), "Bucket should have delay."); assert_ne!(None, bucket.get_delay(), "Bucket should have delay.");
Instant::advance_time(501); Instant::advance_time(501);
assert!(bucket.get_tokens(50), "Half the tokens should be available after a full bucket duration."); assert!(bucket.get_tokens(50), "Half the tokens should be available after a full bucket duration.");
assert_ne!(None, bucket.get_delay(), "Bucket should have delay."); assert_ne!(None, bucket.get_delay(), "Bucket should have delay.");
Instant::advance_time(501); Instant::advance_time(501);
assert!(bucket.get_tokens(50)); assert!(bucket.get_tokens(50));
assert_ne!(None, bucket.get_delay(), "Bucket should have delay."); assert_ne!(None, bucket.get_delay(), "Bucket should have delay.");
} }
#[test] #[test]
fn test_many() { fn test_many() {
Instant::set_time(50_000); Instant::set_time(50_000);
let bucket = VectorTokenBucket::new(Duration::from_millis(1000), 100, *D00, 0.95); let bucket = VectorTokenBucket::new(Duration::from_millis(1000), 100, *D00, 0.95);
assert!(bucket.get_tokens(50), "Should have not violated limit."); assert!(bucket.get_tokens(50), "Should have not violated limit.");
assert_eq!(None, bucket.get_delay(), "Should not be blocked."); assert_eq!(None, bucket.get_delay(), "Should not be blocked.");
for _ in 0..20_000 { for _ in 0..20_000 {
Instant::advance_time(501); Instant::advance_time(501);
assert!(bucket.get_tokens(50), "Should have not violated limit."); assert!(bucket.get_tokens(50), "Should have not violated limit.");
assert_ne!(None, bucket.get_delay(), "Bucket should have delay."); assert_ne!(None, bucket.get_delay(), "Bucket should have delay.");
Instant::advance_time(501); Instant::advance_time(501);
assert!(bucket.get_tokens(50), "Should have not violated limit."); assert!(bucket.get_tokens(50), "Should have not violated limit.");
assert_ne!(None, bucket.get_delay(), "Bucket should have delay."); assert_ne!(None, bucket.get_delay(), "Bucket should have delay.");
} }
assert!(bucket.timestamps.lock().len() < 110, "Check memory leak."); assert!(bucket.timestamps.lock().len() < 110, "Check memory leak.");
} }
} }
} }

View file

@ -1,180 +1,180 @@
use std::future::Future; use std::future::Future;
use std::sync::Arc; use std::sync::Arc;
use log; use log;
use reqwest::{ Client, RequestBuilder, Method }; use reqwest::{ Client, RequestBuilder, Method };
use crate::Result; use crate::Result;
use crate::ResponseInfo; use crate::ResponseInfo;
use crate::RiotApiConfig; use crate::RiotApiConfig;
use crate::RiotApiError; use crate::RiotApiError;
use crate::req::RegionalRequester; use crate::req::RegionalRequester;
use crate::util::InsertOnlyCHashMap; use crate::util::InsertOnlyCHashMap;
/// For retrieving data from the Riot Games API. /// For retrieving data from the Riot Games API.
/// ///
/// # Usage /// # Usage
/// ///
/// Construct an instance using [`with_key(api_key)`](RiotApi::with_key) or /// Construct an instance using [`with_key(api_key)`](RiotApi::with_key) or
/// [`with_config(config)`](RiotApi::with_config). /// [`with_config(config)`](RiotApi::with_config).
/// ///
/// An instance provides access to "endpoint handles" which in turn provide access /// An instance provides access to "endpoint handles" which in turn provide access
/// to individual API method calls. For example, getting a summoner by name: /// to individual API method calls. For example, getting a summoner by name:
/// ```ignore /// ```ignore
/// riot_api.summoner_v4().get_by_summoner_name(Region::NA, "LugnutsK") /// riot_api.summoner_v4().get_by_summoner_name(Region::NA, "LugnutsK")
/// ``` /// ```
/// ///
/// # Rate Limiting /// # Rate Limiting
/// ///
/// The Riot Game API enforces _dynamic_ rate limiting, meaning that rate limits are /// The Riot Game API enforces _dynamic_ rate limiting, meaning that rate limits are
/// specified in response headers and (theoretically) could change at any time. /// specified in response headers and (theoretically) could change at any time.
/// Riven keeps track of changing rate limits seamlessly, preventing you from /// Riven keeps track of changing rate limits seamlessly, preventing you from
/// getting blacklisted. /// getting blacklisted.
/// ///
/// Riven's rate limiting is highly efficient, meaning that it can reach the limits /// Riven's rate limiting is highly efficient, meaning that it can reach the limits
/// of your rate limit without going over. /// of your rate limit without going over.
/// ///
/// To adjust rate limiting, see [RiotApiConfig](crate::RiotApiConfig) and use /// To adjust rate limiting, see [RiotApiConfig](crate::RiotApiConfig) and use
/// [`with_config(config)`](RiotApi::with_config) to construct an instance. /// [`with_config(config)`](RiotApi::with_config) to construct an instance.
pub struct RiotApi { pub struct RiotApi {
/// Configuration settings. /// Configuration settings.
config: RiotApiConfig, config: RiotApiConfig,
/// Client for making requests. /// Client for making requests.
client: Client, client: Client,
/// Per-region requesters. /// Per-region requesters.
regional_requesters: InsertOnlyCHashMap<&'static str, RegionalRequester>, regional_requesters: InsertOnlyCHashMap<&'static str, RegionalRequester>,
} }
impl RiotApi { impl RiotApi {
/// Constructs a new instance from the given [RiotApiConfig](crate::RiotApiConfig), consuming it. /// Constructs a new instance from the given [RiotApiConfig](crate::RiotApiConfig), consuming it.
pub fn with_config(mut config: RiotApiConfig) -> Self { pub fn with_config(mut config: RiotApiConfig) -> Self {
let client_builder = config.client_builder.take() let client_builder = config.client_builder.take()
.expect("!NONE CLIENT_BUILDER IN CONFIG."); .expect("!NONE CLIENT_BUILDER IN CONFIG.");
Self { Self {
config: config, config: config,
client: client_builder.build().expect("Failed to create client from builder."), client: client_builder.build().expect("Failed to create client from builder."),
regional_requesters: InsertOnlyCHashMap::new(), regional_requesters: InsertOnlyCHashMap::new(),
} }
} }
/// Constructs a new instance from the given API key, using default configuration. /// Constructs a new instance from the given API key, using default configuration.
/// ///
/// `api_key` should be a Riot Games API key from /// `api_key` should be a Riot Games API key from
/// [https://developer.riotgames.com/](https://developer.riotgames.com/), /// [https://developer.riotgames.com/](https://developer.riotgames.com/),
/// and should look like `"RGAPI-01234567-89ab-cdef-0123-456789abcdef"`. /// and should look like `"RGAPI-01234567-89ab-cdef-0123-456789abcdef"`.
pub fn with_key(api_key: impl AsRef<[u8]>) -> Self { pub fn with_key(api_key: impl AsRef<[u8]>) -> Self {
Self::with_config(RiotApiConfig::with_key(api_key)) Self::with_config(RiotApiConfig::with_key(api_key))
} }
/// This method should generally not be used directly. Consider using endpoint wrappers instead. /// This method should generally not be used directly. Consider using endpoint wrappers instead.
/// ///
/// Creates a `RequestBuilder` instance with the given parameters, for use with the `execute*()` methods. /// Creates a `RequestBuilder` instance with the given parameters, for use with the `execute*()` methods.
/// ///
/// # Parameters /// # Parameters
/// * `method` - The HTTP method for this request. /// * `method` - The HTTP method for this request.
/// * `region_platform` - The stringified platform, used to create the base URL. /// * `region_platform` - The stringified platform, used to create the base URL.
/// * `path` - The URL path, appended to the base URL. /// * `path` - The URL path, appended to the base URL.
pub fn request(&self, method: Method, region_platform: &str, path: &str) -> RequestBuilder { pub fn request(&self, method: Method, region_platform: &str, path: &str) -> RequestBuilder {
let base_url_platform = self.config.base_url.replace("{}", region_platform); let base_url_platform = self.config.base_url.replace("{}", region_platform);
self.client.request(method, format!("{}{}", base_url_platform, path)) self.client.request(method, format!("{}{}", base_url_platform, path))
} }
/// This method should generally not be used directly. Consider using endpoint wrappers instead. /// This method should generally not be used directly. Consider using endpoint wrappers instead.
/// ///
/// This sends a request based on the given parameters and returns a parsed result. /// This sends a request based on the given parameters and returns a parsed result.
/// ///
/// # Parameters /// # Parameters
/// * `method_id` - A unique string id representing the endpoint method for per-method rate limiting. /// * `method_id` - A unique string id representing the endpoint method for per-method rate limiting.
/// * `region_platform` - The stringified platform, used in rate limiting. /// * `region_platform` - The stringified platform, used in rate limiting.
/// * `request` - The request information. Use `request()` to obtain a `RequestBuilder` instance. /// * `request` - The request information. Use `request()` to obtain a `RequestBuilder` instance.
/// ///
/// # Returns /// # Returns
/// A future resolving to a `Result` containg either a `T` (success) or a `RiotApiError` (failure). /// A future resolving to a `Result` containg either a `T` (success) or a `RiotApiError` (failure).
pub async fn execute_val<'a, T: serde::de::DeserializeOwned + 'a>(&'a self, pub async fn execute_val<'a, T: serde::de::DeserializeOwned + 'a>(&'a self,
method_id: &'static str, region_platform: &'static str, request: RequestBuilder) method_id: &'static str, region_platform: &'static str, request: RequestBuilder)
-> Result<T> -> Result<T>
{ {
let rinfo = self.execute_raw(method_id, region_platform, request).await?; let rinfo = self.execute_raw(method_id, region_platform, request).await?;
let retries = rinfo.retries; let retries = rinfo.retries;
let status = rinfo.response.status(); let status = rinfo.response.status();
let value = rinfo.response.json::<T>().await; let value = rinfo.response.json::<T>().await;
value.map_err(|e| RiotApiError::new(e, retries, None, Some(status))) value.map_err(|e| RiotApiError::new(e, retries, None, Some(status)))
} }
/// This method should generally not be used directly. Consider using endpoint wrappers instead. /// This method should generally not be used directly. Consider using endpoint wrappers instead.
/// ///
/// This sends a request based on the given parameters and returns an optional parsed result. /// This sends a request based on the given parameters and returns an optional parsed result.
/// ///
/// # Parameters /// # Parameters
/// * `method_id` - A unique string id representing the endpoint method for per-method rate limiting. /// * `method_id` - A unique string id representing the endpoint method for per-method rate limiting.
/// * `region_platform` - The stringified platform, used in rate limiting. /// * `region_platform` - The stringified platform, used in rate limiting.
/// * `request` - The request information. Use `request()` to obtain a `RequestBuilder` instance. /// * `request` - The request information. Use `request()` to obtain a `RequestBuilder` instance.
/// ///
/// # Returns /// # Returns
/// A future resolving to a `Result` containg either a `Option<T>` (success) or a `RiotApiError` (failure). /// A future resolving to a `Result` containg either a `Option<T>` (success) or a `RiotApiError` (failure).
pub async fn execute_opt<'a, T: serde::de::DeserializeOwned + 'a>(&'a self, pub async fn execute_opt<'a, T: serde::de::DeserializeOwned + 'a>(&'a self,
method_id: &'static str, region_platform: &'static str, request: RequestBuilder) method_id: &'static str, region_platform: &'static str, request: RequestBuilder)
-> Result<Option<T>> -> Result<Option<T>>
{ {
let rinfo = self.execute_raw(method_id, region_platform, request).await?; let rinfo = self.execute_raw(method_id, region_platform, request).await?;
if rinfo.status_none { if rinfo.status_none {
return Ok(None); return Ok(None);
} }
let retries = rinfo.retries; let retries = rinfo.retries;
let status = rinfo.response.status(); let status = rinfo.response.status();
let value = rinfo.response.json::<Option<T>>().await; let value = rinfo.response.json::<Option<T>>().await;
value.map_err(|e| RiotApiError::new(e, retries, None, Some(status))) value.map_err(|e| RiotApiError::new(e, retries, None, Some(status)))
} }
/// This method should generally not be used directly. Consider using endpoint wrappers instead. /// This method should generally not be used directly. Consider using endpoint wrappers instead.
/// ///
/// This sends a request based on the given parameters but does not deserialize any response body. /// This sends a request based on the given parameters but does not deserialize any response body.
/// ///
/// # Parameters /// # Parameters
/// * `method_id` - A unique string id representing the endpoint method for per-method rate limiting. /// * `method_id` - A unique string id representing the endpoint method for per-method rate limiting.
/// * `region_platform` - The stringified platform, used in rate limiting. /// * `region_platform` - The stringified platform, used in rate limiting.
/// * `request` - The request information. Use `request()` to obtain a `RequestBuilder` instance. /// * `request` - The request information. Use `request()` to obtain a `RequestBuilder` instance.
/// ///
/// # Returns /// # Returns
/// A future resolving to a `Result` containg either `()` (success) or a `RiotApiError` (failure). /// A future resolving to a `Result` containg either `()` (success) or a `RiotApiError` (failure).
pub async fn execute(&self, pub async fn execute(&self,
method_id: &'static str, region_platform: &'static str, request: RequestBuilder) method_id: &'static str, region_platform: &'static str, request: RequestBuilder)
-> Result<()> -> Result<()>
{ {
let rinfo = self.execute_raw(method_id, region_platform, request).await?; let rinfo = self.execute_raw(method_id, region_platform, request).await?;
let retries = rinfo.retries; let retries = rinfo.retries;
let status = rinfo.response.status(); let status = rinfo.response.status();
rinfo.response.error_for_status() rinfo.response.error_for_status()
.map(|_| ()) .map(|_| ())
.map_err(|e| RiotApiError::new(e, retries, None, Some(status))) .map_err(|e| RiotApiError::new(e, retries, None, Some(status)))
} }
/// This method should generally not be used directly. Consider using endpoint wrappers instead. /// This method should generally not be used directly. Consider using endpoint wrappers instead.
/// ///
/// This sends a request based on the given parameters and returns a raw `ResponseInfo`. /// This sends a request based on the given parameters and returns a raw `ResponseInfo`.
/// ///
/// This can be used to implement a Riot API proxy without needing to deserialize and reserialize JSON responses. /// This can be used to implement a Riot API proxy without needing to deserialize and reserialize JSON responses.
/// ///
/// # Parameters /// # Parameters
/// * `method_id` - A unique string id representing the endpoint method for per-method rate limiting. /// * `method_id` - A unique string id representing the endpoint method for per-method rate limiting.
/// * `region_platform` - The stringified platform, used in rate limiting. /// * `region_platform` - The stringified platform, used in rate limiting.
/// * `request` - The request information. Use `request()` to obtain a `RequestBuilder` instance. /// * `request` - The request information. Use `request()` to obtain a `RequestBuilder` instance.
/// ///
/// # Returns /// # Returns
/// A future resolving to a `Result` containg either a `ResponseInfo` (success) or a `RiotApiError` (failure). /// A future resolving to a `Result` containg either a `ResponseInfo` (success) or a `RiotApiError` (failure).
pub fn execute_raw(&self, method_id: &'static str, region_platform: &'static str, request: RequestBuilder) pub fn execute_raw(&self, method_id: &'static str, region_platform: &'static str, request: RequestBuilder)
-> impl Future<Output = Result<ResponseInfo>> + '_ -> impl Future<Output = Result<ResponseInfo>> + '_
{ {
self.regional_requester(region_platform) self.regional_requester(region_platform)
.execute(&self.config, method_id, request) .execute(&self.config, method_id, request)
} }
/// Get or create the RegionalRequester for the given region. /// Get or create the RegionalRequester for the given region.
fn regional_requester(&self, region_platform: &'static str) -> Arc<RegionalRequester> { fn regional_requester(&self, region_platform: &'static str) -> Arc<RegionalRequester> {
self.regional_requesters.get_or_insert_with(region_platform, || { self.regional_requesters.get_or_insert_with(region_platform, || {
log::debug!("Creating requester for region platform {}.", region_platform); log::debug!("Creating requester for region platform {}.", region_platform);
RegionalRequester::new() RegionalRequester::new()
}) })
} }
} }

View file

@ -1,36 +1,36 @@
// use std::borrow::Borrow; // use std::borrow::Borrow;
use std::collections::HashMap; use std::collections::HashMap;
use std::hash::Hash; use std::hash::Hash;
use std::sync::Arc; use std::sync::Arc;
use parking_lot::Mutex; use parking_lot::Mutex;
pub struct InsertOnlyCHashMap<K: Hash + Eq, V> { pub struct InsertOnlyCHashMap<K: Hash + Eq, V> {
base: Mutex<HashMap<K, Arc<V>>>, base: Mutex<HashMap<K, Arc<V>>>,
} }
impl<K: Hash + Eq, V> InsertOnlyCHashMap<K, V> { impl<K: Hash + Eq, V> InsertOnlyCHashMap<K, V> {
#[inline] #[inline]
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
base: Mutex::new(HashMap::new()) base: Mutex::new(HashMap::new())
} }
} }
// #[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>
{ {
Arc::clone(self.base.lock() Arc::clone(self.base.lock()
.entry(key) .entry(key)
.or_insert_with(|| Arc::new(default()))) .or_insert_with(|| Arc::new(default())))
} }
} }

View file

@ -1,3 +1,3 @@
mod insert_only_chashmap; mod insert_only_chashmap;
pub use insert_only_chashmap::*; pub use insert_only_chashmap::*;

View file

@ -1,158 +1,158 @@
{{ {{
const dotUtils = require('./dotUtils.js'); const dotUtils = require('./dotUtils.js');
const champions = require('./.champion.json') const champions = require('./.champion.json')
.filter(({ id }) => id > 0) .filter(({ id }) => id > 0)
.sortBy(({ name }) => name); .sortBy(({ name }) => name);
const constName = name => dotUtils.changeCase.constantCase(name).replace(/[^_A-Z0-9]+/g, ''); const constName = name => dotUtils.changeCase.constantCase(name).replace(/[^_A-Z0-9]+/g, '');
const constNamePad = 12; const constNamePad = 12;
const hashFactor = 256; const hashFactor = 256;
const strHash = (str) => { const strHash = (str) => {
let h = 0; let h = 0;
for (let c of str) for (let c of str)
h = hashFactor * h + c.charCodeAt(0); h = hashFactor * h + c.charCodeAt(0);
return h; return h;
}; };
}}{{= dotUtils.preamble() }} }}{{= dotUtils.preamble() }}
use serde::{ Serialize, Deserialize }; use serde::{ Serialize, Deserialize };
/// League of Legends champions. /// League of Legends champions.
/// ///
/// The documentation of each const field specifies:<br> /// The documentation of each const field specifies:<br>
/// NAME (`IDENTIFIER`, ID). /// NAME (`IDENTIFIER`, ID).
/// ///
/// Implements [IntoEnumIterator](super::IntoEnumIterator). /// Implements [IntoEnumIterator](super::IntoEnumIterator).
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[derive(PartialEq, Eq, PartialOrd, Ord)] #[derive(PartialEq, Eq, PartialOrd, Ord)]
#[serde(transparent)] #[serde(transparent)]
#[repr(transparent)] #[repr(transparent)]
pub struct Champion(pub i16); pub struct Champion(pub i16);
impl Champion { impl Champion {
{{ {{
for (let { id, alias, name } of champions) { for (let { id, alias, name } of champions) {
}} }}
/// {{= name }} (`{{= alias }}`, {{= id }}). /// {{= name }} (`{{= alias }}`, {{= id }}).
pub const {{= constName(name) }}: Self = Self({{= id }}); pub const {{= constName(name) }}: Self = Self({{= id }});
{{ {{
} }
}} }}
pub const fn is_known(self) -> bool { pub const fn is_known(self) -> bool {
match self { match self {
{{ {{
for (let { name, alias } of champions) { for (let { name, alias } of champions) {
}} }}
Self::{{= constName(name).padEnd(constNamePad) }} => true, Self::{{= constName(name).padEnd(constNamePad) }} => true,
{{ {{
} }
}} }}
_ => false, _ => false,
} }
} }
/// The champion's name (`en_US` localization). /// The champion's name (`en_US` localization).
pub const fn name(self) -> Option<&'static str> { pub const fn name(self) -> Option<&'static str> {
match self { match self {
{{ {{
for (let { name } of champions) { for (let { name } of champions) {
}} }}
Self::{{= constName(name).padEnd(constNamePad) }} => Some("{{= name }}"), Self::{{= constName(name).padEnd(constNamePad) }} => Some("{{= name }}"),
{{ {{
} }
}} }}
_ => None, _ => None,
} }
} }
/// The champion's identifier key. Somtimes called "key", "identifier", or "alias". /// The champion's identifier key. Somtimes called "key", "identifier", or "alias".
/// This is mainly used in DDragon paths. /// This is mainly used in DDragon paths.
/// ///
/// This is generally the `en_US` name with spaces and punctuation removed, /// This is generally the `en_US` name with spaces and punctuation removed,
/// capitalization preserved, however the follow are exceptions: /// capitalization preserved, however the follow are exceptions:
/// ///
/// Field | Name | Identifier /// Field | Name | Identifier
/// --------|------|----------- /// --------|------|-----------
{{ {{
for (let { name, alias } of champions) { for (let { name, alias } of champions) {
if (name.replace(/[^a-zA-Z0-9]+/, '') !== alias) { if (name.replace(/[^a-zA-Z0-9]+/, '') !== alias) {
}} }}
/// `{{= constName(name) }}` | "{{= name }}" | "{{= alias }}" /// `{{= constName(name) }}` | "{{= name }}" | "{{= alias }}"
{{ {{
} }
} }
}} }}
pub const fn identifier(self) -> Option<&'static str> { pub const fn identifier(self) -> Option<&'static str> {
match self { match self {
{{ {{
for (let { name, alias } of champions) { for (let { name, alias } of champions) {
}} }}
Self::{{= constName(name).padEnd(constNamePad) }} => Some("{{= alias }}"), Self::{{= constName(name).padEnd(constNamePad) }} => Some("{{= alias }}"),
{{ {{
} }
}} }}
_ => None, _ => None,
} }
} }
} }
impl std::str::FromStr for Champion { impl std::str::FromStr for Champion {
type Err = (); type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.chars() match s.chars()
.take(4) .take(4)
.filter(|c| c.is_ascii_alphanumeric()) .filter(|c| c.is_ascii_alphanumeric())
.fold(0_u32, |hash, next| hash * {{= hashFactor }} + u32::from(next)) .fold(0_u32, |hash, next| hash * {{= hashFactor }} + u32::from(next))
{ {
{{ {{
const keyStrings = (name, alias) => new Set([].concat(...[ name, alias ].map(s => s.toUpperCase()) const keyStrings = (name, alias) => new Set([].concat(...[ name, alias ].map(s => s.toUpperCase())
.map(s => [ .map(s => [
s.replace(/[^A-Z0-9]+/, '').substring(0, 4), s.replace(/[^A-Z0-9]+/, '').substring(0, 4),
s.split(/[^A-Z0-9]/, 1)[0].substring(0, 4), s.split(/[^A-Z0-9]/, 1)[0].substring(0, 4),
s.split(/[^A-Z]/, 1)[0].substring(0, 4), s.split(/[^A-Z]/, 1)[0].substring(0, 4),
]))); ])));
for (const { id, alias, name } of champions) { for (const { id, alias, name } of champions) {
for (const prefix of keyStrings(name, alias)) { for (const prefix of keyStrings(name, alias)) {
}} }}
0x{{= strHash(prefix).toString(16).padEnd(8) }} /* {{= prefix.padEnd(4) }} */ => Ok(Champion::{{= constName(name) }}), 0x{{= strHash(prefix).toString(16).padEnd(8) }} /* {{= prefix.padEnd(4) }} */ => Ok(Champion::{{= constName(name) }}),
{{ {{
} }
} }
}} }}
_ => Err(()), _ => Err(()),
} }
} }
} }
impl std::convert::TryFrom<&str> for Champion { impl std::convert::TryFrom<&str> for Champion {
type Error = <Self as std::str::FromStr>::Err; type Error = <Self as std::str::FromStr>::Err;
fn try_from(value: &str) -> Result<Self, Self::Error> { fn try_from(value: &str) -> Result<Self, Self::Error> {
<Self as std::str::FromStr>::from_str(value) <Self as std::str::FromStr>::from_str(value)
} }
} }
impl std::convert::From<i16> for Champion { impl std::convert::From<i16> for Champion {
fn from(value: i16) -> Self { fn from(value: i16) -> Self {
Self(value) Self(value)
} }
} }
impl std::convert::From<Champion> for i16 { impl std::convert::From<Champion> for i16 {
fn from(value: Champion) -> Self { fn from(value: Champion) -> Self {
value.0 value.0
} }
} }
impl std::fmt::Display for Champion { impl std::fmt::Display for Champion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f) self.0.fmt(f)
} }
} }
impl std::fmt::Debug for Champion { impl std::fmt::Debug for Champion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Champion({} {})", self.0, self.identifier().unwrap_or("UNKNOWN")) write!(f, "Champion({} {})", self.0, self.identifier().unwrap_or("UNKNOWN"))
} }
} }

View file

@ -1,29 +1,29 @@
{{ {{
const dotUtils = require('./dotUtils.js'); const dotUtils = require('./dotUtils.js');
const gameModes = require('./.gameModes.json'); const gameModes = require('./.gameModes.json');
}}{{= dotUtils.preamble() }} }}{{= dotUtils.preamble() }}
use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr }; use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr };
/// League of Legends game mode, such as Classic, /// League of Legends game mode, such as Classic,
/// ARAM, URF, One For All, Ascension, etc. /// ARAM, URF, One For All, Ascension, etc.
#[non_exhaustive] #[non_exhaustive]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash)] #[derive(Eq, PartialEq, Hash)]
#[derive(EnumString, Display, AsRefStr, IntoStaticStr)] #[derive(EnumString, Display, AsRefStr, IntoStaticStr)]
#[repr(u8)] #[repr(u8)]
pub enum GameMode { pub enum GameMode {
{{ {{
for (const e of gameModes) { for (const e of gameModes) {
const desc = e['x-desc'] ? e['x-desc'].split('\n') : []; const desc = e['x-desc'] ? e['x-desc'].split('\n') : [];
}} }}
{{~ desc :line }} {{~ desc :line }}
/// {{= line }} /// {{= line }}
{{~}} {{~}}
{{= e['x-name'] }}, {{= e['x-name'] }},
{{ {{
} }
}} }}
} }
serde_string!(GameMode); serde_string!(GameMode);

View file

@ -1,27 +1,27 @@
{{ {{
const dotUtils = require('./dotUtils.js'); const dotUtils = require('./dotUtils.js');
const gameTypes = require('./.gameTypes.json'); const gameTypes = require('./.gameTypes.json');
}}{{= dotUtils.preamble() }} }}{{= dotUtils.preamble() }}
use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr }; use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr };
/// League of Legends game type: matched game, custom game, or tutorial game. /// League of Legends game type: matched game, custom game, or tutorial game.
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash)] #[derive(Eq, PartialEq, Hash)]
#[derive(EnumString, Display, AsRefStr, IntoStaticStr)] #[derive(EnumString, Display, AsRefStr, IntoStaticStr)]
#[repr(u8)] #[repr(u8)]
pub enum GameType { pub enum GameType {
{{ {{
for (const e of gameTypes) { for (const e of gameTypes) {
const desc = e['x-desc'] ? e['x-desc'].split('\n') : []; const desc = e['x-desc'] ? e['x-desc'].split('\n') : [];
}} }}
{{~ desc :line }} {{~ desc :line }}
/// {{= line }} /// {{= line }}
{{~}} {{~}}
{{= e['x-name'] }}, {{= e['x-name'] }},
{{ {{
} }
}} }}
} }
serde_string!(GameType); serde_string!(GameType);

View file

@ -1,28 +1,28 @@
{{ {{
const dotUtils = require('./dotUtils.js'); const dotUtils = require('./dotUtils.js');
const maps = require('./.maps.json'); const maps = require('./.maps.json');
}}{{= dotUtils.preamble() }} }}{{= dotUtils.preamble() }}
use serde_repr::{ Serialize_repr, Deserialize_repr }; use serde_repr::{ Serialize_repr, Deserialize_repr };
use num_enum::{ IntoPrimitive, TryFromPrimitive }; use num_enum::{ IntoPrimitive, TryFromPrimitive };
/// League of Legends maps. /// League of Legends maps.
#[non_exhaustive] #[non_exhaustive]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash, PartialOrd, Ord)] #[derive(Eq, PartialEq, Hash, PartialOrd, Ord)]
#[derive(Serialize_repr, Deserialize_repr)] #[derive(Serialize_repr, Deserialize_repr)]
#[derive(IntoPrimitive, TryFromPrimitive)] #[derive(IntoPrimitive, TryFromPrimitive)]
#[repr(u8)] #[repr(u8)]
pub enum Map { pub enum Map {
{{ {{
for (const e of maps) { for (const e of maps) {
const desc = e['x-desc'] ? e['x-desc'].split('\n') : []; const desc = e['x-desc'] ? e['x-desc'].split('\n') : [];
}} }}
{{~ desc :line }} {{~ desc :line }}
/// {{= line }} /// {{= line }}
{{~}} {{~}}
{{= e['x-name'] }} = {{= e['x-value'] }}, {{= e['x-name'] }} = {{= e['x-value'] }},
{{ {{
} }
}} }}
} }

View file

@ -1,32 +1,32 @@
{{ {{
const dotUtils = require('./dotUtils.js'); const dotUtils = require('./dotUtils.js');
const queues = require('./.queues.json'); const queues = require('./.queues.json');
}}{{= dotUtils.preamble() }} }}{{= dotUtils.preamble() }}
use serde_repr::{ Serialize_repr, Deserialize_repr }; use serde_repr::{ Serialize_repr, Deserialize_repr };
use num_enum::{ IntoPrimitive, TryFromPrimitive }; use num_enum::{ IntoPrimitive, TryFromPrimitive };
/// League of Legends matchmaking queue. /// League of Legends matchmaking queue.
#[non_exhaustive] #[non_exhaustive]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq)] #[derive(Eq, PartialEq)]
#[derive(Serialize_repr, Deserialize_repr)] #[derive(Serialize_repr, Deserialize_repr)]
#[derive(IntoPrimitive, TryFromPrimitive)] #[derive(IntoPrimitive, TryFromPrimitive)]
#[repr(u16)] #[repr(u16)]
pub enum Queue { pub enum Queue {
{{ {{
for (const e of queues) { for (const e of queues) {
const desc = e['x-desc'] ? e['x-desc'].split('\n') : []; const desc = e['x-desc'] ? e['x-desc'].split('\n') : [];
}} }}
{{~ desc :line }} {{~ desc :line }}
/// {{= line }} /// {{= line }}
{{~}} {{~}}
{{? e['x-deprecated'] }} {{? e['x-deprecated'] }}
/// {{= e.notes }} /// {{= e.notes }}
#[deprecated(note="{{= e.notes }}")] #[deprecated(note="{{= e.notes }}")]
{{?}} {{?}}
{{= e['x-name'] }} = {{= e['x-value'] }}, {{= e['x-name'] }} = {{= e['x-value'] }},
{{ {{
} }
}} }}
} }

View file

@ -1,28 +1,28 @@
{{ {{
const dotUtils = require('./dotUtils.js'); const dotUtils = require('./dotUtils.js');
const seasons = require('./.seasons.json'); const seasons = require('./.seasons.json');
}}{{= dotUtils.preamble() }} }}{{= dotUtils.preamble() }}
use serde_repr::{ Serialize_repr, Deserialize_repr }; use serde_repr::{ Serialize_repr, Deserialize_repr };
use num_enum::{ IntoPrimitive, TryFromPrimitive }; use num_enum::{ IntoPrimitive, TryFromPrimitive };
/// League of Legends matchmaking seasons. /// League of Legends matchmaking seasons.
#[non_exhaustive] #[non_exhaustive]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash, PartialOrd, Ord)] #[derive(Eq, PartialEq, Hash, PartialOrd, Ord)]
#[derive(Serialize_repr, Deserialize_repr)] #[derive(Serialize_repr, Deserialize_repr)]
#[derive(IntoPrimitive, TryFromPrimitive)] #[derive(IntoPrimitive, TryFromPrimitive)]
#[repr(u8)] #[repr(u8)]
pub enum Season { pub enum Season {
{{ {{
for (const e of seasons) { for (const e of seasons) {
const desc = e['x-desc'] ? e['x-desc'].split('\n') : []; const desc = e['x-desc'] ? e['x-desc'].split('\n') : [];
}} }}
{{~ desc :line }} {{~ desc :line }}
/// {{= line }} /// {{= line }}
{{~}} {{~}}
{{= e['x-name'] }} = {{= e['x-value'] }}, {{= e['x-name'] }} = {{= e['x-value'] }},
{{ {{
} }
}} }}
} }

View file

@ -1,160 +1,160 @@
const changeCase = require('change-case'); const changeCase = require('change-case');
// flatMap: https://gist.github.com/samgiles/762ee337dff48623e729 // flatMap: https://gist.github.com/samgiles/762ee337dff48623e729
// [B](f: (A) ⇒ [B]): [B] ; Although the types in the arrays aren't strict (: // [B](f: (A) ⇒ [B]): [B] ; Although the types in the arrays aren't strict (:
Array.prototype.flatMap = function(lambda) { Array.prototype.flatMap = function(lambda) {
return Array.prototype.concat.apply([], this.map(lambda)); return Array.prototype.concat.apply([], this.map(lambda));
}; };
Array.prototype.groupBy = function(lambda) { Array.prototype.groupBy = function(lambda) {
return Object.entries(this.reduce((agg, x) => { return Object.entries(this.reduce((agg, x) => {
const k = lambda(x); const k = lambda(x);
(agg[k] = agg[k] || []).push(x); (agg[k] = agg[k] || []).push(x);
return agg; return agg;
}, {})); }, {}));
}; };
Array.prototype.sortBy = function(lambda) { Array.prototype.sortBy = function(lambda) {
return this.sort((a, b) => { return this.sort((a, b) => {
const va = lambda(a); const va = lambda(a);
const vb = lambda(b); const vb = lambda(b);
if ((typeof va) !== (typeof vb)) if ((typeof va) !== (typeof vb))
throw Error(`Mismatched sort types: ${typeof va}, ${typeof vb}.`); throw Error(`Mismatched sort types: ${typeof va}, ${typeof vb}.`);
if (typeof va === 'number') if (typeof va === 'number')
return va - vb; return va - vb;
if (typeof va === 'string') if (typeof va === 'string')
return va.localeCompare(vb); return va.localeCompare(vb);
throw Error(`Unknown sort type: ${typeof va}.`); throw Error(`Unknown sort type: ${typeof va}.`);
}); });
}; };
function preamble() { function preamble() {
return `\ return `\
/////////////////////////////////////////////// ///////////////////////////////////////////////
// // // //
// ! // // ! //
// This file is automatically generated! // // This file is automatically generated! //
// Do not directly edit! // // Do not directly edit! //
// // // //
///////////////////////////////////////////////`; ///////////////////////////////////////////////`;
} }
function capitalize(input) { function capitalize(input) {
return input[0].toUpperCase() + input.slice(1); return input[0].toUpperCase() + input.slice(1);
} }
function decapitalize(input) { function decapitalize(input) {
return input[0].toLowerCase() + input.slice(1); return input[0].toLowerCase() + input.slice(1);
} }
function normalizeSchemaName(name) { function normalizeSchemaName(name) {
return name.replace(/DTO/ig, ''); return name.replace(/DTO/ig, '');
} }
function normalizeArgName(name) { function normalizeArgName(name) {
const tokens = name.split('_'); const tokens = name.split('_');
const argName = decapitalize(tokens.map(capitalize).join('')); const argName = decapitalize(tokens.map(capitalize).join(''));
return 'base' === argName ? 'Base' : argName; return 'base' === argName ? 'Base' : argName;
} }
function normalizePropName(propName) { function normalizePropName(propName) {
let out = changeCase.snakeCase(propName); let out = changeCase.snakeCase(propName);
if (/^\d/.test(out)) // No leading digits. if (/^\d/.test(out)) // No leading digits.
out = 'x' + out; out = 'x' + out;
if ('type' === out) if ('type' === out)
return 'r#' + out; return 'r#' + out;
return out; return out;
} }
function stringifyType(prop, { endpoint = null, optional = false, fullpath = true, owned = true }) { function stringifyType(prop, { endpoint = null, optional = false, fullpath = true, owned = true }) {
if (prop.anyOf) { if (prop.anyOf) {
prop = prop.anyOf[0]; prop = prop.anyOf[0];
} }
if (optional) { if (optional) {
return `Option<${stringifyType(prop, { endpoint, fullpath, owned })}>`; return `Option<${stringifyType(prop, { endpoint, fullpath, owned })}>`;
} }
let enumType = prop['x-enum']; let enumType = prop['x-enum'];
if (enumType && 'locale' !== enumType) if (enumType && 'locale' !== enumType)
return 'crate::consts::' + changeCase.pascalCase(enumType); return 'crate::consts::' + changeCase.pascalCase(enumType);
let refType = prop['$ref']; let refType = prop['$ref'];
if (refType) { if (refType) {
return (!endpoint ? '' : changeCase.snakeCase(endpoint) + '::') + return (!endpoint ? '' : changeCase.snakeCase(endpoint) + '::') +
normalizeSchemaName(refType.slice(refType.indexOf('.') + 1)); normalizeSchemaName(refType.slice(refType.indexOf('.') + 1));
} }
switch (prop.type) { switch (prop.type) {
case 'boolean': return 'bool'; case 'boolean': return 'bool';
case 'integer': return ('int32' === prop.format ? 'i32' : 'i64'); case 'integer': return ('int32' === prop.format ? 'i32' : 'i64');
case 'number': return ('float' === prop.format ? 'f32' : 'f64'); case 'number': return ('float' === prop.format ? 'f32' : 'f64');
case 'array': case 'array':
const subprop = stringifyType(prop.items, { endpoint, optional, fullpath, owned }); const subprop = stringifyType(prop.items, { endpoint, optional, fullpath, owned });
return (owned ? (fullpath ? 'std::vec::' : '') + `Vec<${subprop}>` : `&[${subprop}]`); return (owned ? (fullpath ? 'std::vec::' : '') + `Vec<${subprop}>` : `&[${subprop}]`);
case 'string': return (owned ? 'String' : '&str'); case 'string': return (owned ? 'String' : '&str');
case 'object': case 'object':
return 'std::collections::HashMap<' + stringifyType(prop['x-key'], { endpoint, optional, fullpath, owned }) + ', ' + return 'std::collections::HashMap<' + stringifyType(prop['x-key'], { endpoint, optional, fullpath, owned }) + ', ' +
stringifyType(prop.additionalProperties, { endpoint, optional, fullpath, owned }) + '>'; stringifyType(prop.additionalProperties, { endpoint, optional, fullpath, owned }) + '>';
default: return prop.type; default: return prop.type;
} }
} }
function formatJsonProperty(name) { function formatJsonProperty(name) {
return `#[serde(rename = "${name}")]`; return `#[serde(rename = "${name}")]`;
} }
function formatAddQueryParam(param) { function formatAddQueryParam(param) {
const k = `"${param.name}"`; const k = `"${param.name}"`;
const name = normalizePropName(param.name); const name = normalizePropName(param.name);
const condStart = param.required ? '' : `mut request = request; if let Some(${name}) = ${name} { `; const condStart = param.required ? '' : `mut request = request; if let Some(${name}) = ${name} { `;
const condEnd = param.required ? '' : ' }' const condEnd = param.required ? '' : ' }'
const prop = param.schema; const prop = param.schema;
switch (prop.type) { switch (prop.type) {
case 'array': return `let ${condStart}request = request.query(&*${name}.iter()` case 'array': return `let ${condStart}request = request.query(&*${name}.iter()`
+ `.map(|w| ( ${k}, w )).collect::<Vec<_>>());${condEnd}`; + `.map(|w| ( ${k}, w )).collect::<Vec<_>>());${condEnd}`;
case 'object': case 'object':
throw 'unsupported'; throw 'unsupported';
default: default:
return `let ${condStart}request = request.query(&[ (${k}, ${name}) ]);${condEnd}`; return `let ${condStart}request = request.query(&[ (${k}, ${name}) ]);${condEnd}`;
} }
} }
function formatAddHeaderParam(param) { function formatAddHeaderParam(param) {
const k = `"${param.name}"`; const k = `"${param.name}"`;
const name = changeCase.snakeCase(param.name); const name = changeCase.snakeCase(param.name);
const condStart = param.required ? '' : `mut request = request; if let Some(${name}) = ${name} { `; const condStart = param.required ? '' : `mut request = request; if let Some(${name}) = ${name} { `;
const condEnd = param.required ? '' : ' }' const condEnd = param.required ? '' : ' }'
const prop = param.schema; const prop = param.schema;
switch (prop.type) { switch (prop.type) {
case 'string': case 'string':
return `let ${condStart}request = request.header(${k}, ${name});${condEnd}`; return `let ${condStart}request = request.header(${k}, ${name});${condEnd}`;
case 'object': case 'object':
throw 'unsupported'; throw 'unsupported';
default: default:
return `let ${condStart}request = request.header(${k}, ${name}.to_string());${condEnd}`; return `let ${condStart}request = request.header(${k}, ${name}.to_string());${condEnd}`;
} }
} }
function formatRouteArgument(route, pathParams = []) { function formatRouteArgument(route, pathParams = []) {
if (!pathParams.length) if (!pathParams.length)
return `"${route}"`; return `"${route}"`;
route = route.replace(/\{\S+?\}/g, '{}'); route = route.replace(/\{\S+?\}/g, '{}');
const args = pathParams const args = pathParams
.map(({name}) => name) .map(({name}) => name)
.map(changeCase.snakeCase) .map(changeCase.snakeCase)
.join(', '); .join(', ');
return `&format!("${route}", ${args})`; return `&format!("${route}", ${args})`;
} }
module.exports = { module.exports = {
changeCase, changeCase,
preamble, preamble,
capitalize, capitalize,
decapitalize, decapitalize,
normalizeSchemaName, normalizeSchemaName,
normalizeArgName, normalizeArgName,
normalizePropName, normalizePropName,
stringifyType, stringifyType,
formatJsonProperty, formatJsonProperty,
formatAddQueryParam, formatAddQueryParam,
formatAddHeaderParam, formatAddHeaderParam,
formatRouteArgument, formatRouteArgument,
}; };

View file

@ -1,81 +1,81 @@
const util = require('util'); const util = require('util');
const fs = require('fs'); const fs = require('fs');
fs.readFileAsync = util.promisify(fs.readFile); fs.readFileAsync = util.promisify(fs.readFile);
fs.writeFileAsync = util.promisify(fs.writeFile); fs.writeFileAsync = util.promisify(fs.writeFile);
const req = require("request-promise-native"); const req = require("request-promise-native");
process.chdir(__dirname); process.chdir(__dirname);
const files = [ const files = [
[ [
'http://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/v1/champion-summary.json', 'http://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/v1/champion-summary.json',
'.champion.json' '.champion.json'
], ],
[ [
'http://www.mingweisamuel.com/riotapi-schema/openapi-3.0.0.json', 'http://www.mingweisamuel.com/riotapi-schema/openapi-3.0.0.json',
'.spec.json' '.spec.json'
], ],
[ [
'http://www.mingweisamuel.com/riotapi-schema/enums/seasons.json', 'http://www.mingweisamuel.com/riotapi-schema/enums/seasons.json',
'.seasons.json' '.seasons.json'
], ],
[ [
'http://www.mingweisamuel.com/riotapi-schema/enums/queues.json', 'http://www.mingweisamuel.com/riotapi-schema/enums/queues.json',
'.queues.json' '.queues.json'
], ],
[ [
'http://www.mingweisamuel.com/riotapi-schema/enums/gameTypes.json', 'http://www.mingweisamuel.com/riotapi-schema/enums/gameTypes.json',
'.gameTypes.json' '.gameTypes.json'
], ],
[ [
'http://www.mingweisamuel.com/riotapi-schema/enums/gameModes.json', 'http://www.mingweisamuel.com/riotapi-schema/enums/gameModes.json',
'.gameModes.json' '.gameModes.json'
], ],
[ [
'http://www.mingweisamuel.com/riotapi-schema/enums/maps.json', 'http://www.mingweisamuel.com/riotapi-schema/enums/maps.json',
'.maps.json' '.maps.json'
] ]
] ]
const downloadFilesPromise = Promise.all(files.map(([url, file]) => req(url) const downloadFilesPromise = Promise.all(files.map(([url, file]) => req(url)
.then(body => fs.writeFileAsync(file, body, "utf8")))); .then(body => fs.writeFileAsync(file, body, "utf8"))));
const doT = require('dot'); const doT = require('dot');
const glob = require('glob-promise'); const glob = require('glob-promise');
const log = a => { console.log(a); return a; }; const log = a => { console.log(a); return a; };
const suffix = '.dt'; const suffix = '.dt';
doT.templateSettings = { doT.templateSettings = {
evaluate: /\r?\n?\{\{([\s\S]+?)\}\}/g, evaluate: /\r?\n?\{\{([\s\S]+?)\}\}/g,
interpolate: /\r?\n?\{\{=([\s\S]+?)\}\}/g, interpolate: /\r?\n?\{\{=([\s\S]+?)\}\}/g,
encode: /\r?\n?\{\{!([\s\S]+?)\}\}/g, encode: /\r?\n?\{\{!([\s\S]+?)\}\}/g,
use: /\r?\n?\{\{#([\s\S]+?)\}\}/g, use: /\r?\n?\{\{#([\s\S]+?)\}\}/g,
define: /\r?\n?\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g, define: /\r?\n?\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g,
conditional: /\r?\n?\{\{\?(\?)?\s*([\s\S]*?)\s*\}\}/g, conditional: /\r?\n?\{\{\?(\?)?\s*([\s\S]*?)\s*\}\}/g,
iterate: /\r?\n?\{\{~\s*(?:\}\}|([\s\S]+?)\s*\:\s*([\w$]+)\s*(?:\:\s*([\w$]+))?\s*\}\})/g, iterate: /\r?\n?\{\{~\s*(?:\}\}|([\s\S]+?)\s*\:\s*([\w$]+)\s*(?:\:\s*([\w$]+))?\s*\}\})/g,
varname: 'it', varname: 'it',
strip: false, strip: false,
append: false, append: false,
selfcontained: false selfcontained: false
}; };
global.require = require; global.require = require;
downloadFilesPromise.then(() => glob.promise("**/*" + suffix, { ignore: ["**/node_modules/**"] })) downloadFilesPromise.then(() => glob.promise("**/*" + suffix, { ignore: ["**/node_modules/**"] }))
.then(files => Promise.all(files .then(files => Promise.all(files
.map(log) .map(log)
.map(file => fs.readFileAsync(file, "utf8") .map(file => fs.readFileAsync(file, "utf8")
.then(input => { .then(input => {
try { try {
return doT.template(input)({}); return doT.template(input)({});
} }
catch (e) { catch (e) {
console.error(`Error thrown while running "${file}":`, e); console.error(`Error thrown while running "${file}":`, e);
throw e; throw e;
} }
}) })
.then(output => fs.writeFileAsync("../src/" + file.slice(0, -suffix.length), output, "utf8")) .then(output => fs.writeFileAsync("../src/" + file.slice(0, -suffix.length), output, "utf8"))
) )
)) ))
.catch(console.error); .catch(console.error);

View file

@ -1,20 +1,20 @@
{ {
"name": "dot-gen", "name": "dot-gen",
"version": "0.0.0", "version": "0.0.0",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"change-case": "^3.1.0", "change-case": "^3.1.0",
"dot": "^1.1.3", "dot": "^1.1.3",
"glob": "^7.1.2", "glob": "^7.1.2",
"glob-promise": "^3.3.0", "glob-promise": "^3.3.0",
"request": "^2.88.0", "request": "^2.88.0",
"request-promise-native": "^1.0.7" "request-promise-native": "^1.0.7"
}, },
"devDependencies": {}, "devDependencies": {},
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"author": "", "author": "",
"license": "GPL-2.0" "license": "GPL-2.0"
} }

View file

@ -1,9 +1,9 @@
Tests are divided up by region. This is because tests cannot share state, and therefore Tests are divided up by region. This is because tests cannot share state, and therefore
cannot share the rate limiting done within a `RiotApi` instance. However, rate limiting cannot share the rate limiting done within a `RiotApi` instance. However, rate limiting
is separate for each region, so it is safe to send requests to different regions from is separate for each region, so it is safe to send requests to different regions from
different instances. different instances.
The tests within an individual file do share their `RiotApi` instance thanks to custom The tests within an individual file do share their `RiotApi` instance thanks to custom
test runners and some macros I hacked together which are located in `async_tests.rs`. test runners and some macros I hacked together which are located in `async_tests.rs`.
They are set up in a way to look like normal test output for fun and probably to They are set up in a way to look like normal test output for fun and probably to
confuse people. confuse people.

View file

@ -1,87 +1,87 @@
/// This is just a huge hack to make a test runner (with no test cases) /// This is just a huge hack to make a test runner (with no test cases)
/// look as if it's running a bunch of (async) test cases. /// look as if it's running a bunch of (async) test cases.
#[macro_export] #[macro_export]
macro_rules! async_tests { macro_rules! async_tests {
( $runner:ident { $( $name:ident : async $eval:block, )* } ) => { ( $runner:ident { $( $name:ident : async $eval:block, )* } ) => {
#[allow(dead_code)] #[allow(dead_code)]
fn $runner(_: &[()]) { fn $runner(_: &[()]) {
env_logger::init(); env_logger::init();
std::process::exit({ std::process::exit({
let rt = tokio::runtime::Runtime::new() let rt = tokio::runtime::Runtime::new()
.expect("Failed to create runtime."); .expect("Failed to create runtime.");
let (_, errs) = rt.block_on(async { let (_, errs) = rt.block_on(async {
println!(); println!();
println!("running tests"); println!("running tests");
println!(); println!();
let mut oks: u32 = 0; let mut oks: u32 = 0;
let mut errs: u32 = 0; let mut errs: u32 = 0;
$( $(
let $name = async { let $name = async {
let result: std::result::Result<(), String> = async { let result: std::result::Result<(), String> = async {
$eval $eval
}.await; }.await;
result result
}; };
let $name = tokio::spawn($name); let $name = tokio::spawn($name);
)* )*
$( $(
let $name = $name.await.expect("Failed to spawn."); let $name = $name.await.expect("Failed to spawn.");
)* )*
$( $(
print!("test {} ... ", stringify!($name)); print!("test {} ... ", stringify!($name));
match $name { match $name {
Ok(_) => { Ok(_) => {
println!("{}", "ok".green()); println!("{}", "ok".green());
oks += 1; oks += 1;
} }
Err(msg) => { Err(msg) => {
println!("{}", "error".bright_red()); println!("{}", "error".bright_red());
println!("{}", msg); println!("{}", msg);
errs += 1; errs += 1;
} }
} }
)* )*
println!(); println!();
print!("test result: {}. ", if errs > 0 { "error".bright_red() } else { "ok".green() }); print!("test result: {}. ", if errs > 0 { "error".bright_red() } else { "ok".green() });
println!("{} passed; {} failed; 0 ignored; 0 measured; 0 filtered out", oks, errs); println!("{} passed; {} failed; 0 ignored; 0 measured; 0 filtered out", oks, errs);
println!(); println!();
(oks, errs) (oks, errs)
}); });
// Just returns #errs as exit code. // Just returns #errs as exit code.
errs as i32 errs as i32
}); });
} }
}; };
} }
#[macro_export] #[macro_export]
macro_rules! rassert { macro_rules! rassert {
( $x:expr ) => { ( $x:expr ) => {
{ {
if $x { Ok(()) } else { Err(stringify!($x)) }? if $x { Ok(()) } else { Err(stringify!($x)) }?
} }
}; };
( $x:expr, $format:expr $(, $arg:expr)* ) => { ( $x:expr, $format:expr $(, $arg:expr)* ) => {
{ {
if $x { Ok(()) } else { Err( format!($format, $( $arg )* ) ) }? if $x { Ok(()) } else { Err( format!($format, $( $arg )* ) ) }?
} }
}; };
} }
#[macro_export] #[macro_export]
macro_rules! rassert_eq { macro_rules! rassert_eq {
( $a:expr, $b:expr ) => { rassert!($a == $b) }; ( $a:expr, $b:expr ) => { rassert!($a == $b) };
( $a:expr, $b:expr, $format:expr $(, $arg:expr)* ) => { ( $a:expr, $b:expr, $format:expr $(, $arg:expr)* ) => {
rassert!($a == $b, $format $(, $arg )* ) rassert!($a == $b, $format $(, $arg )* )
}; };
} }
#[macro_export] #[macro_export]
macro_rules! rassert_ne { macro_rules! rassert_ne {
( $a:expr, $b:expr ) => { rassert!($a != $b) }; ( $a:expr, $b:expr ) => { rassert!($a != $b) };
( $a:expr, $b:expr, $format:expr $(, $arg:expr)* ) => { ( $a:expr, $b:expr, $format:expr $(, $arg:expr)* ) => {
rassert!($a != $b, $format $(, $arg )* ) rassert!($a != $b, $format $(, $arg )* )
}; };
} }

View file

@ -1,76 +1,76 @@
#![cfg_attr(feature = "nightly", feature(custom_test_frameworks))] #![cfg_attr(feature = "nightly", feature(custom_test_frameworks))]
#![cfg_attr(feature = "nightly", test_runner(my_runner))] #![cfg_attr(feature = "nightly", test_runner(my_runner))]
mod async_tests; mod async_tests;
mod testutils; mod testutils;
use testutils::*; use testutils::*;
use colored::*; use colored::*;
use riven::consts::*; use riven::consts::*;
const ROUTE: PlatformRoute = PlatformRoute::EUW1; const ROUTE: PlatformRoute = PlatformRoute::EUW1;
async_tests!{ async_tests!{
my_runner { my_runner {
// Champion Mastery tests. // Champion Mastery tests.
championmastery_getscore_ma5tery: async { championmastery_getscore_ma5tery: async {
let sum = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, "ma5tery"); let sum = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, "ma5tery");
let sum = sum.await.map_err(|e| e.to_string())?.ok_or("Failed to get summoner".to_owned())?; let sum = sum.await.map_err(|e| e.to_string())?.ok_or("Failed to get summoner".to_owned())?;
let p = RIOT_API.champion_mastery_v4().get_champion_mastery_score(ROUTE, &*sum.id); let p = RIOT_API.champion_mastery_v4().get_champion_mastery_score(ROUTE, &*sum.id);
let s = p.await.map_err(|e| e.to_string())?; let s = p.await.map_err(|e| e.to_string())?;
rassert!(969 <= s && s <= 1000, "Unexpected ma5tery score: {}.", s); rassert!(969 <= s && s <= 1000, "Unexpected ma5tery score: {}.", s);
Ok(()) Ok(())
}, },
championmastery_getall_ma5tery: async { championmastery_getall_ma5tery: async {
let sum = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, "ma5tery"); let sum = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, "ma5tery");
let sum = sum.await.map_err(|e| e.to_string())?.ok_or("Failed to get summoner".to_owned())?; let sum = sum.await.map_err(|e| e.to_string())?.ok_or("Failed to get summoner".to_owned())?;
let p = RIOT_API.champion_mastery_v4().get_all_champion_masteries(ROUTE, &*sum.id); let p = RIOT_API.champion_mastery_v4().get_all_champion_masteries(ROUTE, &*sum.id);
let s = p.await.map_err(|e| e.to_string())?; let s = p.await.map_err(|e| e.to_string())?;
rassert!(s.len() >= 142, "Expected masteries: {}.", s.len()); rassert!(s.len() >= 142, "Expected masteries: {}.", s.len());
Ok(()) Ok(())
}, },
spectator_combo: async { spectator_combo: async {
let featured_p = RIOT_API.spectator_v4().get_featured_games(ROUTE); let featured_p = RIOT_API.spectator_v4().get_featured_games(ROUTE);
let featured = featured_p.await.map_err(|e| e.to_string())?; let featured = featured_p.await.map_err(|e| e.to_string())?;
rassert!(featured.game_list.len() > 0); rassert!(featured.game_list.len() > 0);
let summoner_name = &featured.game_list[0].participants[0].summoner_name; let summoner_name = &featured.game_list[0].participants[0].summoner_name;
let summoner_p = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, summoner_name); let summoner_p = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, summoner_name);
let summoner = summoner_p.await.map_err(|e| e.to_string())?.ok_or("Failed to get summoner".to_owned())?; let summoner = summoner_p.await.map_err(|e| e.to_string())?.ok_or("Failed to get summoner".to_owned())?;
let livegame_p = RIOT_API.spectator_v4().get_current_game_info_by_summoner(ROUTE, &summoner.id); let livegame_p = RIOT_API.spectator_v4().get_current_game_info_by_summoner(ROUTE, &summoner.id);
let livegame_o = livegame_p.await.map_err(|e| e.to_string())?; let livegame_o = livegame_p.await.map_err(|e| e.to_string())?;
if let Some(livegame) = livegame_o { if let Some(livegame) = livegame_o {
let participant_match = livegame.participants.iter().find(|p| p.summoner_name == *summoner_name); let participant_match = livegame.participants.iter().find(|p| p.summoner_name == *summoner_name);
rassert!(participant_match.is_some(), "Failed to find summoner in match: {}.", summoner_name); rassert!(participant_match.is_some(), "Failed to find summoner in match: {}.", summoner_name);
} }
Ok(()) Ok(())
}, },
// // TFT tests. // // TFT tests.
// tftleaguev1_getchallengerleague: async { // tftleaguev1_getchallengerleague: async {
// let p = RIOT_API.tft_league_v1().get_challenger_league(Region::EUW); // let p = RIOT_API.tft_league_v1().get_challenger_league(Region::EUW);
// let l = p.await.map_err(|e| e.to_string())?; // let l = p.await.map_err(|e| e.to_string())?;
// rassert!(l.entries.len() > 10, "Expected a few challenger players, got: {}.", l.entries.len()); // rassert!(l.entries.len() > 10, "Expected a few challenger players, got: {}.", l.entries.len());
// Ok(()) // Ok(())
// }, // },
// tftmatchv1_getmatch: async { // tftmatchv1_getmatch: async {
// let p = RIOT_API.tft_match_v1().get_match(Region::EUROPE, "EUW1_4568680990"); // let p = RIOT_API.tft_match_v1().get_match(Region::EUROPE, "EUW1_4568680990");
// let _m = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get TFT match.".to_owned())?; // let _m = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get TFT match.".to_owned())?;
// Ok(()) // Ok(())
// }, // },
// tftsummonerv1_getbyname: async { // tftsummonerv1_getbyname: async {
// let p = RIOT_API.tft_summoner_v1().get_by_summoner_name(Region::EUW, "相当猥琐"); // let p = RIOT_API.tft_summoner_v1().get_by_summoner_name(Region::EUW, "相当猥琐");
// let _s = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get TFT summoner.".to_owned())?; // let _s = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get TFT summoner.".to_owned())?;
// Ok(()) // Ok(())
// }, // },
// tftsummonerv1_getbyname_none: async { // tftsummonerv1_getbyname_none: async {
// let p = RIOT_API.tft_summoner_v1().get_by_summoner_name(Region::EUW, "this summoner does not exist"); // let p = RIOT_API.tft_summoner_v1().get_by_summoner_name(Region::EUW, "this summoner does not exist");
// rassert!(p.await.map_err(|e| e.to_string())?.is_none()); // rassert!(p.await.map_err(|e| e.to_string())?.is_none());
// Ok(()) // Ok(())
// }, // },
} }
} }

View file

@ -1,71 +1,71 @@
#![cfg_attr(feature = "nightly", feature(custom_test_frameworks))] #![cfg_attr(feature = "nightly", feature(custom_test_frameworks))]
#![cfg_attr(feature = "nightly", test_runner(my_runner))] #![cfg_attr(feature = "nightly", test_runner(my_runner))]
mod async_tests; mod async_tests;
mod testutils; mod testutils;
use testutils::*; use testutils::*;
use colored::*; use colored::*;
use riven::consts::*; use riven::consts::*;
const ROUTE: PlatformRoute = PlatformRoute::JP1; const ROUTE: PlatformRoute = PlatformRoute::JP1;
async_tests!{ async_tests!{
my_runner { my_runner {
// Summoner tests. // Summoner tests.
summoner_get_kanjikana: async { summoner_get_kanjikana: async {
let p = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, "私の 頭が かたい"); let p = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, "私の 頭が かたい");
let s = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get myheadhard".to_owned())?; let s = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get myheadhard".to_owned())?;
rassert_eq!("私の頭がかたい", s.name); rassert_eq!("私の頭がかたい", s.name);
Ok(()) Ok(())
}, },
// Failure cases. // Failure cases.
// // Make sure get_raw_response(...) with invalid path fails as expected. // // Make sure get_raw_response(...) with invalid path fails as expected.
// raw_response_invalid: async { // raw_response_invalid: async {
// let p = RIOT_API.get_raw_response("summoner-v4.getBySummonerName", Region::JP.into(), "INVALID/PATH".to_owned(), None); // let p = RIOT_API.get_raw_response("summoner-v4.getBySummonerName", Region::JP.into(), "INVALID/PATH".to_owned(), None);
// let r = p.await; // let r = p.await;
// rassert!(r.is_err()); // rassert!(r.is_err());
// Ok(()) // Ok(())
// }, // },
// summoner_v4().get_by_summoner_name(...) normally returns an option. // summoner_v4().get_by_summoner_name(...) normally returns an option.
// If we use `get` (instead of `get_optional`) make sure it errors. // If we use `get` (instead of `get_optional`) make sure it errors.
get_nonoptional_invalid: async { get_nonoptional_invalid: async {
let path_string = format!("/lol/summoner/v4/summoners/by-name/{}", "SUMMONER THAT DOES NOT EXIST"); let path_string = format!("/lol/summoner/v4/summoners/by-name/{}", "SUMMONER THAT DOES NOT EXIST");
let request = RIOT_API.request(reqwest::Method::GET, ROUTE.into(), &path_string); let request = RIOT_API.request(reqwest::Method::GET, ROUTE.into(), &path_string);
let p = RIOT_API.execute_val::<riven::models::summoner_v4::Summoner>( let p = RIOT_API.execute_val::<riven::models::summoner_v4::Summoner>(
"summoner-v4.getBySummonerName", ROUTE.into(), request); "summoner-v4.getBySummonerName", ROUTE.into(), request);
let r = p.await; let r = p.await;
rassert!(r.is_err()); rassert!(r.is_err());
Ok(()) Ok(())
}, },
// Make sure 403 is handled as expected. // Make sure 403 is handled as expected.
tournament_forbidden: async { tournament_forbidden: async {
let p = RIOT_API.tournament_v4().get_tournament_code(ROUTE.to_regional(), "INVALID_CODE"); let p = RIOT_API.tournament_v4().get_tournament_code(ROUTE.to_regional(), "INVALID_CODE");
let r = p.await; let r = p.await;
rassert!(r.is_err()); rassert!(r.is_err());
rassert_eq!(Some(reqwest::StatusCode::FORBIDDEN), r.unwrap_err().status_code()); rassert_eq!(Some(reqwest::StatusCode::FORBIDDEN), r.unwrap_err().status_code());
Ok(()) Ok(())
}, },
// tft-league-v1.getLeagueEntriesForSummoner // tft-league-v1.getLeagueEntriesForSummoner
// https://github.com/MingweiSamuel/Riven/issues/25 // https://github.com/MingweiSamuel/Riven/issues/25
tft_league_getleagueentriesforsummoner: async { tft_league_getleagueentriesforsummoner: async {
let sp = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, "Caihonbbt"); let sp = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, "Caihonbbt");
let sr = sp.await.map_err(|e| e.to_string())?.ok_or("Failed to get \"Caihonbbt\"".to_owned())?; let sr = sp.await.map_err(|e| e.to_string())?.ok_or("Failed to get \"Caihonbbt\"".to_owned())?;
let lp = RIOT_API.tft_league_v1().get_league_entries_for_summoner(ROUTE, &sr.id); let lp = RIOT_API.tft_league_v1().get_league_entries_for_summoner(ROUTE, &sr.id);
let lr = lp.await.map_err(|e| e.to_string())?; let lr = lp.await.map_err(|e| e.to_string())?;
rassert!(0 < lr.len()); rassert!(0 < lr.len());
Ok(()) Ok(())
}, },
// tft-league-v1.getTopRatedLadder // tft-league-v1.getTopRatedLadder
// https://github.com/MingweiSamuel/Riven/issues/24 // https://github.com/MingweiSamuel/Riven/issues/24
tft_league_gettopratedladder: async { tft_league_gettopratedladder: async {
let lp = RIOT_API.tft_league_v1().get_top_rated_ladder(ROUTE, QueueType::RANKED_TFT_TURBO); let lp = RIOT_API.tft_league_v1().get_top_rated_ladder(ROUTE, QueueType::RANKED_TFT_TURBO);
let lr = lp.await.map_err(|e| e.to_string())?; let lr = lp.await.map_err(|e| e.to_string())?;
rassert!(0 < lr.len()); rassert!(0 < lr.len());
Ok(()) Ok(())
}, },
} }
} }

View file

@ -1,60 +1,60 @@
#![cfg_attr(feature = "nightly", feature(custom_test_frameworks))] #![cfg_attr(feature = "nightly", feature(custom_test_frameworks))]
#![feature(async_closure)] #![feature(async_closure)]
#![cfg_attr(feature = "nightly", test_runner(my_runner))] #![cfg_attr(feature = "nightly", test_runner(my_runner))]
mod async_tests; mod async_tests;
mod testutils; mod testutils;
use testutils::*; use testutils::*;
use futures_util::future; use futures_util::future;
use colored::*; use colored::*;
use riven::consts::*; use riven::consts::*;
use riven::models::summoner_v4::Summoner; use riven::models::summoner_v4::Summoner;
const REGION: Region = Region::KR; const REGION: Region = Region::KR;
async_tests!{ async_tests!{
my_runner { my_runner {
league_summoner_bulk_test: async { league_summoner_bulk_test: async {
let leagues = (1..10) let leagues = (1..10)
.map(async move |i| { .map(async move |i| {
let leaguelist = RIOT_API.league_v4().get_league_entries(REGION, let leaguelist = RIOT_API.league_v4().get_league_entries(REGION,
QueueType::RANKED_SOLO_5x5, Tier::GOLD, Division::III, Some(i)); QueueType::RANKED_SOLO_5x5, Tier::GOLD, Division::III, Some(i));
let leaguelist = leaguelist.await let leaguelist = leaguelist.await
.map_err(|e| e.to_string())? .map_err(|e| e.to_string())?
.ok_or("Failed to get challenger league".to_owned())?; .ok_or("Failed to get challenger league".to_owned())?;
println!("League list {}: {} items.", i, leaguelist.len()); println!("League list {}: {} items.", i, leaguelist.len());
let summoners = leaguelist let summoners = leaguelist
.iter() .iter()
.map(async move |leagueentry| { .map(async move |leagueentry| {
let summonerfuture = RIOT_API.summoner_v4().get_by_summoner_id( let summonerfuture = RIOT_API.summoner_v4().get_by_summoner_id(
REGION, &leagueentry.summoner_id); REGION, &leagueentry.summoner_id);
summonerfuture.await summonerfuture.await
.map_err(|e| e.to_string())? .map_err(|e| e.to_string())?
.ok_or(format!("Failed to get summoner_id {}.", .ok_or(format!("Failed to get summoner_id {}.",
leagueentry.summoner_id)) leagueentry.summoner_id))
}); });
future::join_all(summoners).await future::join_all(summoners).await
.into_iter() .into_iter()
// I'm not sure where this result goes. // I'm not sure where this result goes.
.collect::<Result<Vec<Summoner>, String>>() .collect::<Result<Vec<Summoner>, String>>()
}); });
let all_summoners = future::join_all(leagues).await let all_summoners = future::join_all(leagues).await
.into_iter() .into_iter()
.flat_map(|league| league) .flat_map(|league| league)
.flat_map(|summoner| summoner); .flat_map(|summoner| summoner);
for (i, summoner) in all_summoners.enumerate() { for (i, summoner) in all_summoners.enumerate() {
println!("{}: {}", i + 1, summoner.name); println!("{}: {}", i + 1, summoner.name);
} }
Ok(()) Ok(())
}, },
} }
} }

View file

@ -1,154 +1,154 @@
#![cfg_attr(feature = "nightly", feature(custom_test_frameworks))] #![cfg_attr(feature = "nightly", feature(custom_test_frameworks))]
#![cfg_attr(feature = "nightly", test_runner(my_runner))] #![cfg_attr(feature = "nightly", test_runner(my_runner))]
mod async_tests; mod async_tests;
mod testutils; mod testutils;
use testutils::*; use testutils::*;
use colored::*; use colored::*;
use riven::consts::*; use riven::consts::*;
use riven::models::summoner_v4::*; use riven::models::summoner_v4::*;
fn validate_summoners(s1: Summoner, s2: Summoner) -> Result<(), String> { fn validate_summoners(s1: Summoner, s2: Summoner) -> Result<(), String> {
rassert_eq!(s1.name, s2.name, "Names didn't match {}.", ""); rassert_eq!(s1.name, s2.name, "Names didn't match {}.", "");
rassert_eq!(s1.id, s2.id, "SummonerId didn't match {}.", ""); rassert_eq!(s1.id, s2.id, "SummonerId didn't match {}.", "");
rassert_eq!(s1.account_id, s2.account_id, "AccountId didn't match {}.", ""); rassert_eq!(s1.account_id, s2.account_id, "AccountId didn't match {}.", "");
Ok(()) Ok(())
} }
const ROUTE: PlatformRoute = PlatformRoute::NA1; const ROUTE: PlatformRoute = PlatformRoute::NA1;
async_tests!{ async_tests!{
my_runner { my_runner {
// Summoner tests. // Summoner tests.
summoner_double: async { summoner_double: async {
let l1p = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, "lug nuts k"); let l1p = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, "lug nuts k");
let l2p = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, "lugnuts k"); let l2p = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, "lugnuts k");
let l1 = l1p.await.map_err(|e| e.to_string())?.ok_or("Failed to get l1".to_owned())?; let l1 = l1p.await.map_err(|e| e.to_string())?.ok_or("Failed to get l1".to_owned())?;
let l2 = l2p.await.map_err(|e| e.to_string())?.ok_or("Failed to get l2".to_owned())?; let l2 = l2p.await.map_err(|e| e.to_string())?.ok_or("Failed to get l2".to_owned())?;
validate_summoners(l1, l2)?; validate_summoners(l1, l2)?;
Ok(()) Ok(())
}, },
champion_getrotation: async { champion_getrotation: async {
let p = RIOT_API.champion_v3().get_champion_info(ROUTE); let p = RIOT_API.champion_v3().get_champion_info(ROUTE);
let d = p.await.map_err(|e| e.to_string())?; let d = p.await.map_err(|e| e.to_string())?;
let new_len = d.free_champion_ids_for_new_players.len(); let new_len = d.free_champion_ids_for_new_players.len();
let free_len = d.free_champion_ids.len(); let free_len = d.free_champion_ids.len();
let level = d.max_new_player_level; let level = d.max_new_player_level;
rassert!(new_len >= 10, "New len: {}", new_len); rassert!(new_len >= 10, "New len: {}", new_len);
rassert!(free_len >= 15, "Free len: {}", free_len); rassert!(free_len >= 15, "Free len: {}", free_len);
rassert_eq!(10, level, "New player level: {}", level); rassert_eq!(10, level, "New player level: {}", level);
Ok(()) Ok(())
}, },
leagueexp_get: async { leagueexp_get: async {
let p = RIOT_API.league_exp_v4().get_league_entries(ROUTE, QueueType::RANKED_SOLO_5x5, Tier::CHALLENGER, Division::I, None); let p = RIOT_API.league_exp_v4().get_league_entries(ROUTE, QueueType::RANKED_SOLO_5x5, Tier::CHALLENGER, Division::I, None);
let d = p.await.map_err(|e| e.to_string())?; let d = p.await.map_err(|e| e.to_string())?;
rassert!(!d.is_empty(), "Challenger shouldn't be empty."); rassert!(!d.is_empty(), "Challenger shouldn't be empty.");
Ok(()) Ok(())
}, },
matchlist_get: async { matchlist_get: async {
let sp = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, "haha yes"); let sp = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, "haha yes");
let s = sp.await.map_err(|e| e.to_string())?.ok_or("Failed to get \"haha yes\"".to_owned())?; let s = sp.await.map_err(|e| e.to_string())?.ok_or("Failed to get \"haha yes\"".to_owned())?;
let mp = RIOT_API.match_v4().get_matchlist(ROUTE, &s.account_id, None, Some(2500), None, None, Some(2600), None, None); let mp = RIOT_API.match_v4().get_matchlist(ROUTE, &s.account_id, None, Some(2500), None, None, Some(2600), None, None);
let m = mp.await.map_err(|e| e.to_string())?.ok_or("Failed to get matchlist".to_owned())?; let m = mp.await.map_err(|e| e.to_string())?.ok_or("Failed to get matchlist".to_owned())?;
rassert!(m.matches.len() > 0, "Matchlist should not be empty"); rassert!(m.matches.len() > 0, "Matchlist should not be empty");
Ok(()) Ok(())
}, },
matchlist_get2: async { matchlist_get2: async {
let sp = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, "haha yes"); let sp = RIOT_API.summoner_v4().get_by_summoner_name(ROUTE, "haha yes");
let s = sp.await.map_err(|e| e.to_string())?.ok_or("Failed to get \"haha yes\"".to_owned())?; let s = sp.await.map_err(|e| e.to_string())?.ok_or("Failed to get \"haha yes\"".to_owned())?;
let mp = RIOT_API.match_v4().get_matchlist(ROUTE, &s.account_id, None, None, Some(&[ Champion::SION, Champion::SIVIR, Champion::CASSIOPEIA ]), None, None, None, None); let mp = RIOT_API.match_v4().get_matchlist(ROUTE, &s.account_id, None, None, Some(&[ Champion::SION, Champion::SIVIR, Champion::CASSIOPEIA ]), None, None, None, None);
let m = mp.await.map_err(|e| e.to_string())?.ok_or("Failed to get matchlist".to_owned())?; let m = mp.await.map_err(|e| e.to_string())?.ok_or("Failed to get matchlist".to_owned())?;
rassert!(m.matches.len() > 0, "Matchlist should not be empty"); rassert!(m.matches.len() > 0, "Matchlist should not be empty");
Ok(()) Ok(())
}, },
match_get: async { match_get: async {
let p = RIOT_API.match_v4().get_match(ROUTE, 3190191338); let p = RIOT_API.match_v4().get_match(ROUTE, 3190191338);
let m = p.await.map_err(|e| e.to_string())?.ok_or("Match not found.".to_owned())?; let m = p.await.map_err(|e| e.to_string())?.ok_or("Match not found.".to_owned())?;
rassert!(!m.participants.is_empty(), "Match should have participants."); rassert!(!m.participants.is_empty(), "Match should have participants.");
Ok(()) Ok(())
}, },
match_get_bots: async { match_get_bots: async {
let p = RIOT_API.match_v4().get_match(ROUTE, 3251803350); let p = RIOT_API.match_v4().get_match(ROUTE, 3251803350);
let m = p.await.map_err(|e| e.to_string())?.ok_or("Match not found.".to_owned())?; let m = p.await.map_err(|e| e.to_string())?.ok_or("Match not found.".to_owned())?;
rassert!(!m.participants.is_empty(), "Match should have participants."); rassert!(!m.participants.is_empty(), "Match should have participants.");
Ok(()) Ok(())
}, },
match_get_odyssey: async { match_get_odyssey: async {
let p = RIOT_API.match_v4().get_match(ROUTE, 2881976826); let p = RIOT_API.match_v4().get_match(ROUTE, 2881976826);
let m = p.await.map_err(|e| e.to_string())?.ok_or("Match not found.".to_owned())?; let m = p.await.map_err(|e| e.to_string())?.ok_or("Match not found.".to_owned())?;
rassert!(!m.participants.is_empty(), "Match should have participants."); rassert!(!m.participants.is_empty(), "Match should have participants.");
Ok(()) Ok(())
}, },
match_get_aram: async { match_get_aram: async {
let p = RIOT_API.match_v4().get_match(ROUTE, 2961635718); let p = RIOT_API.match_v4().get_match(ROUTE, 2961635718);
let m = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get match.".to_owned())?; let m = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get match.".to_owned())?;
rassert!(!m.participants.is_empty(), "Match should have participants."); rassert!(!m.participants.is_empty(), "Match should have participants.");
Ok(()) Ok(())
}, },
match_get_aram2: async { match_get_aram2: async {
let p = RIOT_API.match_v4().get_match(ROUTE, 3596184782); let p = RIOT_API.match_v4().get_match(ROUTE, 3596184782);
let m = p.await.map_err(|e| e.to_string())?.ok_or("Match not found.".to_owned())?; let m = p.await.map_err(|e| e.to_string())?.ok_or("Match not found.".to_owned())?;
rassert!(!m.participants.is_empty(), "Match should have participants."); rassert!(!m.participants.is_empty(), "Match should have participants.");
Ok(()) Ok(())
}, },
match_get_urf900: async { match_get_urf900: async {
let p = RIOT_API.match_v4().get_match(ROUTE, 2963663381); let p = RIOT_API.match_v4().get_match(ROUTE, 2963663381);
let m = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get match.".to_owned())?; let m = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get match.".to_owned())?;
rassert!(!m.participants.is_empty(), "Match should have participants."); rassert!(!m.participants.is_empty(), "Match should have participants.");
Ok(()) Ok(())
}, },
match_get_tutorial1: async { match_get_tutorial1: async {
let p = RIOT_API.match_v4().get_match(ROUTE, 3432145099); let p = RIOT_API.match_v4().get_match(ROUTE, 3432145099);
let m = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get match.".to_owned())?; let m = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get match.".to_owned())?;
rassert!(!m.participants.is_empty(), "Match should have participants."); rassert!(!m.participants.is_empty(), "Match should have participants.");
Ok(()) Ok(())
}, },
match_get_tutorial2: async { match_get_tutorial2: async {
let p = RIOT_API.match_v4().get_match(ROUTE, 3432116214); let p = RIOT_API.match_v4().get_match(ROUTE, 3432116214);
let m = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get match.".to_owned())?; let m = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get match.".to_owned())?;
rassert!(!m.participants.is_empty(), "Match should have participants."); rassert!(!m.participants.is_empty(), "Match should have participants.");
Ok(()) Ok(())
}, },
match_get_tutorial3: async { match_get_tutorial3: async {
let p = RIOT_API.match_v4().get_match(ROUTE, 3432156790); let p = RIOT_API.match_v4().get_match(ROUTE, 3432156790);
let m = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get match.".to_owned())?; let m = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get match.".to_owned())?;
rassert!(!m.participants.is_empty(), "Match should have participants."); rassert!(!m.participants.is_empty(), "Match should have participants.");
Ok(()) Ok(())
}, },
match_gettimeline: async { match_gettimeline: async {
let p = RIOT_API.match_v4().get_match_timeline(ROUTE, 3190191338); let p = RIOT_API.match_v4().get_match_timeline(ROUTE, 3190191338);
let m = p.await.map_err(|e| e.to_string())?.ok_or("Match timeline not found.".to_owned())?; let m = p.await.map_err(|e| e.to_string())?.ok_or("Match timeline not found.".to_owned())?;
rassert!(!m.frames.is_empty(), "Match timeline should have frames."); rassert!(!m.frames.is_empty(), "Match timeline should have frames.");
Ok(()) Ok(())
}, },
// Commented out, requires special API key. // Commented out, requires special API key.
// // LOR // // LOR
// lor_ranked_get_leaderboards: async { // lor_ranked_get_leaderboards: async {
// let future = RIOT_API.lor_ranked_v1().get_leaderboards(Region::AMERICAS); // let future = RIOT_API.lor_ranked_v1().get_leaderboards(Region::AMERICAS);
// let _leaderboard = future.await.map_err(|e| e.to_string())?; // let _leaderboard = future.await.map_err(|e| e.to_string())?;
// Ok(()) // Ok(())
// }, // },
// CLASH // CLASH
clash_get_tournaments: async { clash_get_tournaments: async {
let p = RIOT_API.clash_v1().get_tournaments(ROUTE); let p = RIOT_API.clash_v1().get_tournaments(ROUTE);
let tours = p.await.map_err(|e| e.to_string())?; let tours = p.await.map_err(|e| e.to_string())?;
if let Some(tour0) = tours.first() { if let Some(tour0) = tours.first() {
let p = RIOT_API.clash_v1().get_tournament_by_id(ROUTE, tour0.id); let p = RIOT_API.clash_v1().get_tournament_by_id(ROUTE, tour0.id);
let tour1 = p.await.map_err(|e| e.to_string())?; let tour1 = p.await.map_err(|e| e.to_string())?;
assert_eq!(Some(tour0.id), tour1.map(|t| t.id)); assert_eq!(Some(tour0.id), tour1.map(|t| t.id));
} }
Ok(()) Ok(())
}, },
clash_get_team_by_id: async { clash_get_team_by_id: async {
let p = RIOT_API.clash_v1().get_team_by_id(ROUTE, "00000000-0000-0000-0000-000000000000"); let p = RIOT_API.clash_v1().get_team_by_id(ROUTE, "00000000-0000-0000-0000-000000000000");
let team = p.await.map_err(|e| e.to_string())?; let team = p.await.map_err(|e| e.to_string())?;
assert!(team.is_none()); assert!(team.is_none());
Ok(()) Ok(())
}, },
} }
} }

View file

@ -1,40 +1,40 @@
#![cfg_attr(feature = "nightly", feature(custom_test_frameworks))] #![cfg_attr(feature = "nightly", feature(custom_test_frameworks))]
#![cfg_attr(feature = "nightly", test_runner(my_runner))] #![cfg_attr(feature = "nightly", test_runner(my_runner))]
mod async_tests; mod async_tests;
mod testutils; mod testutils;
use testutils::RIOT_API; use testutils::RIOT_API;
use colored::*; use colored::*;
use riven::consts::*; use riven::consts::*;
use riven::models::summoner_v4::Summoner; use riven::models::summoner_v4::Summoner;
const ROUTE: PlatformRoute = PlatformRoute::TR1; const ROUTE: PlatformRoute = PlatformRoute::TR1;
async_tests!{ async_tests!{
my_runner { my_runner {
league_summoner_bulk_test: async { league_summoner_bulk_test: async {
let p = RIOT_API.league_v4().get_challenger_league(ROUTE, QueueType::RANKED_SOLO_5x5); let p = RIOT_API.league_v4().get_challenger_league(ROUTE, QueueType::RANKED_SOLO_5x5);
// let p = future_start(p); // let p = future_start(p);
let ll = p.await.map_err(|e| e.to_string())?; let ll = p.await.map_err(|e| e.to_string())?;
println!("{:?} Challenger {} entries.", ROUTE, ll.entries.len()); println!("{:?} Challenger {} entries.", ROUTE, ll.entries.len());
let sl = ll.entries.iter().take(50) let sl = ll.entries.iter().take(50)
.map(|entry| RIOT_API.summoner_v4().get_by_summoner_id(ROUTE, &entry.summoner_id)) .map(|entry| RIOT_API.summoner_v4().get_by_summoner_id(ROUTE, &entry.summoner_id))
.map(tokio::spawn) .map(tokio::spawn)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
for (i, s) in sl.into_iter().enumerate() { for (i, s) in sl.into_iter().enumerate() {
let summoner: Summoner = s.await let summoner: Summoner = s.await
.expect("tokio::spawn join error") .expect("tokio::spawn join error")
.map_err(|e| e.to_string())?; .map_err(|e| e.to_string())?;
println!("{}: {}", i + 1, summoner.name); println!("{}: {}", i + 1, summoner.name);
} }
Ok(()) Ok(())
}, },
} }
} }

View file

@ -1,23 +1,23 @@
#![allow(dead_code)] #![allow(dead_code)]
use lazy_static::lazy_static; use lazy_static::lazy_static;
use riven::{ RiotApi, RiotApiConfig }; use riven::{ RiotApi, RiotApiConfig };
lazy_static! { lazy_static! {
pub static ref RIOT_API: RiotApi = { pub static ref RIOT_API: RiotApi = {
let api_key = std::env::var("RGAPI_KEY").ok() let api_key = std::env::var("RGAPI_KEY").ok()
.or_else(|| std::fs::read_to_string("apikey.txt").ok()) .or_else(|| std::fs::read_to_string("apikey.txt").ok())
.expect("Failed to find RGAPI_KEY env var or apikey.txt."); .expect("Failed to find RGAPI_KEY env var or apikey.txt.");
RiotApi::with_config(RiotApiConfig::with_key(api_key.trim()) RiotApi::with_config(RiotApiConfig::with_key(api_key.trim())
.preconfig_burst()) .preconfig_burst())
}; };
} }
pub mod ids { pub mod ids {
pub const SUMMONER_ID_LUGNUTSK: &'static str = "SBM8Ubipo4ge2yj7bhEzL7yvV0C9Oc1XA2l6v5okGMA_nCw"; pub const SUMMONER_ID_LUGNUTSK: &'static str = "SBM8Ubipo4ge2yj7bhEzL7yvV0C9Oc1XA2l6v5okGMA_nCw";
pub const SUMMONER_ID_MA5TERY: &'static str = "IbC4uyFEEW3ZkZw6FZF4bViw3P1EynclAcI6-p-vCpI99Ec"; pub const SUMMONER_ID_MA5TERY: &'static str = "IbC4uyFEEW3ZkZw6FZF4bViw3P1EynclAcI6-p-vCpI99Ec";
pub const SUMMONER_ID_C9SNEAKY: &'static str = "ghHSdADqgxKwcRl_vWndx6wKiyZx0xKQv-LOhOcU5LU"; pub const SUMMONER_ID_C9SNEAKY: &'static str = "ghHSdADqgxKwcRl_vWndx6wKiyZx0xKQv-LOhOcU5LU";
pub const ACCOUNT_ID_C9SNEAKY: &'static str = "ML_CcLT94UUHp1iDvXOXCidfmzzPrk_Jbub1f_INhw"; pub const ACCOUNT_ID_C9SNEAKY: &'static str = "ML_CcLT94UUHp1iDvXOXCidfmzzPrk_Jbub1f_INhw";
pub const ACCOUNT_ID_LUGNUTSK: &'static str = "iheZF2uJ50S84Hfq6Ob8GNlJAUmBmac-EsEEWBJjD01q1jQ"; pub const ACCOUNT_ID_LUGNUTSK: &'static str = "iheZF2uJ50S84Hfq6Ob8GNlJAUmBmac-EsEEWBJjD01q1jQ";
} }