Riot API Library for Rust
Find a file
2024-03-23 22:24:29 -07:00
.github/workflows test: add testing and ci for wasm (#63) 2024-02-24 21:42:06 -08:00
.vscode fix: regen, updates to fix bad match data 2024-03-05 11:31:06 -08:00
riven Add match_v5::Participant::riot_id_game_name() helper method 2024-03-23 22:24:29 -07:00
.gitignore Fix .gitignore for riven/srcgen move 2021-09-27 19:36:11 -07:00
Cargo.toml Move proxy to make it an example, update its README.md 2024-01-20 19:39:44 -08:00
doc.bash Re-export reqwest properly 2020-06-04 22:41:26 -07:00
LICENSE Convert CRLF to LF 2021-06-30 16:40:35 -07:00
README.md docs: small updates to README.md 2024-03-04 14:40:17 -08:00
rust-toolchain.toml Update testing commands 2022-08-15 16:01:07 -07:00
rustfmt.toml Add rustfmt.toml 2024-01-20 19:41:46 -08:00
test-full.bash test: add testing and ci for wasm (#63) 2024-02-24 21:42:06 -08:00
test-wasm.bash test: add testing and ci for wasm (#63) 2024-02-24 21:42:06 -08:00
test.bash test.bash RUST_BACKTRACE=full 2024-01-15 11:34:10 -08:00

Riven

Riven Github Crates.io Docs.rs unsafe forbidden

Rust Library for the Riot Games API.

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 (Swagger).

Design

  • Fast, asynchronous, thread-safe.
  • Automatically retries failed requests, configurable.
  • Supports all endpoints, kept up-to-date using riotapi-schema.
  • Can compile to Wasm for server-side or browser+proxy use.

Usage

use riven::RiotApi;
use riven::consts::PlatformRoute;

// Enter tokio async runtime.
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
    // Create RiotApi instance from key string.
    let api_key = std::env!("RGAPI_KEY"); // "RGAPI-01234567-89ab-cdef-0123-456789abcdef";
    let riot_api = RiotApi::new(api_key);

    // 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.");

    // Print summoner name.
    println!("{} Champion Masteries:", summoner.name);

    // Get champion mastery data.
    let masteries = riot_api.champion_mastery_v4()
        .get_all_champion_masteries_by_puuid(PlatformRoute::NA1, &summoner.puuid).await
        .expect("Get champion masteries failed.");

    // Print champion masteries.
    for (i, mastery) in masteries.iter().take(10).enumerate() {
        println!("{: >2}) {: <9}    {: >7} ({})", i + 1,
            mastery.champion_id.name().unwrap_or("UNKNOWN"),
            mastery.champion_points, mastery.champion_level);
    }
});

Output:

잘 못 Champion Masteries:
 1) Riven        1236866 (7)
 2) Fiora         230679 (5)
 3) Katarina      175985 (5)
 4) Lee Sin       156070 (7)
 5) Jax           102662 (5)
 6) Gnar           76373 (6)
 7) Kai'Sa         64271 (5)
 8) Caitlyn        46614 (5)
 9) Irelia         46465 (5)
10) Vladimir       37176 (5)

The RiotApi struct documentation contains additional usage information. The tests and example proxy provide more example usage.

Feature Flags

Nightly vs Stable

Enable the nightly feature to use nightly-only functionality. This enables nightly optimizations in the parking_lot crate.

riven = { version = "...", features = [ "nightly" ] }

rustls

Riven uses reqwest for making requests. By default, reqwest uses the native TLS library. If you prefer using rustls you can do so by turning off the Riven default features and specifying the rustls-tls feature:

riven = { version = "...", default-features = false, features = [ "rustls-tls" ] }

log or tracing

Riven is additionally able to produce tracing spans for requests if the tracing feature is enabled. By default the tracing feature is disabled and Riven instead writes to log.

Docs

On docs.rs.

Error Handling

Riven returns either Result<T> or Result<Option<T>> within futures.

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.

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.

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.

You can configure the number of time Riven retries using RiotApiConfig::set_retries(...) and the RiotApi::from_config(config) 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.

Semantic Versioning

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.

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.

Parts of Riven that do not depend on Riot API changes do follow semantic versioning.

Additional Help

Feel free to make an issue if you are have any questions or trouble with Riven.

Development

NodeJS is used to generate code for Riven. The riven/srcgen folder contains the code and doT.js templates. index.js lists the JSON files downloaded and used to generate the code.

To set up the srcgen, you will first need to install NodeJS. Then enter the riven/srcgen folder and run npm ci (or npm install) to install dependencies.

To run the srcgen use node riven/srcgen from the repository root.