Class: Twitch::V2::Streams
- Inherits:
-
Object
- Object
- Twitch::V2::Streams
- Defined in:
- lib/kappa/stream.rb
Overview
Query class for finding featured streams or streams meeting certain criteria.
Instance Method Summary collapse
-
#all(options = {}) {|stream| ... } ⇒ Array<Stream>?
Get all currently live streams sorted by descending viewer count.
-
#featured(options = {}) {|stream| ... } ⇒ Array<Stream>?
Get the currently featured (promoted) streams.
-
#find(options) {|stream| ... } ⇒ Array<Stream>?
Get streams for a specific game, for a set of channels, or by other criteria, sorted by descending viewer count.
-
#get(stream_name) ⇒ Stream?
Get a live stream by name.
-
#summary ⇒ StreamSummary
Get site-wide stream summary statistics.
Instance Method Details
#all(options = {}) {|stream| ... } ⇒ Array<Stream>?
Get all currently live streams sorted by descending viewer count.
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/kappa/stream.rb', line 146 def all( = {}, &block) return @query.connection.accumulate( :path => 'streams', :json => 'streams', :create => -> hash { Stream.new(hash, @query) }, :limit => [:limit], :offset => [:offset], &block ) end |
#featured(options = {}) {|stream| ... } ⇒ Array<Stream>?
There is no guarantee of how many streams are featured at any given time.
Get the currently featured (promoted) streams. This includes the streams shown on the Twitch homepage.
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/kappa/stream.rb', line 258 def featured( = {}, &block) params = {} if [:hls] params[:hls] = true end return @query.connection.accumulate( :path => 'streams/featured', :params => params, :json => 'featured', :sub_json => 'stream', :create => -> hash { Stream.new(hash, @query) }, :limit => [:limit], :offset => [:offset], &block ) end |
#find(options) {|stream| ... } ⇒ Array<Stream>?
Get streams for a specific game, for a set of channels, or by other criteria, sorted by descending viewer count.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/kappa/stream.rb', line 187 def find(, &block) check = .dup check.delete(:limit) check.delete(:offset) raise ArgumentError, 'options' if check.empty? params = {} channels = [:channel] if channels if !channels.respond_to?(:map) raise ArgumentError, ':channel' end params[:channel] = channels.map { |channel| if channel.respond_to?(:name) channel.name else channel.to_s end }.join(',') end game = [:game] if game if game.respond_to?(:name) params[:game] = game.name else params[:game] = game.to_s end end if [:hls] params[:hls] = true end if [:embeddable] params[:embeddable] = true end return @query.connection.accumulate( :path => 'streams', :params => params, :json => 'streams', :create => -> hash { Stream.new(hash, @query) }, :limit => [:limit], :offset => [:offset], &block ) end |
#get(stream_name) ⇒ Stream?
Get a live stream by name.
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/kappa/stream.rb', line 116 def get(stream_name) name = CGI.escape(stream_name) # HTTP 422 can happen if the stream is associated with a Justin.tv account. Twitch::Status.map(404 => nil, 422 => nil) do json = @query.connection.get("streams/#{name}") stream = json['stream'] stream.nil? ? nil : Stream.new(stream, @query) end end |
#summary ⇒ StreamSummary
Get site-wide stream summary statistics.
284 285 286 287 |
# File 'lib/kappa/stream.rb', line 284 def summary json = @query.connection.get('streams/summary') StreamSummary.new(json) end |