Garen
An API wrapper for Riot Games (League of Legends)
Installation
Add this line to your application's Gemfile:
gem 'garen'
And then execute:
$ bundle
Or install it yourself as:
$ gem install garen
Usage
Latest Updates
Nov. 16th 2017:
Deleted the mastery and runes endpoints and associated tests, as these are being deprecated by Riot as part of their new rune system. Updated some VCRs.
Old:
I have updated the way that rate limits are returned in the response. If you pass in the parameter 'return_rate_limits' and set it to true, it will return both the app and method limit counts. The response back from your API call will include a response hash of the api response from riot, and a rate_limit hash with the app and method counts included in.
See below:
summoner = garen.summoner.by_name('Beasley', return_rate_limits: true)
# returns
"#<Hashie::Mash rate_limit=#<Hashie::Mash app_count=\"3:120,3:1\" method_count=\"1:10,1:600\"> response=#<Hashie::Rash account_id=36072798 id=22332661 name=\"Beasley\" profile_icon_id=20
95 revision_date=1503543762000 summoner_level=30>>"
# so you could call for example:
summoner.response.name
# this will give you 'Beasley' from the example above.
summoner.rate_limit.app_count
# this will give you '3:120,3:1' from the example above.
How to Use:
You can begin by adding a config block to your application to set your Riot API-Key, instead of having to pass it through every call as a parameter. However, if you'd rather pass it through as a parameter each time, that is also fine.
Garen.configure do |config|
config.api_key = 'RGAPI-Whatever-Riot-API-Token-You-Were-Given'
end
To get started, first create a Garen client
garen = Garen::Client.new
# If you didn't pass in your API key in a config block you would pass it in here
garen = Garen::Client.new(api_key: 'RGAPI-Whatever-Riot-API-Token-You-Were-Given')
# You may also pass in the service platform too - it defaults to 'na1' but feel free to change
garen = Garen::Client.new(service_platform: 'euw1')
# You can also pass in a debug parameter for troubleshooting issues, just pass in debug: true
You are now free to make API calls using the Garen::Client instance you created.
For example, if I wanted to retrieve summoner info for my league account 'Beasley':
summoner_info = garen.summoner.by_name('Beasley')
You can also pass in optional params into the api calls. For example, if you wanted to get a list of just the free champions this week, you could run:
f2p_champs = garen.champion.all(freeToPlay: true)
Just look at the documentation on Riot's API - https://developer.riotgames.com/api-methods/ - for all the different query arguments you can pass in.
Endpoints
The endpoints currently supported and their corresponding methods are:
CHAMPION-MASTERY-V3
.champion_mastery.by_summoner_id(summoner_id)
.champion_mastery.by_summoner_and_champion_id(summoner_id, champion_id)
.champion_mastery.score_by_summoner_id(summoner_id)
CHAMPION-V3
.champion.all
.champion.by_champion_id(champion_id)
LEAGUE-V3
.league.challenger
.league.master
.league.by_summoner_id
.league.position_by_summoner_id
LOL-STATIC-DATA-V3
.static.champions
.static.champions_by_id(champion_id)
.static.items
.static.items_by_id(item_id)
.static.language_strings
.static.languages
.static.maps
.static.masteries
.static.masteries_by_id(mastery_id)
.static.profile_icons
.static.realms
.static.runes
.static.runes_by_id(rune_id)
.static.summoner_spells
.static.summoner_spells_by_id(summoner_spell_id)
.static.version
LOL-STATUS-V3
.status.status
MATCH-V3
.match.by_match_id(match_id)
.match.by_account_id(account_id)
.match.recent_by_account_id(account_id)
.match.timeline_by_match_id(match_id)
SPECTATOR-V3
.spectator.by_summoner_id(summoner_id) - will return 404 if summoner not in a game
.spectator.featured_games
SUMMONER-V3
.summoner.by_name(name)
.summoner.by_account_id(account_id)
.summoner.by_summoner_id(summoner_id)
Not Implemented
Tournaments endpoints.
Development
After checking out the repo, you can run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/b4ugh/garen.
- Fork it ( https://github.com/b4ugh/garen/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'new stuff!')
- Push to the branch (git push origin my-new-feature)
- Create a new PR (pull request)
License
The gem is available as open source under the terms of the MIT License.