diff --git a/lib/sightstone/league.rb b/lib/sightstone/league.rb index 1dbb798..68b6687 100644 --- a/lib/sightstone/league.rb +++ b/lib/sightstone/league.rb @@ -1,11 +1,15 @@ +# Class to represent a league +# @attr [String] name name of the league +# @attr [String] queue queue Type (can be: RANKED_SOLO_5x5, RANKED_TEAM_3x3, RANKED_TEAM_5x5) +# @attr [String] tier tier of the requestet summoner (can be: CHALLENGER, DIAMOND, PLATINUM, GOLD, SILVER, BRONZE) +# @attr [Array] entries class League - attr_accessor :entries, :name, :queue, :tier, :timestamp + attr_accessor :entries, :name, :queue, :tier def initialize(data) @name = data['name'] @queue = data['queue'] @tier = data['tier'] - @timestamp = data['timestamp'] @entries = [] data['entries'].each do |entry| @entries << LeagueItem.new(entry) @@ -13,29 +17,48 @@ class League end end +# One entry of a league +# @attr [Boolean] isFreshBlood determines if summoner is new in the league +# @attr [Boolean] isHotStreak hotStreak = 3 games won in a row +# @attr [Boolean] isInactive true if summoner is inactive +# @attr [Boolean] isVetern true if veteran +# @attr [Fixnum] lastPlayed timestamp of last played game +# @attr [String] leagueName name of the league +# @attr [Fixnum] leaguePoints leaguePoints +# @attr [MiniSeries, nil] nil if player has no miniseries, a miniseries object if he is in one +# @attr [String] playerOrTeamId id of the player or team as a string +# @attr [String] playerOrTeamName name of the player/team +# @attr [String] queueType type of the queue +# @attr [String] rank rank (can be: I, II, III, IV, V) +# @attr [String] tier tier (can be: CHALLENGER, DIAMOND, PLATINUM, GOLD, SILVER, BRONZE) +# @attr [Fixnum] wins number of won matches in given queue class LeagueItem - attr_accessor :isFreshBlood, :isHotStreak, :isActive, :isVeteran, :lastPlayed, :leagueName, :leaguePoints, :losses, :miniSeries, :playerOrTeamId, :playerOrTeamName, :queueType, :rank, :tier, :timeUntilDecay, :wins + attr_accessor :isFreshBlood, :isHotStreak, :isInactive, :isVeteran, :lastPlayed, :leagueName, :leaguePoints, :miniSeries, :playerOrTeamId, :playerOrTeamName, :queueType, :rank, :tier, :wins def initialize(data) @isFreshBlood=data['isFreshBlood'] @isHotStreak=data['isHotStreak'] - @isActive=data['isActive'] + @isInactive=data['isInactive'] @isVeteran=data['isVeteran'] @lastPlayed=data['lastPlayed'] - @leagueName=data['leageuName'] + @leagueName=data['leagueName'] @leaguePoints=data['leaguePoints'] - @losses=data['losses'] @miniSeries= MiniSeries.new(data['miniSeries']) if data.has_key? 'miniSeries' @playerOrTeamId=data['playerOrTeamId'] @playerOrTeamName=data['playerOrTeamName'] @queueType=data['queueType'] @rank=data['rank'] @tier=data['tier'] - @timeUntilDecay=data['timeUntilDecay'] @wins=data['wins'] end end +# Class to represent a MiniSeries (Promotion games) +# @attr [Fixnum] losses number of lost games of the series +# @attr [Fixnum] wins number of won games of the series +# @attr [Fixnum] target number of required wins to win the series +# @attr [Fixnum] timeLeftToPlayMillis time left to complete the series +# @attr [String] win/loose history as a string. Each character shows a (W)in, (L)oss or (N)ot played class MiniSeries attr_accessor :losses, :wins, :target, :progress, :timeLeftToPlayMillis def initialize(data) @@ -43,6 +66,6 @@ class MiniSeries @wins = data['wins'] @target = data['target'] @progress = data['progress'] - @timeLeftToPlayMillis = data['timeLeftToPlayMillies'] + @timeLeftToPlayMillis = data['timeLeftToPlayMillis'] end end diff --git a/lib/sightstone/modules/league_module.rb b/lib/sightstone/modules/league_module.rb index db54f47..8c080d2 100644 --- a/lib/sightstone/modules/league_module.rb +++ b/lib/sightstone/modules/league_module.rb @@ -2,11 +2,16 @@ require 'sightstone/modules/sightstone_base_module' require 'sightstone/summoner' require 'sightstone/league' +# module to provide calls to the league api class LeagueModule < SightstoneBaseModule def initialize(sightstone) @sightstone = sightstone end + # Provides league information of a summoner + # @param [Summoner, Integer] summoner + # @param optional [Hash] optional arguments: :region => replaces default region + # @returns [Array] an array of all leagues the summoner and his teams are in def league(summoner, optional={}) region = optional[:region] || @sightstone.region id = if summoner.is_a? Summoner @@ -15,7 +20,7 @@ class LeagueModule < SightstoneBaseModule summoner end - uri = "https://prod.api.pvp.net/api/#{region}/v2.1/league/by-summoner/#{id}" + uri = "https://prod.api.pvp.net/api/lol/#{region}/v2.2/league/by-summoner/#{id}" response = _get_api_response(uri) _parse_response(response) { |resp| data = JSON.parse(resp)