Class: Sightstone::LeagueModule

Inherits:
SightstoneBaseModule show all
Defined in:
lib/sightstone/modules/league_module.rb

Overview

module to provide calls to the league api

Instance Method Summary collapse

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

#leagues(summoner, optional = {}) ⇒ Array<League>

Provides league information of a summoner

Parameters:

  • summoner (Summoner, Integer)
  • optional (Hash) (defaults to: {})

    optional arguments: :region => replaces default region

Returns:

  • (Array<League>)

    an array of all leagues the summoner and his teams are in



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