diff --git a/lib/sightstone/modules/league_module.rb b/lib/sightstone/modules/league_module.rb index afa131e..344a1f1 100644 --- a/lib/sightstone/modules/league_module.rb +++ b/lib/sightstone/modules/league_module.rb @@ -36,6 +36,34 @@ class LeagueModule < SightstoneBaseModule end } end + + # Get all entries for the given summoner + # @param [Summoner, Integer] summoner or summoner id + # @param optional [Hash] optional arguments: :region => replaces default region + # @return [Array] an array of all entries for that given summoner + def league_entries(summoner, optional={}) + region = optional[:region] || @sightstone.region + id = if summoner.is_a? Summoner + summoner.id + else + summoner + end + + uri = "https://prod.api.pvp.net/api/lol/#{region}/v2.3/league/by-summoner/#{id}/entry" + response = _get_api_response(uri) + _parse_response(response) { |resp| + data = JSON.parse(resp) + entries = [] + data.each do |entry| + entries << LeagueItem.new(entry) + end + if block_given? + yield entries + else + return entries + end + } + end end end \ No newline at end of file diff --git a/sightstone.gemspec b/sightstone.gemspec index c86c693..1f7edf3 100644 --- a/sightstone.gemspec +++ b/sightstone.gemspec @@ -1,7 +1,7 @@ Gem::Specification.new do |s| s.name = 'sightstone' - s.version = '1.4.3' - s.date = '2014-03-16' + s.version = '1.4.4' + s.date = '2014-03-17' s.summary = 'Ruby wrapper for riots league of legends api' s.description = s.summary s.authors = ["Daniel Bauer"] diff --git a/test/test_league_module.rb b/test/test_league_module.rb index 900ac77..ec6c843 100644 --- a/test/test_league_module.rb +++ b/test/test_league_module.rb @@ -20,6 +20,22 @@ class LeagueModuleTest < BaseTest _check_league(league) end end + + def test_entry + begin + entries = @@sightstone.league.league_entries(@@req_id) + rescue Sightstone::RateLimitExceededException + puts "Rate limit exeeded, waiting 1 sec" + sleep 1 + retry + end + entries.each do |entry| + assert_instance_of(Sightstone::LeagueItem, entry) + + # check the league entries + _check_league_item(entry) + end + end def _check_league(league) assert_instance_of String, league.name