#riot #lol #league #legends #api #api-wrapper #api-bindings

lol_api_rs

A simple API wrapper for the Riot League of Legends API

1 unstable release

Uses old Rust 2015

0.2.0 Jul 19, 2017

#16 in #legends

MIT license

105KB
1.5K SLoC

League of Legends API Wrapper for Rust

Want to create the next coolest thing with Rust? A discord bot? A new website? The next haxor information center? This is for you.

Getting Started

The first thing is first. In your Cargo.toml file, add the following line

[dependencies]
lol_api_rs = "0.2.0"

In your main file add:

extern crate lol_api_rs;

Making Your First Call

Once everything is installed, making your first call is as easy as creating a constructor function and calling an endpoint.

// Use the Riot API constructor
use lol_api_rs::client::Riot;

// Define your Riot API Key
const RIOT_API_KEY: &'static str = "RGAPI-xxxxxxxxxxx";

fn main () {
	// Define new riot API factory
    // It accepts the following arguments.
    // The first param is your API key
    // The second param is the region to run your queries against. (NA is default)
    // The third param is if you want to use a custom logger to log debug statements
    let riot = Riot::new(RIOT_API_KEY, None, None);

    // For our example we'll get champion information for Champion 99 - Lux
    let json = riot.get_champions_by_id(99);

    // Every call will return a Result<DataType, String> The below match is a simple handler for this.
    match json {
        Ok(j) => println!("{:?}", j),
        Err(e) => println!("There was an error: {}", e)
    }
}

Breaking changes

0.2.0

  • Previously all calls returned the result or paniced. This was changed to returning a type Result.

Questions/Comments?

Open an issue on Github or send me an email. I would love to make this more robust/better working. Aware of rate limits, better coded, etc. This is my first rust project and I'm looking forward to learning more about the language and the community.

Dependencies

~6–16MB
~225K SLoC