Class: Lolxin::Spectator

Inherits:
Api
  • Object
show all
Defined in:
lib/lolxin/api/spectator.rb

Defined Under Namespace

Classes: BannedChampion, CurrentGameParticipant, FeaturedGames, Mastery, Observer, Participant, Rune

Constant Summary collapse

CurrentGameInfo =
FeaturedGameInfo = Struct.new(
  :game_id,
  :game_start_time,
  :platform_id,
  :game_mode,
  :map_id,
  :game_type,
  :banned_champions,
  :observers,
  :participants,
  :game_length,
  :game_queue_config_id
)

Constants inherited from Api

Api::BASE_ENDPOINT

Instance Attribute Summary collapse

Attributes inherited from Api

#api_key, #conn, #region, #version

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Spectator

Returns a new instance of Spectator.



67
68
69
70
# File 'lib/lolxin/api/spectator.rb', line 67

def initialize(options = {})
  super
  @endpoint = "spectator/%{version}" % {version: @version}
end

Instance Attribute Details

#endpointObject

Returns the value of attribute endpoint.



65
66
67
# File 'lib/lolxin/api/spectator.rb', line 65

def endpoint
  @endpoint
end

Instance Method Details

#by_summoner(summoner_id) ⇒ Object



72
73
74
75
76
77
78
79
# 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


81
82
83
84
85
86
87
88
# File 'lib/lolxin/api/spectator.rb', line 81

def featured_games
  url = "#{endpoint}/featured-games"
  res = conn.get(url)
  return res if res.status != 200

  featured = JSON.parse(res.body)
  build_featured_games(featured)
end