documented

This commit is contained in:
danijoo
2013-12-30 15:00:49 +01:00
parent 08c8bf21c3
commit fd3b1b31cc
3 changed files with 54 additions and 7 deletions

View File

@@ -1,3 +1,6 @@
# Class to represent the masterybook of a summoner
# @attr [Numeric] summonerId id of the summoner
# @attr [Array<MasteryPage>] pages of the masterybook
class MasteryBook class MasteryBook
attr_accessor :pages, :summonerId attr_accessor :pages, :summonerId
@@ -10,6 +13,11 @@ class MasteryBook
end end
end end
# Class to represent a page of a masterybook
# @attr [Numeric] id ID of the page
# @attr [String] name page name
# @attr [Boolean] current indicates if the page is selected
# @attr [Array<Talent>] array of selected talents
class MasteryPage class MasteryPage
attr_accessor :id, :talents, :name, :current attr_accessor :id, :talents, :name, :current
@@ -25,6 +33,10 @@ class MasteryPage
end end
# Class to represent a talent of a mastery page
# @attr [Numeric] id id of the mastery
# @attr [String] name of the mastery
# @attr [Numeric] rank rank of the mastery
class Talent class Talent
attr_accessor :id,:rank, :name attr_accessor :id,:rank, :name

View File

@@ -4,17 +4,23 @@ require 'sightstone/masterybook'
require 'sightstone/runebook' require 'sightstone/runebook'
require 'open-uri' require 'open-uri'
# Module to provide calls to the summoner api
class SummonerModule < SightstoneBaseModule class SummonerModule < SightstoneBaseModule
def initialize(sightstone) def initialize(sightstone)
@sightstone = sightstone @sightstone = sightstone
end end
# returns a summoner object
# @param name_or_id [Integer, String] name or id of the summoner
# @param optional [Hash] optional arguments: :region => replaces default region
# @ return [Summoner] summoner
def summoner(name_or_id, optional={}) def summoner(name_or_id, optional={})
region = optional[:region] || @sightstone.region region = optional[:region] || @sightstone.region
uri = if name_or_id.is_a? Integer uri = if name_or_id.is_a? Integer
"https://prod.api.pvp.net/api/lol/#{region}/v1.1/summoner/#{name_or_id}" "https://prod.api.pvp.net/api/lol/#{region}/v1.2/summoner/#{name_or_id}"
else else
"https://prod.api.pvp.net/api/lol/#{region}/v1.1/summoner/by-name/#{URI::encode(name_or_id)}" "https://prod.api.pvp.net/api/lol/#{region}/v1.2/summoner/by-name/#{URI::encode(name_or_id)}"
end end
response = _get_api_response(uri) response = _get_api_response(uri)
@@ -24,18 +30,30 @@ class SummonerModule < SightstoneBaseModule
} }
end end
# returns the names for the ids
# @param ids [Array<Numeric>] ids
# @param optional [Hash<Symbol, String>] optional arguments: :region => replaces default region
# @return [Hash<Numeric, String>] a hash matching each id to the summoners name
def names(ids, optional={}) def names(ids, optional={})
region = optional[:region] || @sightstone.region region = optional[:region] || @sightstone.region
ids = ids.join(',') ids = ids.join(',')
uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.1/summoner/#{ids}/name" uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.2/summoner/#{ids}/name"
response = _get_api_response(uri) response = _get_api_response(uri)
_parse_response(response) { |resp| _parse_response(response) { |resp|
data = JSON.parse(resp) data = JSON.parse(resp)
return data['summoners'] names_array = data['summoners']
names_hash = Hash.new
names_array.each do |summoner|
names_hash[summoner['id']] = summoner['name']
end
return names_hash
} }
end end
# returns the runebook of a summoner
# @param summoner [Summoner, id] summoner object or id of a summoner
# @param optional [Hash<Symbol, String>] optional arguments: :region => replaces default region
# @return [Runebook] runebook of the summoner
def runes(summoner, optional={}) def runes(summoner, optional={})
region = optional[:region] || @sightstone.region region = optional[:region] || @sightstone.region
id = if summoner.is_a? Summoner id = if summoner.is_a? Summoner
@@ -43,7 +61,7 @@ class SummonerModule < SightstoneBaseModule
else else
summoner summoner
end end
uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.1/summoner/#{id}/runes" uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.2/summoner/#{id}/runes"
response = _get_api_response(uri) response = _get_api_response(uri)
_parse_response(response) { |resp| _parse_response(response) { |resp|
data = JSON.parse(resp) data = JSON.parse(resp)
@@ -51,6 +69,10 @@ class SummonerModule < SightstoneBaseModule
} }
end end
# returns the masterybook of a summoner
# @param summoner [Summoner, id] summoner object or id of a summoner
# @param optional [Hash<Symbol, String>] optional arguments: :region => replaces default region
# @return [Masterybook] masterybook of the summoner
def masteries(summoner, optional={}) def masteries(summoner, optional={})
region = optional[:region] || @sightstone.region region = optional[:region] || @sightstone.region
id = if summoner.is_a? Summoner id = if summoner.is_a? Summoner
@@ -58,7 +80,7 @@ class SummonerModule < SightstoneBaseModule
else else
summoner summoner
end end
uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.1/summoner/#{id}/masteries" uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.2/summoner/#{id}/masteries"
response = _get_api_response(uri) response = _get_api_response(uri)
_parse_response(response) { |resp| _parse_response(response) { |resp|
data = JSON.parse(resp) data = JSON.parse(resp)

View File

@@ -1,3 +1,6 @@
# Class to represent the runebook of a summoner
# @attr [Numeric] summonerId id of the summoner
# @attr [Array<RunePage>] pages of the runebook
class RuneBook class RuneBook
attr_accessor :pages, :summonerId attr_accessor :pages, :summonerId
@@ -10,6 +13,11 @@ class RuneBook
end end
end end
# Class to represent a page of a runebook
# @attr [Numeric] id ID of the page
# @attr [String] name page name
# @attr [Boolean] current indicates if the page is selected
# @attr [Hash<Numeric, Rune>] slots matches slot ids to the rune
class RunePage class RunePage
attr_accessor :id, :slots, :name, :current attr_accessor :id, :slots, :name, :current
@@ -25,6 +33,11 @@ class RunePage
end end
# Class to represent a rune
# @attr [Numeric] id ID of the rune
# @attr [String] description description
# @attr [String] name name of the rune
# @attr [Numeric] tier rune tier (1,2,3)
class Rune class Rune
attr_accessor :id, :description, :name, :tier attr_accessor :id, :description, :name, :tier