readme example

This commit is contained in:
Mingwei Samuel 2019-11-03 14:36:30 -08:00
parent 1581425206
commit 3d0b42e31c
4 changed files with 15 additions and 13 deletions

View file

@ -23,9 +23,13 @@ Riven currently uses nightly Rust.
use riven::RiotApi; use riven::RiotApi;
use riven::consts::Region; use riven::consts::Region;
async { // Enter tokio async runtime.
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
// Create RiotApi instance from key. // Create RiotApi instance from key.
let riot_api = RiotApi::with_key("RGAPI-01234567-89ab-cdef-0123-456789abcdef"); let api_key = "RGAPI-01234567-89ab-cdef-0123-456789abcdef";
# let api_key = std::env::var("RGAPI_KEY").ok().or_else(|| std::fs::read_to_string("apikey.txt").ok()).unwrap();
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()
@ -48,10 +52,8 @@ async {
mastery.champion_id.to_string(), mastery.champion_id.to_string(),
mastery.champion_points, mastery.champion_level); mastery.champion_points, mastery.champion_level);
} }
} });
``` ```
Full code in [tests/readme.rs.ignored](./tests/readme.rs.ignored)
Output: Output:
```text ```text
잘 못 Champion Masteries: 잘 못 Champion Masteries:

View file

@ -1,9 +1,9 @@
/////////////////////////////////////////////// ///////////////////////////////////////////////
// // // //
// ! // // ! //
// 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 };

View file

@ -7,7 +7,7 @@ macro_rules! async_tests {
env_logger::init(); env_logger::init();
std::process::exit({ std::process::exit({
let mut rt = tokio::runtime::current_thread::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 {

View file

@ -19,7 +19,7 @@ async_tests!{
my_runner { my_runner {
league_summoner_bulk_test: async { league_summoner_bulk_test: async {
let leagues = (1..20) 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));