16 releases (4 stable)

✓ Uses Rust 2018 edition

1.3.0 May 4, 2020
1.1.0 Mar 31, 2020
0.2.2 Jan 30, 2020
0.2.0 Dec 31, 2019
0.1.2 Nov 14, 2019

#1 in #riot

Download history 17/week @ 2020-01-23 49/week @ 2020-01-30 9/week @ 2020-02-06 21/week @ 2020-02-13 31/week @ 2020-02-20 97/week @ 2020-02-27 26/week @ 2020-03-05 15/week @ 2020-03-12 41/week @ 2020-03-19 25/week @ 2020-03-26 19/week @ 2020-04-02 58/week @ 2020-04-09 44/week @ 2020-04-16 7/week @ 2020-04-23 39/week @ 2020-04-30 7/week @ 2020-05-07

137 downloads per month

MIT license

230KB
3.5K SLoC

Riven

Riven Github Crates.io Docs.rs Travis CI 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.
  • TFT API Support.

Usage

use riven::RiotApi;
use riven::consts::Region;

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

    // Get summoner data.
    let summoner = riot_api.summoner_v4()
        .get_by_summoner_name(Region::NA, "잘못").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(Region::NA, &summoner.id).await
        .expect("Get champion masteries failed.");

    // Print champioon masteries.
    for (i, mastery) in masteries[..10].iter().enumerate() {
        println!("{: >2}) {: <9}    {: >7} ({})", i + 1,
            mastery.champion_id.to_string(),
            mastery.champion_points, mastery.champion_level);
    }
});

Output:

잘 못 Champion Masteries:
 1) Riven        1219895 (7)
 2) Fiora         229714 (5)
 3) Katarina      175985 (5)
 4) Lee Sin       150546 (7)
 5) Jax           100509 (5)
 6) Gnar           76373 (6)
 7) Kai'Sa         64271 (5)
 8) Caitlyn        46479 (5)
 9) Irelia         46465 (5)
10) Vladimir       37176 (5)

Nightly vs Stable

Enable the nightly feature to use nightly-only functionality. Mainly enables nightly optimizations in the parking_lot crate. Also required for running async integration tests.

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::with_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 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 srcgen folder and run npm ci (or npm install) to install dependencies.

To run the srcgen use node srcgen from the main folder.

Dependencies

~5.5–9MB
~192K SLoC