kappa 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +6 -6
- data/LICENSE +19 -19
- data/README.md +285 -285
- data/lib/kappa.rb +15 -15
- data/lib/kappa/channel.rb +214 -214
- data/lib/kappa/configuration.rb +88 -88
- data/lib/kappa/connection.rb +139 -139
- data/lib/kappa/errors.rb +43 -43
- data/lib/kappa/game.rb +216 -216
- data/lib/kappa/id_equality.rb +17 -17
- data/lib/kappa/images.rb +44 -44
- data/lib/kappa/proxy.rb +32 -32
- data/lib/kappa/query.rb +22 -22
- data/lib/kappa/status.rb +16 -16
- data/lib/kappa/stream.rb +289 -288
- data/lib/kappa/team.rb +132 -132
- data/lib/kappa/user.rb +159 -159
- data/lib/kappa/version.rb +3 -3
- data/lib/kappa/video.rb +229 -229
- metadata +23 -44
data/lib/kappa/errors.rb
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
module Twitch
|
2
|
-
# The base class for all `Twitch` errors.
|
3
|
-
class Error < StandardError
|
4
|
-
# An error that occurred as the result of a request to the Twitch.tv API.
|
5
|
-
class ResponseError < Error
|
6
|
-
# @private
|
7
|
-
def initialize(arg, url, status, body)
|
8
|
-
super(arg)
|
9
|
-
@url = url
|
10
|
-
@status = status
|
11
|
-
@body = body
|
12
|
-
end
|
13
|
-
|
14
|
-
# @example
|
15
|
-
# "https://api.twitch.tv/kraken/streams?limit=100&offset=0"
|
16
|
-
# @return [String] The request URL that resulted in this response error.
|
17
|
-
attr_reader :url
|
18
|
-
|
19
|
-
# @example
|
20
|
-
# 500
|
21
|
-
# @return [Fixnum] The HTTP status code for the response.
|
22
|
-
attr_reader :status
|
23
|
-
|
24
|
-
# @example
|
25
|
-
# '{"status":422,"message":"Channel desrow is not available on Twitch","error":"Unprocessable Entity"}'
|
26
|
-
# @return [String] The response body.
|
27
|
-
attr_reader :body
|
28
|
-
end
|
29
|
-
|
30
|
-
# An error indicating an HTTP client error code (4xx) from the Twitch.tv API.
|
31
|
-
class ClientError < ResponseError
|
32
|
-
end
|
33
|
-
|
34
|
-
# An error indicating an HTTP server error code (5xx) from the Twitch.tv API.
|
35
|
-
class ServerError < ResponseError
|
36
|
-
end
|
37
|
-
|
38
|
-
# An error indicating a malformed response from the Twitch.tv API.
|
39
|
-
# All Twitch.tv responses are expected to valid JSON objects.
|
40
|
-
class FormatError < ResponseError
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
1
|
+
module Twitch
|
2
|
+
# The base class for all `Twitch` errors.
|
3
|
+
class Error < StandardError
|
4
|
+
# An error that occurred as the result of a request to the Twitch.tv API.
|
5
|
+
class ResponseError < Error
|
6
|
+
# @private
|
7
|
+
def initialize(arg, url, status, body)
|
8
|
+
super(arg)
|
9
|
+
@url = url
|
10
|
+
@status = status
|
11
|
+
@body = body
|
12
|
+
end
|
13
|
+
|
14
|
+
# @example
|
15
|
+
# "https://api.twitch.tv/kraken/streams?limit=100&offset=0"
|
16
|
+
# @return [String] The request URL that resulted in this response error.
|
17
|
+
attr_reader :url
|
18
|
+
|
19
|
+
# @example
|
20
|
+
# 500
|
21
|
+
# @return [Fixnum] The HTTP status code for the response.
|
22
|
+
attr_reader :status
|
23
|
+
|
24
|
+
# @example
|
25
|
+
# '{"status":422,"message":"Channel desrow is not available on Twitch","error":"Unprocessable Entity"}'
|
26
|
+
# @return [String] The response body.
|
27
|
+
attr_reader :body
|
28
|
+
end
|
29
|
+
|
30
|
+
# An error indicating an HTTP client error code (4xx) from the Twitch.tv API.
|
31
|
+
class ClientError < ResponseError
|
32
|
+
end
|
33
|
+
|
34
|
+
# An error indicating an HTTP server error code (5xx) from the Twitch.tv API.
|
35
|
+
class ServerError < ResponseError
|
36
|
+
end
|
37
|
+
|
38
|
+
# An error indicating a malformed response from the Twitch.tv API.
|
39
|
+
# All Twitch.tv responses are expected to valid JSON objects.
|
40
|
+
class FormatError < ResponseError
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/kappa/game.rb
CHANGED
@@ -1,216 +1,216 @@
|
|
1
|
-
module Twitch::V2
|
2
|
-
# Games are categories (e.g. League of Legends, Diablo 3) used by streams and channels.
|
3
|
-
# Games can be searched for by query.
|
4
|
-
# @see Games#top Games#top
|
5
|
-
# @see Games#find Games#find
|
6
|
-
# @see Games
|
7
|
-
class Game
|
8
|
-
include Twitch::IdEquality
|
9
|
-
|
10
|
-
# @private
|
11
|
-
def initialize(hash, query)
|
12
|
-
@query = query
|
13
|
-
@channel_count = hash['channels']
|
14
|
-
@viewer_count = hash['viewers']
|
15
|
-
|
16
|
-
game = hash['game']
|
17
|
-
@id = game['_id']
|
18
|
-
@name = game['name']
|
19
|
-
@giantbomb_id = game['giantbomb_id']
|
20
|
-
@box_images = Images.new(game['box'])
|
21
|
-
@logo_images = Images.new(game['logo'])
|
22
|
-
end
|
23
|
-
|
24
|
-
# Get streams for this game.
|
25
|
-
# @example
|
26
|
-
# game.streams
|
27
|
-
# @example
|
28
|
-
# game.streams(:embeddable => true, :limit => 20)
|
29
|
-
# @example
|
30
|
-
# game.streams do |stream|
|
31
|
-
# next if stream.viewer_count < 1000
|
32
|
-
# puts stream.url
|
33
|
-
# end
|
34
|
-
# @param options [Hash] Search criteria.
|
35
|
-
# @option options [Array<String, Channel, #name>] :channel Only return streams for these channels.
|
36
|
-
# If a channel is not currently streaming, it is omitted. You must specify an array of channels
|
37
|
-
# or channel names.
|
38
|
-
# @option options [Boolean] :embeddable (nil) If `true`, limit the streams to those that can be embedded. If `false` or `nil`, do not limit.
|
39
|
-
# @option options [Boolean] :hls (nil) If `true`, limit the streams to those using HLS (HTTP Live Streaming). If `false` or `nil`, do not limit.
|
40
|
-
# @option options [Fixnum] :limit (nil) Limit on the number of results returned.
|
41
|
-
# @option options [Fixnum] :offset (0) Offset into the result set to begin enumeration.
|
42
|
-
# @yield Optional. If a block is given, each stream found is yielded.
|
43
|
-
# @yieldparam [Stream] stream Current stream.
|
44
|
-
# @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/streams.md#get-streams GET /streams
|
45
|
-
# @raise [ArgumentError] If `:channel` is not an array.
|
46
|
-
# @return [Array<Stream>] Streams matching the specified criteria, if no block is given.
|
47
|
-
# @return [nil] If a block is given.
|
48
|
-
def streams(options = {}, &block)
|
49
|
-
@query.streams.find(options.merge(:game => @name), &block)
|
50
|
-
end
|
51
|
-
|
52
|
-
# @example
|
53
|
-
# 21799
|
54
|
-
# @return [Fixnum] Unique Twitch ID.
|
55
|
-
attr_reader :id
|
56
|
-
|
57
|
-
# @example
|
58
|
-
# "League of Legends"
|
59
|
-
# @return [String] User-friendly game name.
|
60
|
-
attr_reader :name
|
61
|
-
|
62
|
-
# @example
|
63
|
-
# 24024
|
64
|
-
# @return [Fixnum] Unique game ID for GiantBomb.com.
|
65
|
-
attr_reader :giantbomb_id
|
66
|
-
|
67
|
-
# @return [Images] Set of images for the game's box art.
|
68
|
-
attr_reader :box_images
|
69
|
-
|
70
|
-
# @return [Images] Set of images for the game's logo.
|
71
|
-
attr_reader :logo_images
|
72
|
-
|
73
|
-
# @example
|
74
|
-
# 802
|
75
|
-
# @return [Fixnum] Total number of channels currently streaming this game on Twitch.
|
76
|
-
attr_reader :channel_count
|
77
|
-
|
78
|
-
# @example
|
79
|
-
# 68592
|
80
|
-
# @return [Fixnum] Total number of viewers across all channels currently watching this game on Twitch.
|
81
|
-
attr_reader :viewer_count
|
82
|
-
end
|
83
|
-
|
84
|
-
# A game suggestion returned by Twitch when searching for games via `Twitch.games.find`.
|
85
|
-
# @see Games#find Games#find
|
86
|
-
class GameSuggestion
|
87
|
-
include Twitch::IdEquality
|
88
|
-
|
89
|
-
# @private
|
90
|
-
def initialize(hash)
|
91
|
-
@id = hash['_id']
|
92
|
-
@name = hash['name']
|
93
|
-
@giantbomb_id = hash['giantbomb_id']
|
94
|
-
@popularity = hash['popularity']
|
95
|
-
@box_images = Images.new(hash['box'])
|
96
|
-
@logo_images = Images.new(hash['logo'])
|
97
|
-
end
|
98
|
-
|
99
|
-
# @example
|
100
|
-
# 155075940
|
101
|
-
# @return [Fixnum] Unique Twitch ID.
|
102
|
-
attr_reader :id
|
103
|
-
|
104
|
-
# @example
|
105
|
-
# "Dark Souls"
|
106
|
-
# @return [String] Game name.
|
107
|
-
attr_reader :name
|
108
|
-
|
109
|
-
# @example
|
110
|
-
# 32697
|
111
|
-
# @return [Fixnum] Unique game ID for GiantBomb.com.
|
112
|
-
attr_reader :giantbomb_id
|
113
|
-
|
114
|
-
# @example
|
115
|
-
# 67
|
116
|
-
# @return [Fixnum] Relative popularity metric. Higher number means more popular. This value only has meaning relative to other popularity values.
|
117
|
-
attr_reader :popularity
|
118
|
-
|
119
|
-
# @return [Images] Set of images for the game's box art.
|
120
|
-
attr_reader :box_images
|
121
|
-
|
122
|
-
# @return [Images] Set of images for the game's logo.
|
123
|
-
attr_reader :logo_images
|
124
|
-
end
|
125
|
-
|
126
|
-
# Query class for finding top games or finding games by name.
|
127
|
-
# @see Game
|
128
|
-
# @see GameSuggestion
|
129
|
-
class Games
|
130
|
-
# @private
|
131
|
-
def initialize(query)
|
132
|
-
@query = query
|
133
|
-
end
|
134
|
-
|
135
|
-
# Get a list of games with the highest number of current viewers on Twitch.
|
136
|
-
# @example
|
137
|
-
# Twitch.games.top
|
138
|
-
# @example
|
139
|
-
# Twitch.games.top(:limit => 10)
|
140
|
-
# @example
|
141
|
-
# Twitch.games.top do |game|
|
142
|
-
# next if game.viewer_count < 10000
|
143
|
-
# puts game.name
|
144
|
-
# end
|
145
|
-
# @param options [Hash] Filter criteria.
|
146
|
-
# @option options [Boolean] :hls (nil) If `true`, limit the games to those that have any streams using HLS (HTTP Live Streaming). If `false` or `nil`, do not limit.
|
147
|
-
# @option options [Fixnum] :limit (nil) Limit on the number of results returned.
|
148
|
-
# @option options [Fixnum] :offset (0) Offset into the result set to begin enumeration.
|
149
|
-
# @yield Optional. If a block is given, each top game is yielded.
|
150
|
-
# @yieldparam [Game] game Current game.
|
151
|
-
# @see Game Game
|
152
|
-
# @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/games.md#get-gamestop GET /games/top
|
153
|
-
# @return [Array<Game>] Games sorted by number of current viewers on Twitch, highest first, if no block is given.
|
154
|
-
# @return [nil] If a block is given.
|
155
|
-
def top(options = {}, &block)
|
156
|
-
params = {}
|
157
|
-
|
158
|
-
if options[:hls]
|
159
|
-
params[:hls] = true
|
160
|
-
end
|
161
|
-
|
162
|
-
return @query.connection.accumulate(
|
163
|
-
:path => 'games/top',
|
164
|
-
:params => params,
|
165
|
-
:json => 'top',
|
166
|
-
:create => -> hash { Game.new(hash, @query) },
|
167
|
-
:limit => options[:limit],
|
168
|
-
:offset => options[:offset],
|
169
|
-
&block
|
170
|
-
)
|
171
|
-
end
|
172
|
-
|
173
|
-
# Get a list of games with names similar to the specified name.
|
174
|
-
# @example
|
175
|
-
# Twitch.games.find(:name => 'diablo')
|
176
|
-
# @example
|
177
|
-
# Twitch.games.find(:name => 'starcraft', :live => true)
|
178
|
-
# @example
|
179
|
-
# Twitch.games.find(:name => 'starcraft') do |suggestion|
|
180
|
-
# next if suggestion.name =~ /heart of the swarm/i
|
181
|
-
# puts suggestion.name
|
182
|
-
# end
|
183
|
-
# @param options [Hash] Search criteria.
|
184
|
-
# @option options [String] :name Game name search term. This can be a partial name, e.g. `"league"`.
|
185
|
-
# @option options [Boolean] :live (false) If `true`, only returns games that are currently live on at least one channel.
|
186
|
-
# @option options [Fixnum] :limit (nil) Limit on the number of results returned.
|
187
|
-
# @yield Optional. If a block is given, each game suggestion is yielded.
|
188
|
-
# @yieldparam [GameSuggestion] suggestion Current game suggestion.
|
189
|
-
# @see GameSuggestion GameSuggestion
|
190
|
-
# @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/search.md#get-searchgames GET /search/games
|
191
|
-
# @raise [ArgumentError] If `:name` is not specified.
|
192
|
-
# @return [Array<GameSuggestion>] Games matching the criteria, if no block is given.
|
193
|
-
# @return [nil] If a block is given.
|
194
|
-
def find(options)
|
195
|
-
raise ArgumentError, 'options' if options.nil?
|
196
|
-
raise ArgumentError, 'name' if options[:name].nil?
|
197
|
-
|
198
|
-
params = {
|
199
|
-
:query => options[:name],
|
200
|
-
:type => 'suggest'
|
201
|
-
}
|
202
|
-
|
203
|
-
if options[:live]
|
204
|
-
params.merge!(:live => true)
|
205
|
-
end
|
206
|
-
|
207
|
-
return @query.connection.accumulate(
|
208
|
-
:path => 'search/games',
|
209
|
-
:params => params,
|
210
|
-
:json => 'games',
|
211
|
-
:create => GameSuggestion,
|
212
|
-
:limit => options[:limit]
|
213
|
-
)
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
1
|
+
module Twitch::V2
|
2
|
+
# Games are categories (e.g. League of Legends, Diablo 3) used by streams and channels.
|
3
|
+
# Games can be searched for by query.
|
4
|
+
# @see Games#top Games#top
|
5
|
+
# @see Games#find Games#find
|
6
|
+
# @see Games
|
7
|
+
class Game
|
8
|
+
include Twitch::IdEquality
|
9
|
+
|
10
|
+
# @private
|
11
|
+
def initialize(hash, query)
|
12
|
+
@query = query
|
13
|
+
@channel_count = hash['channels']
|
14
|
+
@viewer_count = hash['viewers']
|
15
|
+
|
16
|
+
game = hash['game']
|
17
|
+
@id = game['_id']
|
18
|
+
@name = game['name']
|
19
|
+
@giantbomb_id = game['giantbomb_id']
|
20
|
+
@box_images = Images.new(game['box'])
|
21
|
+
@logo_images = Images.new(game['logo'])
|
22
|
+
end
|
23
|
+
|
24
|
+
# Get streams for this game.
|
25
|
+
# @example
|
26
|
+
# game.streams
|
27
|
+
# @example
|
28
|
+
# game.streams(:embeddable => true, :limit => 20)
|
29
|
+
# @example
|
30
|
+
# game.streams do |stream|
|
31
|
+
# next if stream.viewer_count < 1000
|
32
|
+
# puts stream.url
|
33
|
+
# end
|
34
|
+
# @param options [Hash] Search criteria.
|
35
|
+
# @option options [Array<String, Channel, #name>] :channel Only return streams for these channels.
|
36
|
+
# If a channel is not currently streaming, it is omitted. You must specify an array of channels
|
37
|
+
# or channel names.
|
38
|
+
# @option options [Boolean] :embeddable (nil) If `true`, limit the streams to those that can be embedded. If `false` or `nil`, do not limit.
|
39
|
+
# @option options [Boolean] :hls (nil) If `true`, limit the streams to those using HLS (HTTP Live Streaming). If `false` or `nil`, do not limit.
|
40
|
+
# @option options [Fixnum] :limit (nil) Limit on the number of results returned.
|
41
|
+
# @option options [Fixnum] :offset (0) Offset into the result set to begin enumeration.
|
42
|
+
# @yield Optional. If a block is given, each stream found is yielded.
|
43
|
+
# @yieldparam [Stream] stream Current stream.
|
44
|
+
# @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/streams.md#get-streams GET /streams
|
45
|
+
# @raise [ArgumentError] If `:channel` is not an array.
|
46
|
+
# @return [Array<Stream>] Streams matching the specified criteria, if no block is given.
|
47
|
+
# @return [nil] If a block is given.
|
48
|
+
def streams(options = {}, &block)
|
49
|
+
@query.streams.find(options.merge(:game => @name), &block)
|
50
|
+
end
|
51
|
+
|
52
|
+
# @example
|
53
|
+
# 21799
|
54
|
+
# @return [Fixnum] Unique Twitch ID.
|
55
|
+
attr_reader :id
|
56
|
+
|
57
|
+
# @example
|
58
|
+
# "League of Legends"
|
59
|
+
# @return [String] User-friendly game name.
|
60
|
+
attr_reader :name
|
61
|
+
|
62
|
+
# @example
|
63
|
+
# 24024
|
64
|
+
# @return [Fixnum] Unique game ID for GiantBomb.com.
|
65
|
+
attr_reader :giantbomb_id
|
66
|
+
|
67
|
+
# @return [Images] Set of images for the game's box art.
|
68
|
+
attr_reader :box_images
|
69
|
+
|
70
|
+
# @return [Images] Set of images for the game's logo.
|
71
|
+
attr_reader :logo_images
|
72
|
+
|
73
|
+
# @example
|
74
|
+
# 802
|
75
|
+
# @return [Fixnum] Total number of channels currently streaming this game on Twitch.
|
76
|
+
attr_reader :channel_count
|
77
|
+
|
78
|
+
# @example
|
79
|
+
# 68592
|
80
|
+
# @return [Fixnum] Total number of viewers across all channels currently watching this game on Twitch.
|
81
|
+
attr_reader :viewer_count
|
82
|
+
end
|
83
|
+
|
84
|
+
# A game suggestion returned by Twitch when searching for games via `Twitch.games.find`.
|
85
|
+
# @see Games#find Games#find
|
86
|
+
class GameSuggestion
|
87
|
+
include Twitch::IdEquality
|
88
|
+
|
89
|
+
# @private
|
90
|
+
def initialize(hash)
|
91
|
+
@id = hash['_id']
|
92
|
+
@name = hash['name']
|
93
|
+
@giantbomb_id = hash['giantbomb_id']
|
94
|
+
@popularity = hash['popularity']
|
95
|
+
@box_images = Images.new(hash['box'])
|
96
|
+
@logo_images = Images.new(hash['logo'])
|
97
|
+
end
|
98
|
+
|
99
|
+
# @example
|
100
|
+
# 155075940
|
101
|
+
# @return [Fixnum] Unique Twitch ID.
|
102
|
+
attr_reader :id
|
103
|
+
|
104
|
+
# @example
|
105
|
+
# "Dark Souls"
|
106
|
+
# @return [String] Game name.
|
107
|
+
attr_reader :name
|
108
|
+
|
109
|
+
# @example
|
110
|
+
# 32697
|
111
|
+
# @return [Fixnum] Unique game ID for GiantBomb.com.
|
112
|
+
attr_reader :giantbomb_id
|
113
|
+
|
114
|
+
# @example
|
115
|
+
# 67
|
116
|
+
# @return [Fixnum] Relative popularity metric. Higher number means more popular. This value only has meaning relative to other popularity values.
|
117
|
+
attr_reader :popularity
|
118
|
+
|
119
|
+
# @return [Images] Set of images for the game's box art.
|
120
|
+
attr_reader :box_images
|
121
|
+
|
122
|
+
# @return [Images] Set of images for the game's logo.
|
123
|
+
attr_reader :logo_images
|
124
|
+
end
|
125
|
+
|
126
|
+
# Query class for finding top games or finding games by name.
|
127
|
+
# @see Game
|
128
|
+
# @see GameSuggestion
|
129
|
+
class Games
|
130
|
+
# @private
|
131
|
+
def initialize(query)
|
132
|
+
@query = query
|
133
|
+
end
|
134
|
+
|
135
|
+
# Get a list of games with the highest number of current viewers on Twitch.
|
136
|
+
# @example
|
137
|
+
# Twitch.games.top
|
138
|
+
# @example
|
139
|
+
# Twitch.games.top(:limit => 10)
|
140
|
+
# @example
|
141
|
+
# Twitch.games.top do |game|
|
142
|
+
# next if game.viewer_count < 10000
|
143
|
+
# puts game.name
|
144
|
+
# end
|
145
|
+
# @param options [Hash] Filter criteria.
|
146
|
+
# @option options [Boolean] :hls (nil) If `true`, limit the games to those that have any streams using HLS (HTTP Live Streaming). If `false` or `nil`, do not limit.
|
147
|
+
# @option options [Fixnum] :limit (nil) Limit on the number of results returned.
|
148
|
+
# @option options [Fixnum] :offset (0) Offset into the result set to begin enumeration.
|
149
|
+
# @yield Optional. If a block is given, each top game is yielded.
|
150
|
+
# @yieldparam [Game] game Current game.
|
151
|
+
# @see Game Game
|
152
|
+
# @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/games.md#get-gamestop GET /games/top
|
153
|
+
# @return [Array<Game>] Games sorted by number of current viewers on Twitch, highest first, if no block is given.
|
154
|
+
# @return [nil] If a block is given.
|
155
|
+
def top(options = {}, &block)
|
156
|
+
params = {}
|
157
|
+
|
158
|
+
if options[:hls]
|
159
|
+
params[:hls] = true
|
160
|
+
end
|
161
|
+
|
162
|
+
return @query.connection.accumulate(
|
163
|
+
:path => 'games/top',
|
164
|
+
:params => params,
|
165
|
+
:json => 'top',
|
166
|
+
:create => -> hash { Game.new(hash, @query) },
|
167
|
+
:limit => options[:limit],
|
168
|
+
:offset => options[:offset],
|
169
|
+
&block
|
170
|
+
)
|
171
|
+
end
|
172
|
+
|
173
|
+
# Get a list of games with names similar to the specified name.
|
174
|
+
# @example
|
175
|
+
# Twitch.games.find(:name => 'diablo')
|
176
|
+
# @example
|
177
|
+
# Twitch.games.find(:name => 'starcraft', :live => true)
|
178
|
+
# @example
|
179
|
+
# Twitch.games.find(:name => 'starcraft') do |suggestion|
|
180
|
+
# next if suggestion.name =~ /heart of the swarm/i
|
181
|
+
# puts suggestion.name
|
182
|
+
# end
|
183
|
+
# @param options [Hash] Search criteria.
|
184
|
+
# @option options [String] :name Game name search term. This can be a partial name, e.g. `"league"`.
|
185
|
+
# @option options [Boolean] :live (false) If `true`, only returns games that are currently live on at least one channel.
|
186
|
+
# @option options [Fixnum] :limit (nil) Limit on the number of results returned.
|
187
|
+
# @yield Optional. If a block is given, each game suggestion is yielded.
|
188
|
+
# @yieldparam [GameSuggestion] suggestion Current game suggestion.
|
189
|
+
# @see GameSuggestion GameSuggestion
|
190
|
+
# @see https://github.com/justintv/Twitch-API/blob/master/v2_resources/search.md#get-searchgames GET /search/games
|
191
|
+
# @raise [ArgumentError] If `:name` is not specified.
|
192
|
+
# @return [Array<GameSuggestion>] Games matching the criteria, if no block is given.
|
193
|
+
# @return [nil] If a block is given.
|
194
|
+
def find(options)
|
195
|
+
raise ArgumentError, 'options' if options.nil?
|
196
|
+
raise ArgumentError, 'name' if options[:name].nil?
|
197
|
+
|
198
|
+
params = {
|
199
|
+
:query => options[:name],
|
200
|
+
:type => 'suggest'
|
201
|
+
}
|
202
|
+
|
203
|
+
if options[:live]
|
204
|
+
params.merge!(:live => true)
|
205
|
+
end
|
206
|
+
|
207
|
+
return @query.connection.accumulate(
|
208
|
+
:path => 'search/games',
|
209
|
+
:params => params,
|
210
|
+
:json => 'games',
|
211
|
+
:create => GameSuggestion,
|
212
|
+
:limit => options[:limit]
|
213
|
+
)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|