fixed, documentation and update to team module

This commit is contained in:
danijoo
2014-01-01 19:35:09 +01:00
parent e3a0e74b2f
commit 9ada2f659c
2 changed files with 54 additions and 11 deletions

View File

@@ -2,11 +2,16 @@ require 'sightstone/modules/sightstone_base_module'
require 'sightstone/summoner' require 'sightstone/summoner'
require 'sightstone/team' require 'sightstone/team'
# module to make calls to the team api
class TeamModule < SightstoneBaseModule class TeamModule < SightstoneBaseModule
def initialize(sightstone) def initialize(sightstone)
@sightstone = sightstone @sightstone = sightstone
end end
# call to receive all teams for a summoner
# @param [Summoner, Fixnum] summoner summoner object or id of a summoner
# @param optional [Hash] optional arguments: :region => replaces default region
# @ return [Array<Team>] An array containing all teams of the given summoner
def teams(summoner, optional={}) def teams(summoner, optional={})
region = optional[:region] || @sightstone.region region = optional[:region] || @sightstone.region
id = if summoner.is_a? Summoner id = if summoner.is_a? Summoner
@@ -15,7 +20,7 @@ class TeamModule < SightstoneBaseModule
summoner summoner
end end
uri = "https://prod.api.pvp.net/api/#{region}/v2.1/team/by-summoner/#{id}" uri = "https://prod.api.pvp.net/api/lol/#{region}/v2.2/team/by-summoner/#{id}"
response = _get_api_response(uri) response = _get_api_response(uri)
_parse_response(response) { |resp| _parse_response(response) { |resp|

View File

@@ -1,18 +1,32 @@
# A Team
# @attr [Fixnum] createDate UNIX timestamp of team creation
# @attr [String] fullId id of the team
# @attr [Fixnum] lastGameDate UNIX timespamp of last game
# @attr [Fixnum] lastJoinDate UNIX timestamp of the date where the newest player joined the team
# @attr [Fixnum] lastJoinedRankedTeamQueueDate UNIX timestamp of latest team game
# @attr [Array<TeamHistoryGame>] matchHistory List of latest games
# @attr [Fixnum] modifyDate UNIX timestamp of latest team modification
# @attr [String] name team name
# @attr [Roster] roster team roster
# @attr [Fixnum] secondLastJoinDate UNIX timestamp of second latest join date of a member
# @attr [String] status team status
# @attr [String] tag tag of the team
# @attr [Array<TeamStat>] teamStatSummary array containing the stats of the team
# @attr [Fixnum] thridLastJoinDate UNIX timestamp of third latest join date of a member
class Team class Team
attr_accessor :teamStatSummary, :status, :tag, :roster, :lastGameDate, :modifyDate, :teamId, :timestamp, :lastJoinDate, :secondLastJoinDate, :matchHistory, :lastJoinedRankedTeamQueueDate, :name, :thirdLastJoinDate, :createDate attr_accessor :teamStatSummary, :status, :tag, :roster, :lastGameDate, :modifyDate, :teamId, :lastJoinDate, :secondLastJoinDate, :matchHistory, :lastJoinedRankedTeamQueueDate, :name, :thirdLastJoinDate, :createDate
def initialize(data) def initialize(data)
@status = data['status'] @status = data['status']
@tag = data['tag'] @tag = data['tag']
@roster = Roster.new(data['roster']) @roster = Roster.new(data['roster'])
@lastGameDate = data['lastGameDate'] @lastGameDate = data['lastGameDate']
@modifyDate = data['modifyDate'] @modifyDate = data['modifyDate']
@teamId = data['teamId']['fullId'] @teamId = data['fullId']
@timestamp = data['timestamp']
@lastJoinDate = data['lastJoinDate'] @lastJoinDate = data['lastJoinDate']
@secondLastJoinDate = data['secondLastJoinDate'] @secondLastJoinDate = data['secondLastJoinDate']
@matchHistory = [] @matchHistory = []
data['matchHistory'].each do |game| data['matchHistory'].each do |game|
matchHistory << Game.new(game) matchHistory << TeamHistoryGame.new(game)
end end
@lastJoinedRankedTeamQueueDate=data['lastJoinedRankedTeamQueueDate'] @lastJoinedRankedTeamQueueDate=data['lastJoinedRankedTeamQueueDate']
@name = data['name'] @name = data['name']
@@ -26,6 +40,9 @@ class Team
end end
end end
# class to represent the roster of a team
# @attr [Fixnum] ownerId summoner ID of the team owner
# @attr [Array<Member>] memberList list of all team members
class Roster class Roster
attr_accessor :ownerId, :memberList attr_accessor :ownerId, :memberList
def initialize(data) def initialize(data)
@@ -37,6 +54,11 @@ class Roster
end end
end end
# member of a team
# @attr [Fixnum] joinDate UNIX timestamp of join date
# @attr [Fixnum] inviteDate UNIX timestamp of invitation date
# @attr [String] status status of the team member
# @attr [Fixnum] playerId summoner ID of the member
class Member class Member
attr_accessor :joinDate, :inviteDate, :status, :playerId attr_accessor :joinDate, :inviteDate, :status, :playerId
def initialize(data) def initialize(data)
@@ -47,20 +69,37 @@ class Member
end end
end end
# statistical overview of a team
# @attr [Fixnum] wins number of won games
# @attr [Fixnum] losses number of lost games
# @attr [Fixnum] averageFamesPlayed average played games of member
# @attr [String] fullId id of the team
# @attr [String] teamStatType queue of the stat
class TeamStat class TeamStat
attr_accessor :wins, :losses, :averageGamesPlayed, :teamId, :teamStatType attr_accessor :wins, :losses, :averageGamesPlayed, :fullId, :teamStatType
def initialize(data) def initialize(data)
@wins = data['wins'] @wins = data['wins']
@losses = data['losses'] @losses = data['losses']
@averageGamesPlayed = data['averageGamesPlayed'] @averageGamesPlayed = data['averageGamesPlayed']
@teamId = data['teamId'] @fullId = data['fullId']
@teamStatType = data['teamStatType'] @teamStatType = data['teamStatType']
end end
end end
class Game # Recent game of a team
attr_accessor :gameMode, :mapId, :assists, :opposingTeamName, :invalid, :deaths, :gameId, :kills, :win, :date, :opposingTeamKills # @attr [Fixnum] gameMode mode of the game
# @attr [Fixnum] mapId ID of the map
# @attr [Fixnum] assists assists of the team
# @attr [String] opposingTeamName name of the enemy team
# @attr [Boolean] invalid Invalid flag # TODO what is this?
# @attr [Fixnum] deaths number of deaths summed over all players of the team
# @attr [Boolean] win true if game has been won by the team
# @attr [Fixnum] opposingTeamKills number of kills of the enemy team
# @attr [Fixnum] gameId ID of the game
# @attr [Fixnum] kills kills of the team
class TeamHistoryGame
attr_accessor :gameMode, :mapId, :assists, :opposingTeamName, :invalid, :deaths, :gameId, :kills, :win, :opposingTeamKills
def initialize(data) def initialize(data)
@gameMode = data['gameMode'] @gameMode = data['gameMode']
@mapId = data['mapId'] @mapId = data['mapId']
@@ -71,7 +110,6 @@ class Game
@gameId = data['gameId'] @gameId = data['gameId']
@kills = data['kills'] @kills = data['kills']
@win = data['win'] @win = data['win']
@date = data['date']
@opposingTeamKills = data['opposingTeamKills'] @opposingTeamKills = data['opposingTeamKills']
end end
end end