fixes, documenttation and tests for game api
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
require 'sightstone/stat'
|
require 'sightstone/stat'
|
||||||
|
|
||||||
|
# match history of a summoner
|
||||||
|
# @attr [Fixnum] summonerId ID of the summoner
|
||||||
|
# @attr [Array<HistoryGame>] games unsorted list of recently played games
|
||||||
class MatchHistory
|
class MatchHistory
|
||||||
attr_accessor :games, :summonerId
|
attr_accessor :games, :summonerId
|
||||||
|
|
||||||
@@ -7,13 +10,28 @@ class MatchHistory
|
|||||||
@summonerId = data['summonerId']
|
@summonerId = data['summonerId']
|
||||||
@games = []
|
@games = []
|
||||||
data['games'].each do |game|
|
data['games'].each do |game|
|
||||||
games << Game.new(game)
|
games << HistoryGame.new(game)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Game
|
# A played game
|
||||||
attr_accessor :championId, :createDate, :createDateString, :fellowPlayers, :gameId, :gameMode, :gameType, :invalid, :level, :mapId, :spell1, :spell2, :statistics, :subType, :teamId
|
# @attr [Fixnum] championId ID of the played champ of requested summoner
|
||||||
|
# @attr [Fixnum] createDate UNIX timestamp of creation date of the games
|
||||||
|
# @attr [Array<Player>] fellowPlayers a list of all players of the game
|
||||||
|
# @attr [Fixnum] gameId ID of the game
|
||||||
|
# @attr [String] gameMode mode of the game
|
||||||
|
# @attr [String] gameType type of the game
|
||||||
|
# @attr [Boolean] invalid Invalid flag #TODO what is this?
|
||||||
|
# @attr [Fixnum] level level of the requested summoner
|
||||||
|
# @attr [Fixnum] mapId ID of the played map
|
||||||
|
# @attr [Fixnum] spell1 selected summoner spell no 1
|
||||||
|
# @attr [Fixnum] spell2 selected summoner spell no 2
|
||||||
|
# @attr [String] subtype subtype
|
||||||
|
# @attr [Fixnum] teamId ID of the team if there is a team associated to the game
|
||||||
|
# @attr [Array<Stat>] statistics statistics of the game
|
||||||
|
class HistoryGame
|
||||||
|
attr_accessor :championId, :createDate, :fellowPlayers, :gameId, :gameMode, :gameType, :invalid, :level, :mapId, :spell1, :spell2, :statistics, :subType, :teamId
|
||||||
|
|
||||||
def initialize(data)
|
def initialize(data)
|
||||||
@championId=data['championId']
|
@championId=data['championId']
|
||||||
@@ -29,7 +47,7 @@ class Game
|
|||||||
@invalid=data['invalid']
|
@invalid=data['invalid']
|
||||||
@level=data['level']
|
@level=data['level']
|
||||||
@mapId=data['mapId']
|
@mapId=data['mapId']
|
||||||
@spell1=data['spell1]']
|
@spell1=data['spell1']
|
||||||
@spell2=data['spell2']
|
@spell2=data['spell2']
|
||||||
@statistics = []
|
@statistics = []
|
||||||
data['statistics'].each do |stat|
|
data['statistics'].each do |stat|
|
||||||
@@ -40,6 +58,10 @@ class Game
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# player of a game
|
||||||
|
# @attr [Fixnum] championId ID of played Champion
|
||||||
|
# @attr [Fixnum] summonerId ID of the summoner
|
||||||
|
# @attr [Fixnum] teammId ID of the team
|
||||||
class Player
|
class Player
|
||||||
attr_accessor :championId, :summonerId, :teamId
|
attr_accessor :championId, :summonerId, :teamId
|
||||||
|
|
||||||
@@ -48,4 +70,22 @@ class Player
|
|||||||
@summonerId = data['summonerId']
|
@summonerId = data['summonerId']
|
||||||
@teamId = data['teamId']
|
@teamId = data['teamId']
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# statistical value of a game
|
||||||
|
# @attr [Fixnum] id ID of the statistical value
|
||||||
|
# @attr [String] mame name of the statistical value (example: MINIONS_KILLED)
|
||||||
|
# @attr [Fixnum] value value
|
||||||
|
class Stat
|
||||||
|
attr_accessor :id, :name, :value
|
||||||
|
|
||||||
|
def initialize(data)
|
||||||
|
@name = data['name']
|
||||||
|
@id = data['id']
|
||||||
|
@value = if data.has_key? 'value'
|
||||||
|
data['value']
|
||||||
|
else
|
||||||
|
data['count']
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -2,12 +2,17 @@ require 'sightstone/modules/sightstone_base_module'
|
|||||||
require 'sightstone/summoner'
|
require 'sightstone/summoner'
|
||||||
require 'sightstone/match_history'
|
require 'sightstone/match_history'
|
||||||
|
|
||||||
|
# module to access the game api
|
||||||
class GameModule < SightstoneBaseModule
|
class GameModule < SightstoneBaseModule
|
||||||
|
|
||||||
def initialize(sightstone)
|
def initialize(sightstone)
|
||||||
@sightstone = sightstone
|
@sightstone = sightstone
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# returns the match history of a summoner
|
||||||
|
# @param [Summoner, Fixnum] summoner summoner object or id of a summoner
|
||||||
|
# @param optional [Hash] optional arguments: :region => replaces default region
|
||||||
|
# @return [MatchHistory] match history of the summoner
|
||||||
def recent(summoner, optional={})
|
def recent(summoner, optional={})
|
||||||
region = optional[:region] || @sightstone.region
|
region = optional[:region] || @sightstone.region
|
||||||
id = if summoner.is_a? Summoner
|
id = if summoner.is_a? Summoner
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
class Stat
|
|
||||||
attr_accessor :name, :value
|
|
||||||
|
|
||||||
def initialize(data)
|
|
||||||
@name = data['name']
|
|
||||||
@value = if data.has_key? 'value'
|
|
||||||
data['value']
|
|
||||||
else
|
|
||||||
data['count']
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
58
test/test_game_module.rb
Normal file
58
test/test_game_module.rb
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
require 'test/unit'
|
||||||
|
require 'sightstone'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class GameModuleTest < BaseTest
|
||||||
|
|
||||||
|
@@req_id = 30447079
|
||||||
|
|
||||||
|
def test_recent_games
|
||||||
|
matchHistory = @@sightstone.game.recent(@@req_id)
|
||||||
|
assert_instance_of(MatchHistory, matchHistory)
|
||||||
|
assert_instance_of(Fixnum, matchHistory.summonerId)
|
||||||
|
assert_instance_of(Array, matchHistory.games)
|
||||||
|
matchHistory.games.each do |game|
|
||||||
|
_check_game game
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def _check_game(game)
|
||||||
|
assert_instance_of(HistoryGame, game)
|
||||||
|
assert_instance_of(Fixnum, game.createDate)
|
||||||
|
assert_instance_of(Fixnum, game.championId)
|
||||||
|
assert_instance_of(Fixnum, game.gameId)
|
||||||
|
assert_instance_of(String, game.gameType)
|
||||||
|
assert(game.invalid || !game.invalid)
|
||||||
|
assert_instance_of(Fixnum, game.level)
|
||||||
|
assert_instance_of(Fixnum, game.mapId)
|
||||||
|
assert_instance_of(Fixnum, game.spell1)
|
||||||
|
assert_instance_of(Fixnum, game.spell2)
|
||||||
|
assert_instance_of(String, game.subType)
|
||||||
|
assert_instance_of(Fixnum, game.teamId)
|
||||||
|
assert_instance_of(Array, game.fellowPlayers)
|
||||||
|
assert_instance_of(Array, game.statistics)
|
||||||
|
_check_statistics(game.statistics)
|
||||||
|
_check_fellows(game.fellowPlayers)
|
||||||
|
end
|
||||||
|
|
||||||
|
def _check_statistics(stats)
|
||||||
|
stats.each do |stat|
|
||||||
|
assert_instance_of(Stat, stat)
|
||||||
|
assert_instance_of(Fixnum, stat.value)
|
||||||
|
assert_instance_of(Fixnum, stat.id)
|
||||||
|
assert_instance_of(String, stat.name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def _check_fellows(fellows)
|
||||||
|
fellows.each do |fellow|
|
||||||
|
assert_instance_of(Player, fellow)
|
||||||
|
assert_instance_of(Fixnum, fellow.championId)
|
||||||
|
assert_instance_of(Fixnum, fellow.summonerId)
|
||||||
|
assert_instance_of(Fixnum, fellow.teamId)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user