Writing a League of Legends API Wrapper


League of Legends used to be one of my favorite games. One of my practice Rails sites is a LoL stats tracker that lets you look up play stats from RiotGame’s API. Rather than use a gem that does all the work for me, I wrote my own wrapper to practice making my own API calls.

Raw Player Data Output

The process was fairly simple. I initialized my LeagueWrapper object with my API key that’s stored in Rails secrets.yml. This will refer to the league_api_key variable I have in my secrets.yml.


Next I follow Riot’s documentation on how to make API calls and use net/http to return the results. And voila! We now have data returned from Riot that we can muck around with and manipulate. I now have retrieved the summoner ID from my friend’s username, Killerbill, and got data from his recent matches. By decoding the JSON retrieved, we can clearly see the data needed to manipulate.

Match History
Match History JSON

From using that data, in my models I can pick out the information I need and save it to my database:

Save to Database Code

This allows me to store stats such as KDA, or something more interesting such as average gold per game at various times in the game, or performance across multiple game modes.

Parsed Match History

And there you have it, a simple way to use Riot’s League of Legends API with Rails.