class Lolxin::Spectator

Constants

BannedChampion
CurrentGameInfo
CurrentGameParticipant
FeaturedGames
Mastery
Observer
Participant
Rune

Attributes

endpoint[RW]

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method
# File lib/lolxin/api/spectator.rb, line 67
def initialize(options = {})
  super
  @endpoint = "spectator/%{version}" % {version: @version}
end

Public Instance Methods

by_summoner(summoner_id) click to toggle source
# File lib/lolxin/api/spectator.rb, line 72
def by_summoner(summoner_id)
  url = "#{endpoint}/active-games/by-summoner/#{summoner_id}"
  res = conn.get(url)
  return res if res.status != 200

  current_game = JSON.parse(res.body)
  build_current_game_info(current_game)
end

Private Instance Methods

build_banned_champions(banned_champions) click to toggle source
# File lib/lolxin/api/spectator.rb, line 131
def build_banned_champions(banned_champions)
  return [] if banned_champions.nil? or banned_champions.empty?

  banned_champions.map do |banned_champion|
    BannedChampion.new(
      banned_champion['pickTurn'],
      banned_champion['championId'],
      banned_champion['teamId']
    )
  end
end
build_current_game_info(current_game) click to toggle source
# File lib/lolxin/api/spectator.rb, line 92
def build_current_game_info(current_game)
  CurrentGameInfo.new(
    current_game['gameId'],
    current_game['gameStartTime'],
    current_game['platformId'],
    current_game['gameMode'],
    current_game['mapId'],
    current_game['gameType'],
    build_banned_champions(current_game['bannedChampions']),
    build_observer(current_game['observers']),
    build_current_game_participants(current_game['participants']),
    current_game['gameLength'],
    current_game['gameQueueConfigId']
  )
end
build_current_game_participants(participants) click to toggle source
# File lib/lolxin/api/spectator.rb, line 149
def build_current_game_participants(participants)
  participants.map do |participant|
    CurrentGameParticipant.new(
      participant['profileIconId'],
      participant['championId'],
      participant['summonerName'],
      participant['runes'],
      participant['bot'],
      participant['teamId'],
      participant['spell2d'],
      participant['masteries'],
      participant['spell1id'],
      participant['summonerId']
    )
  end
end
build_observer(observer) click to toggle source
# File lib/lolxin/api/spectator.rb, line 143
def build_observer(observer)
  return nil if observer.nil?

  Observer.new(observer['encryptionKey'])
end
build_participants(participants) click to toggle source
# File lib/lolxin/api/spectator.rb, line 166
def build_participants(participants)
  participants.map do |participant|
    Participant.new(
      participant['profileIconId'],
      participant['championId'],
      participant['summonerName'],
      participant['bot'],
      participant['spell2d'],
      participant['teamId'],
      participant['spell1id']
    )
  end
end