2024-01-21 03:40:41 +00:00
|
|
|
#![cfg_attr(rustfmt, rustfmt_skip)]
|
2021-07-02 06:16:59 +00:00
|
|
|
///////////////////////////////////////////////
|
|
|
|
// //
|
|
|
|
// ! //
|
|
|
|
// This file is automatically generated! //
|
|
|
|
// Do not directly edit! //
|
|
|
|
// //
|
|
|
|
///////////////////////////////////////////////
|
|
|
|
|
2019-11-03 20:04:25 +00:00
|
|
|
#![forbid(unsafe_code)]
|
2022-02-09 01:17:47 +00:00
|
|
|
#![deny(missing_docs)]
|
2019-11-03 20:04:25 +00:00
|
|
|
|
2021-07-02 06:16:59 +00:00
|
|
|
//! <h1 align="center">
|
|
|
|
//! Riven<br>
|
|
|
|
//! </h1>
|
|
|
|
//! <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://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>
|
2021-09-10 05:51:15 +00:00
|
|
|
//! <!--<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>-->
|
2021-07-02 06:16:59 +00:00
|
|
|
//! <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>
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! Rust Library for the [Riot Games API](https://developer.riotgames.com/).
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! 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
|
|
|
|
//! [Riot API Reference](https://developer.riotgames.com/api-methods/) ([Swagger](http://www.mingweisamuel.com/riotapi-schema/tool/)).
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-09-19 18:22:09 +00:00
|
|
|
//! # Design
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! * Fast, asynchronous, thread-safe.
|
2024-03-04 22:59:19 +00:00
|
|
|
//! * Automatically retries failed requests, configurable.
|
2021-09-10 05:51:15 +00:00
|
|
|
//! * Supports all endpoints, kept up-to-date using [riotapi-schema](https://github.com/MingweiSamuel/riotapi-schema).
|
2024-03-04 22:59:19 +00:00
|
|
|
//! * Can compile to Wasm for server-side or browser+proxy use.
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-09-19 18:22:09 +00:00
|
|
|
//! # Usage
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! ```rust
|
|
|
|
//! use riven::RiotApi;
|
|
|
|
//! use riven::consts::PlatformRoute;
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! // Enter tokio async runtime.
|
2021-09-09 21:54:02 +00:00
|
|
|
//! let rt = tokio::runtime::Runtime::new().unwrap();
|
2021-07-02 06:16:59 +00:00
|
|
|
//! rt.block_on(async {
|
|
|
|
//! // Create RiotApi instance from key string.
|
2021-09-09 21:54:02 +00:00
|
|
|
//! let api_key = std::env!("RGAPI_KEY"); // "RGAPI-01234567-89ab-cdef-0123-456789abcdef";
|
2021-09-19 18:22:09 +00:00
|
|
|
//! let riot_api = RiotApi::new(api_key);
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! // Get summoner data.
|
|
|
|
//! let summoner = riot_api.summoner_v4()
|
|
|
|
//! .get_by_summoner_name(PlatformRoute::NA1, "잘 못").await
|
|
|
|
//! .expect("Get summoner failed.")
|
|
|
|
//! .expect("There is no summoner with that name.");
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! // Print summoner name.
|
|
|
|
//! println!("{} Champion Masteries:", summoner.name);
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! // Get champion mastery data.
|
|
|
|
//! let masteries = riot_api.champion_mastery_v4()
|
2023-12-27 06:21:47 +00:00
|
|
|
//! .get_all_champion_masteries_by_puuid(PlatformRoute::NA1, &summoner.puuid).await
|
2021-07-02 06:16:59 +00:00
|
|
|
//! .expect("Get champion masteries failed.");
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2023-03-08 21:21:41 +00:00
|
|
|
//! // Print champion masteries.
|
2021-07-02 06:16:59 +00:00
|
|
|
//! for (i, mastery) in masteries.iter().take(10).enumerate() {
|
|
|
|
//! println!("{: >2}) {: <9} {: >7} ({})", i + 1,
|
2021-09-09 21:54:02 +00:00
|
|
|
//! mastery.champion_id.name().unwrap_or("UNKNOWN"),
|
2021-07-02 06:16:59 +00:00
|
|
|
//! mastery.champion_points, mastery.champion_level);
|
|
|
|
//! }
|
|
|
|
//! });
|
|
|
|
//! ```
|
|
|
|
//! Output:
|
|
|
|
//! ```text
|
|
|
|
//! 잘 못 Champion Masteries:
|
2021-09-09 21:54:02 +00:00
|
|
|
//! 1) Riven 1236866 (7)
|
|
|
|
//! 2) Fiora 230679 (5)
|
2021-07-02 06:16:59 +00:00
|
|
|
//! 3) Katarina 175985 (5)
|
2021-09-09 21:54:02 +00:00
|
|
|
//! 4) Lee Sin 156070 (7)
|
|
|
|
//! 5) Jax 102662 (5)
|
2021-07-02 06:16:59 +00:00
|
|
|
//! 6) Gnar 76373 (6)
|
|
|
|
//! 7) Kai'Sa 64271 (5)
|
2021-09-09 21:54:02 +00:00
|
|
|
//! 8) Caitlyn 46614 (5)
|
2021-07-02 06:16:59 +00:00
|
|
|
//! 9) Irelia 46465 (5)
|
|
|
|
//! 10) Vladimir 37176 (5)
|
|
|
|
//! ```
|
2021-09-19 18:22:09 +00:00
|
|
|
//! The [`RiotApi` struct documentation](https://docs.rs/riven/latest/riven/struct.RiotApi.html)
|
|
|
|
//! contains additional usage information. The [tests](https://github.com/MingweiSamuel/Riven/tree/v/2.x.x/riven/tests)
|
2024-01-21 03:40:41 +00:00
|
|
|
//! and [example proxy](https://github.com/MingweiSamuel/Riven/tree/v/2.x.x/riven/examples/proxy)
|
2021-09-19 18:22:09 +00:00
|
|
|
//! provide more example usage.
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-09-19 18:22:09 +00:00
|
|
|
//! ## Feature Flags
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-09-19 18:22:09 +00:00
|
|
|
//! ### Nightly vs Stable
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-04 18:10:50 +00:00
|
|
|
//! Enable the `nightly` feature to use nightly-only functionality. This enables
|
2021-07-02 06:16:59 +00:00
|
|
|
//! [nightly optimizations in the `parking_lot` crate](https://github.com/Amanieu/parking_lot#nightly-vs-stable).
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-04 18:10:50 +00:00
|
|
|
//! ```toml
|
|
|
|
//! riven = { version = "...", features = [ "nightly" ] }
|
|
|
|
//! ```
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-09-19 18:22:09 +00:00
|
|
|
//! ### rustls
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-04 18:10:50 +00:00
|
|
|
//! Riven uses [reqwest](https://github.com/seanmonstar/reqwest) for making requests. By default, reqwest uses the native TLS library.
|
|
|
|
//! If you prefer using [rustls](https://github.com/ctz/rustls) you can do so by turning off the Riven default features
|
|
|
|
//! and specifying the `rustls-tls` feature:
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-04 18:10:50 +00:00
|
|
|
//! ```toml
|
|
|
|
//! riven = { version = "...", default-features = false, features = [ "rustls-tls" ] }
|
|
|
|
//! ```
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2024-03-04 22:59:19 +00:00
|
|
|
//! ### `log` or `tracing`
|
|
|
|
//!
|
|
|
|
//! Riven is additionally able to produce [tracing](https://docs.rs/tracing) spans for requests if the `tracing` feature is enabled.
|
|
|
|
//! By default the `tracing` feature is disabled and Riven instead writes to [`log`](https://docs.rs/log).
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-09-19 18:22:09 +00:00
|
|
|
//! ## Docs
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! [On docs.rs](https://docs.rs/riven/).
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-09-19 18:22:09 +00:00
|
|
|
//! ## Error Handling
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! Riven returns either `Result<T>` or `Result<Option<T>>` within futures.
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! 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,
|
|
|
|
//! incorrect API key, etc.
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! If the `Option` is `None`, this indicates that the request completed
|
|
|
|
//! 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
|
|
|
|
//! spectator data for a summoner who is not in-game.
|
|
|
|
//! Specifically, the API returned a 404 HTTP status code in this situation.
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! 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
|
|
|
|
//! attempted, and the Reqwest `Response` object.
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! You can configure the number of time Riven retries using
|
2021-09-19 18:22:09 +00:00
|
|
|
//! `RiotApiConfig::set_retries(...)` and the `RiotApi::from_config(config)`
|
2021-07-02 06:16:59 +00:00
|
|
|
//! 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
|
|
|
|
//! inevitably fail again.
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-09-19 18:22:09 +00:00
|
|
|
//! ## Semantic Versioning
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! This package follows semantic versioning to an extent. However, the Riot API
|
|
|
|
//! itself changes often and does not follow semantic versioning, which makes
|
|
|
|
//! things difficult. Out-of-date versions will slowly partially cease to work due
|
|
|
|
//! to this.
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! When the API changes, this may result in breaking changes in the `models`
|
|
|
|
//! module, `endpoints` module, and some of the `consts` module. "Handle accessor"
|
|
|
|
//! methods may be removed from `RiotApi` if the corresponding endpoint is removed
|
|
|
|
//! from the Riot API. These breaking changes will increment the **MINOR** version,
|
|
|
|
//! not the major version.
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! Parts of Riven that do not depend on Riot API changes do follow semantic
|
|
|
|
//! versioning.
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-09-19 18:22:09 +00:00
|
|
|
//! ## Additional Help
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! Feel free to [make an issue](https://github.com/MingweiSamuel/Riven/issues/new)
|
|
|
|
//! if you are have any questions or trouble with Riven.
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-09-19 18:22:09 +00:00
|
|
|
//! # Development
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! NodeJS is used to generate code for Riven. The
|
2021-09-19 18:22:09 +00:00
|
|
|
//! [`riven/srcgen`](https://github.com/MingweiSamuel/Riven/tree/v/2.x.x/riven/srcgen)
|
2021-07-02 06:16:59 +00:00
|
|
|
//! 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
|
|
|
|
//! code.
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-07-02 06:16:59 +00:00
|
|
|
//! To set up the srcgen, you will first need to install NodeJS. Then enter the
|
2021-09-19 18:22:09 +00:00
|
|
|
//! `riven/srcgen` folder and run `npm ci` (or `npm install`) to install
|
|
|
|
//! dependencies.
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
2021-09-19 18:22:09 +00:00
|
|
|
//! To run the srcgen use `node riven/srcgen` from the repository root.
|
2023-05-10 18:58:24 +00:00
|
|
|
//!
|
|
|
|
//!
|
2019-10-23 07:39:40 +00:00
|
|
|
|
2020-06-05 05:11:53 +00:00
|
|
|
// Re-exported reqwest types.
|
|
|
|
pub use reqwest;
|
|
|
|
|
2019-11-03 03:55:07 +00:00
|
|
|
mod config;
|
|
|
|
pub use config::RiotApiConfig;
|
2019-10-23 02:33:15 +00:00
|
|
|
|
2019-10-14 06:38:22 +00:00
|
|
|
pub mod consts;
|
2019-10-12 07:48:15 +00:00
|
|
|
|
2023-05-10 18:58:24 +00:00
|
|
|
#[rustfmt::skip]
|
2019-10-22 21:28:23 +00:00
|
|
|
pub mod endpoints;
|
2019-10-22 07:01:11 +00:00
|
|
|
|
2019-11-03 03:55:07 +00:00
|
|
|
mod error;
|
|
|
|
pub use error::*;
|
|
|
|
|
2020-06-05 05:39:51 +00:00
|
|
|
pub mod meta;
|
|
|
|
|
2023-05-10 18:58:24 +00:00
|
|
|
#[rustfmt::skip]
|
2019-11-03 18:48:45 +00:00
|
|
|
pub mod models;
|
2021-12-29 18:04:54 +00:00
|
|
|
mod models_impls;
|
2019-11-03 18:48:45 +00:00
|
|
|
|
2019-11-03 03:55:07 +00:00
|
|
|
mod req;
|
2019-10-17 23:00:04 +00:00
|
|
|
|
2020-06-05 04:52:43 +00:00
|
|
|
mod response_info;
|
|
|
|
pub use response_info::*;
|
|
|
|
|
2019-10-17 23:00:04 +00:00
|
|
|
mod riot_api;
|
|
|
|
pub use riot_api::*;
|
|
|
|
|
2019-10-17 21:44:26 +00:00
|
|
|
mod util;
|
2024-02-24 08:28:22 +00:00
|
|
|
|
|
|
|
/// Wasm compatibility layer for [`std::time`] or [`web_time`].
|
|
|
|
#[rustfmt::skip]
|
|
|
|
pub mod time {
|
|
|
|
#[cfg(not(target_family = "wasm"))]
|
|
|
|
pub use std::time::*;
|
|
|
|
#[cfg(target_family = "wasm")]
|
|
|
|
pub use web_time::*;
|
|
|
|
|
|
|
|
#[cfg(not(target_family = "wasm"))]
|
|
|
|
pub use tokio::time::sleep;
|
|
|
|
#[cfg(target_family = "wasm")]
|
|
|
|
pub use gloo_timers::future::sleep;
|
|
|
|
}
|