forked from mirror/Riven
1
0
Fork 0
Riot API Library for Rust
 
 
 
Go to file
Mingwei Samuel cf23db7361 Upgrade to reqwest 0.10, tokio 0.2, release 0.2.0 2019-12-30 21:36:23 -08:00
src Upgrade to reqwest 0.10, tokio 0.2, release 0.2.0 2019-12-30 21:36:23 -08:00
srcgen Update return Option only if x-nullable-404 2019-11-07 16:06:01 -08:00
tests Upgrade to reqwest 0.10, tokio 0.2, release 0.2.0 2019-12-30 21:36:23 -08:00
.gitignore Version 0.1.0 2019-11-05 00:19:33 -08:00
.travis.yml Update doctests 2019-11-07 16:38:53 -08:00
Cargo.toml Upgrade to reqwest 0.10, tokio 0.2, release 0.2.0 2019-12-30 21:36:23 -08:00
LICENSE Version 0.1.0 2019-11-05 00:19:33 -08:00
README.md Upgrade to reqwest 0.10, tokio 0.2, release 0.2.0 2019-12-30 21:36:23 -08:00

README.md

Riven

Riven Github Crates.io Docs.rs Travis CI unsafe forbidden

Rust Library for the Riot Games API.

Rivens'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 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 if a summoner (by name) or match (by id) doesn't exist.

Additional Info

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