Class: Sightstone::TeamModule

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

Overview

module to make calls to the team api

Instance Method Summary collapse

Constructor Details

#initialize(sightstone) ⇒ TeamModule

Returns a new instance of TeamModule.



8
9
10
# File 'lib/sightstone/modules/team_module.rb', line 8

def initialize(sightstone)
  @sightstone = sightstone
end

Instance Method Details

#teams(summoner, optional = {}) ⇒ Object

call to receive all teams for a summoner @ return [Array<Team>] An array containing all teams of the given summoner

Parameters:

  • summoner (Summoner, Fixnum)

    summoner object or id of a summoner

  • optional (Hash) (defaults to: {})

    optional arguments: :region => replaces default region



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sightstone/modules/team_module.rb', line 16

def teams(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.2/team/by-summoner/#{id}"

  response = _get_api_response(uri)
  _parse_response(response) { |resp|
    data = JSON.parse(resp)
    teams = []
    data.each do |team|
      teams << Team.new(team)
    end
    if block_given?
      yield teams
    else
      return teams
    end
  }
end