Class: Sightstone::LeagueModule
- Inherits:
-
SightstoneBaseModule
- Object
- SightstoneBaseModule
- Sightstone::LeagueModule
- Defined in:
- lib/sightstone/modules/league_module.rb
Overview
module to provide calls to the league api
Instance Method Summary collapse
-
#initialize(sightstone) ⇒ LeagueModule
constructor
A new instance of LeagueModule.
-
#league_entries(summoner, optional = {}) ⇒ Array<LeagueItem>
Get all entries for the given summoner.
-
#leagues(summoner, optional = {}) ⇒ Array<League>
Provides league information of a summoner.
Constructor Details
#initialize(sightstone) ⇒ LeagueModule
Returns a new instance of LeagueModule.
8 9 10 |
# File 'lib/sightstone/modules/league_module.rb', line 8 def initialize(sightstone) @sightstone = sightstone end |
Instance Method Details
#league_entries(summoner, optional = {}) ⇒ Array<LeagueItem>
Get all entries for the given summoner
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/sightstone/modules/league_module.rb', line 44 def league_entries(summoner, optional={}) region = optional[:region] || @sightstone.region id = if summoner.is_a? Summoner summoner.id else summoner end uri = "https://prod.api.pvp.net/api/lol/#{region}/v2.3/league/by-summoner/#{id}/entry" response = _get_api_response(uri) _parse_response(response) { |resp| data = JSON.parse(resp) entries = [] data.each do |entry| entries << LeagueItem.new(entry) end if block_given? yield entries else return entries end } end |
#leagues(summoner, optional = {}) ⇒ Array<League>
Provides league information of a summoner
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sightstone/modules/league_module.rb', line 16 def leagues(summoner, optional={}) region = optional[:region] || @sightstone.region id = if summoner.is_a? Summoner summoner.id else summoner end uri = "https://prod.api.pvp.net/api/lol/#{region}/v2.3/league/by-summoner/#{id}" response = _get_api_response(uri) _parse_response(response) { |resp| data = JSON.parse(resp) leagues = [] data.each do |league| leagues << League.new(league) end if block_given? yield leagues else return leagues end } end |