champions api: rdoc, tests, removed debug strings
This commit is contained in:
@@ -1,3 +1,15 @@
|
|||||||
|
# Class to represent a champion
|
||||||
|
# @attr [Boolean] active determines if champion is active
|
||||||
|
# @attr [Integer] attackRank attack rank
|
||||||
|
# @attr [Boolean] botEnabled Bot enabled flag (for custom games)
|
||||||
|
# @attr [Boolean] botMmEnabled Bot Match Made enabeld flag (for Coop/AI games)
|
||||||
|
# @attr [Integer] defenseRank Champion defense rank.
|
||||||
|
# @attr [Integer] difficultyRank Champion difficulty rank.
|
||||||
|
# @attr [Boolean] freeToPlay Indicates if the champion is free to play. Free to play champions are rotated periodically.
|
||||||
|
# @attr [Fixnum] id Champion ID.
|
||||||
|
# @attr [Integer] magicRank Champion magic rank.
|
||||||
|
# @attr [String] name Champion name.
|
||||||
|
# @attr [boolean] rankedPlayEnabled Ranked play enabled flag.
|
||||||
class Champion
|
class Champion
|
||||||
attr_accessor :active, :attackRank, :botEnabled, :botMmEnabled
|
attr_accessor :active, :attackRank, :botEnabled, :botMmEnabled
|
||||||
attr_accessor :defenseRank, :difficultyRank, :freeToPlay, :id, :magicRank, :name, :rankedPlayEnabled
|
attr_accessor :defenseRank, :difficultyRank, :freeToPlay, :id, :magicRank, :name, :rankedPlayEnabled
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
require 'sightstone/champion'
|
require 'sightstone/champion'
|
||||||
require 'sightstone/modules/sightstone_base_module'
|
require 'sightstone/modules/sightstone_base_module'
|
||||||
|
|
||||||
|
# Module to provide calls to the summoner api
|
||||||
class ChampionModule < SightstoneBaseModule
|
class ChampionModule < SightstoneBaseModule
|
||||||
|
|
||||||
def initialize(sightstone)
|
def initialize(sightstone)
|
||||||
@sightstone = sightstone
|
@sightstone = sightstone
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# call to get champions
|
||||||
|
# @param optional [Hash] optional arguments: :region => replaces default region, :free_to_play => boolean (only free to play champs if true)
|
||||||
|
# @return [Array<Champion>] array of champs
|
||||||
def champions(optional={})
|
def champions(optional={})
|
||||||
region = optional[:region] || @sightstone.region
|
region = optional[:region] || @sightstone.region
|
||||||
free_to_play = optional[:free_to_play]
|
free_to_play = optional[:free_to_play]
|
||||||
uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.1/champion"
|
uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.1/champion"
|
||||||
response = _get_api_response(uri, {'freeToPlay' => free_to_play})
|
response = _get_api_response(uri, {'freeToPlay' => free_to_play})
|
||||||
puts response
|
|
||||||
|
|
||||||
_parse_response(response) { |resp|
|
_parse_response(response) { |resp|
|
||||||
data = JSON.parse(resp)
|
data = JSON.parse(resp)
|
||||||
|
|||||||
31
test/test_champions_module.rb
Normal file
31
test/test_champions_module.rb
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
require 'test/unit'
|
||||||
|
require 'sightstone'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ChampionModuleTest < BaseTest
|
||||||
|
|
||||||
|
def test_champions
|
||||||
|
champions = @@sightstone.champion.champions
|
||||||
|
assert_instance_of(Array, champions)
|
||||||
|
if(champions.size > 0)
|
||||||
|
_check_champion(champions[0])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_free_to_play
|
||||||
|
champions = @@sightstone.champion.champions :free_to_play => true
|
||||||
|
champions.each do |champ|
|
||||||
|
assert_equal(true, champ.freeToPlay)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def _check_champion(champ)
|
||||||
|
assert_instance_of(Champion, champ)
|
||||||
|
assert_instance_of(Fixnum, champ.attackRank)
|
||||||
|
assert_instance_of(Fixnum, champ.defenseRank)
|
||||||
|
assert_instance_of(String, champ.name)
|
||||||
|
assert_instance_of(Fixnum, champ.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user