Riven/README.md

95 lines
3.8 KiB
Markdown
Raw Normal View History

2019-11-05 07:03:59 +00:00
<h1 align="center">
Riven<br>
2019-11-05 07:29:20 +00:00
<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>
2019-11-05 07:03:59 +00:00
<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>
<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>
<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>
</h1>
2019-11-03 20:04:25 +00:00
Rust Library for the [Riot Games API](https://developer.riotgames.com/).
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](https://developer.riotgames.com/api-methods/) ([Swagger](http://www.mingweisamuel.com/riotapi-schema/tool/)).
## Design
2019-11-03 20:04:25 +00:00
* Fast, asynchronous, thread-safe.
* Automatically retries failed requests.
* TFT API Support.
## Usage
```rust
use riven::RiotApi;
use riven::consts::Region;
2019-11-05 01:00:59 +00:00
// Riven Enter tokio async runtime.
2019-11-03 22:36:30 +00:00
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
2019-11-08 00:38:53 +00:00
// Create RiotApi instance from key string.
2019-11-03 22:36:30 +00:00
let api_key = "RGAPI-01234567-89ab-cdef-0123-456789abcdef";
2019-11-08 00:38:53 +00:00
# /* (doc testing) */ let api_key = std::env!("RGAPI_KEY");
2019-11-03 22:36:30 +00:00
let riot_api = RiotApi::with_key(api_key);
2019-11-03 20:04:25 +00:00
// 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.");
2019-11-03 20:04:25 +00:00
// 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.");
2019-11-03 20:04:25 +00:00
// 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);
}
2019-11-03 22:36:30 +00:00
});
2019-11-03 20:04:25 +00:00
```
Output:
```text
잘 못 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)
```
2019-11-05 06:41:47 +00:00
### Nightly vs Stable
Enable the `nightly` feature to use nightly-only functionality. Mainly enables
[nightly optimizations in the `parking_lot` crate](https://github.com/Amanieu/parking_lot#nightly-vs-stable).
Also required for running async integration tests.
### Docs
2019-11-05 06:41:47 +00:00
[On docs.rs](https://docs.rs/riven/).
### Error Handling
2019-11-05 06:41:47 +00:00
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
2019-11-05 06:41:47 +00:00
Feel free to [make an issue](https://github.com/MingweiSamuel/Riven/issues/new)
if you are have any questions or trouble using Riven.