Class: Twitch::V2::Videos
- Inherits:
-
Object
- Object
- Twitch::V2::Videos
- Defined in:
- lib/kappa/video.rb
Overview
Query class for finding videos.
Instance Method Summary collapse
-
#for_channel(channel, options = {}) {|video| ... } ⇒ Array<Video>?
Get the videos for a channel, most recently created first.
-
#get(id) ⇒ Video
Get a video by ID.
-
#top(options = {}) {|video| ... } ⇒ Array<Video>?
Get the list of most popular videos based on view count.
Instance Method Details
#for_channel(channel, options = {}) {|video| ... } ⇒ Array<Video>?
Get the videos for a channel, most recently created first.
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 |
# File 'lib/kappa/video.rb', line 200 def for_channel(channel, = {}) if channel.respond_to?(:name) channel_name = channel.name else channel_name = channel.to_s end params = {} type = [:type] || :highlights if !type.nil? if ![:broadcasts, :highlights].include?(type) raise ArgumentError, 'type' end params[:broadcasts] = (type == :broadcasts) end name = CGI.escape(channel_name) return @query.connection.accumulate( :path => "channels/#{name}/videos", :params => params, :json => 'videos', :create => -> hash { Video.new(hash, @query) }, :limit => [:limit], :offset => [:offset] ) end |
#get(id) ⇒ Video
Get a video by ID.
120 121 122 123 124 125 126 127 128 |
# File 'lib/kappa/video.rb', line 120 def get(id) raise ArgumentError, 'id' if !id || id.strip.empty? id = CGI.escape(id) Twitch::Status.map(404 => nil) do json = @query.connection.get("videos/#{id}") Video.new(json, @query) end end |
#top(options = {}) {|video| ... } ⇒ Array<Video>?
Note:
The number of videos returned is potentially very large, so it's recommended that you specify a :limit
.
Get the list of most popular videos based on view count.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/kappa/video.rb', line 154 def top( = {}, &block) params = {} if [:game] params[:game] = [:game] end period = [:period] || :week if ![:week, :month, :all].include?(period) raise ArgumentError, 'period' end params[:period] = period.to_s return @query.connection.accumulate( :path => 'videos/top', :params => params, :json => 'videos', :create => -> hash { Video.new(hash, @query) }, :limit => [:limit], :offset => [:offset], &block ) end |