From fd3b1b31cc4fbeaea7b48c86c91892519c2ee869 Mon Sep 17 00:00:00 2001 From: danijoo Date: Mon, 30 Dec 2013 15:00:49 +0100 Subject: [PATCH] documented --- lib/sightstone/masterybook.rb | 12 ++++++++ lib/sightstone/modules/summoner_module.rb | 36 ++++++++++++++++++----- lib/sightstone/runebook.rb | 13 ++++++++ 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/lib/sightstone/masterybook.rb b/lib/sightstone/masterybook.rb index 83b2316..e322584 100644 --- a/lib/sightstone/masterybook.rb +++ b/lib/sightstone/masterybook.rb @@ -1,3 +1,6 @@ +# Class to represent the masterybook of a summoner +# @attr [Numeric] summonerId id of the summoner +# @attr [Array] pages of the masterybook class MasteryBook attr_accessor :pages, :summonerId @@ -10,6 +13,11 @@ class MasteryBook 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] array of selected talents class MasteryPage attr_accessor :id, :talents, :name, :current @@ -25,6 +33,10 @@ class MasteryPage 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 attr_accessor :id,:rank, :name diff --git a/lib/sightstone/modules/summoner_module.rb b/lib/sightstone/modules/summoner_module.rb index e1d051f..4c122de 100644 --- a/lib/sightstone/modules/summoner_module.rb +++ b/lib/sightstone/modules/summoner_module.rb @@ -4,17 +4,23 @@ require 'sightstone/masterybook' require 'sightstone/runebook' require 'open-uri' +# Module to provide calls to the summoner api class SummonerModule < SightstoneBaseModule + def initialize(sightstone) @sightstone = sightstone 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={}) region = optional[:region] || @sightstone.region 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 - "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 response = _get_api_response(uri) @@ -24,18 +30,30 @@ class SummonerModule < SightstoneBaseModule } end - + # returns the names for the ids + # @param ids [Array] ids + # @param optional [Hash] optional arguments: :region => replaces default region + # @return [Hash] a hash matching each id to the summoners name def names(ids, optional={}) region = optional[:region] || @sightstone.region 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) _parse_response(response) { |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 + # returns the runebook of a summoner + # @param summoner [Summoner, id] summoner object or id of a summoner + # @param optional [Hash] optional arguments: :region => replaces default region + # @return [Runebook] runebook of the summoner def runes(summoner, optional={}) region = optional[:region] || @sightstone.region id = if summoner.is_a? Summoner @@ -43,7 +61,7 @@ class SummonerModule < SightstoneBaseModule else summoner 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) _parse_response(response) { |resp| data = JSON.parse(resp) @@ -51,6 +69,10 @@ class SummonerModule < SightstoneBaseModule } end + # returns the masterybook of a summoner + # @param summoner [Summoner, id] summoner object or id of a summoner + # @param optional [Hash] optional arguments: :region => replaces default region + # @return [Masterybook] masterybook of the summoner def masteries(summoner, optional={}) region = optional[:region] || @sightstone.region id = if summoner.is_a? Summoner @@ -58,7 +80,7 @@ class SummonerModule < SightstoneBaseModule else summoner 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) _parse_response(response) { |resp| data = JSON.parse(resp) diff --git a/lib/sightstone/runebook.rb b/lib/sightstone/runebook.rb index f19044e..75f2096 100644 --- a/lib/sightstone/runebook.rb +++ b/lib/sightstone/runebook.rb @@ -1,3 +1,6 @@ +# Class to represent the runebook of a summoner +# @attr [Numeric] summonerId id of the summoner +# @attr [Array] pages of the runebook class RuneBook attr_accessor :pages, :summonerId @@ -10,6 +13,11 @@ class RuneBook 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] slots matches slot ids to the rune class RunePage attr_accessor :id, :slots, :name, :current @@ -25,6 +33,11 @@ class RunePage 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 attr_accessor :id, :description, :name, :tier