Class: Twitch::V2::Games

Inherits:
Object
  • Object
show all
Defined in:
lib/kappa/game.rb

Overview

Query class for finding top games or finding games by name.

See Also:

Instance Method Summary collapse

Instance Method Details

#find(options) {|suggestion| ... } ⇒ Array<GameSuggestion>?

Get a list of games with names similar to the specified name.

Examples:

Twitch.games.find(:name => 'diablo')
Twitch.games.find(:name => 'starcraft', :live => true)
Twitch.games.find(:name => 'starcraft') do |suggestion|
  next if suggestion.name =~ /heart of the swarm/i
  puts suggestion.name
end

Parameters:

  • options (Hash)

    Search criteria.

Options Hash (options):

  • :name (String)

    Game name search term. This can be a partial name, e.g. "league".

  • :live (Boolean) — default: false

    If true, only returns games that are currently live on at least one channel.

  • :limit (Fixnum) — default: nil

    Limit on the number of results returned.

Yields:

  • Optional. If a block is given, each game suggestion is yielded.

Yield Parameters:

Returns:

  • (Array<GameSuggestion>)

    Games matching the criteria, if no block is given.

  • (nil)

    If a block is given.

Raises:

  • (ArgumentError)

    If :name is not specified.

See Also:



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/kappa/game.rb', line 194

def find(options)
  raise ArgumentError, 'options' if options.nil?
  raise ArgumentError, 'name' if options[:name].nil?

  params = {
    :query => options[:name],
    :type => 'suggest'
  }

  if options[:live]
    params.merge!(:live => true)
  end

  return @query.connection.accumulate(
    :path => 'search/games',
    :params => params,
    :json => 'games',
    :create => GameSuggestion,
    :limit => options[:limit]
  )
end

#top(options = {}) {|game| ... } ⇒ Array<Game>?

Get a list of games with the highest number of current viewers on Twitch.

Examples:

Twitch.games.top
Twitch.games.top(:limit => 10)
Twitch.games.top do |game|
  next if game.viewer_count < 10000
  puts game.name
end

Parameters:

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

    Filter criteria.

Options Hash (options):

  • :hls (Boolean) — default: nil

    If true, limit the games to those that have any streams using HLS (HTTP Live Streaming). If false or nil, do not limit.

  • :limit (Fixnum) — default: nil

    Limit on the number of results returned.

  • :offset (Fixnum) — default: 0

    Offset into the result set to begin enumeration.

Yields:

  • Optional. If a block is given, each top game is yielded.

Yield Parameters:

  • game (Game)

    Current game.

Returns:

  • (Array<Game>)

    Games sorted by number of current viewers on Twitch, highest first, if no block is given.

  • (nil)

    If a block is given.

See Also:



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/kappa/game.rb', line 155

def top(options = {}, &block)
  params = {}

  if options[:hls]
    params[:hls] = true
  end

  return @query.connection.accumulate(
    :path => 'games/top',
    :params => params,
    :json => 'top',
    :create => -> hash { Game.new(hash, @query) },
    :limit => options[:limit],
    :offset => options[:offset],
    &block
  )
end