class Yt::Collections::Base
Public Class Methods
new(options = {})
click to toggle source
# File lib/yt/collections/base.rb, line 13 def initialize(options = {}) @parent = options[:parent] @auth = options[:auth] end
of(parent)
click to toggle source
# File lib/yt/collections/base.rb, line 18 def self.of(parent) new parent: parent, auth: parent.auth end
Public Instance Methods
includes(*relationships)
click to toggle source
# File lib/yt/collections/base.rb, line 44 def includes(*relationships) self.tap do @items = [] @included_relationships = relationships end end
where(requirements = {})
click to toggle source
Adds requirements to the collection in order to limit the result of List methods to only items that match the requirements.
Under the hood, all the requirements are passed to the YouTube API as query parameters, after transforming the keys to camel-case.
To know which requirements are available for each collection, check the documentation of the corresponding YouTube API endpoint. For instance the list of valid requirements to filter a list of videos are at developers.google.com/youtube/v3/docs/search/list
@example Return the first video of a channel (no requirements):
channel.videos.first
@example Return the first long video of a channel by video count:
channel.videos.where(order: 'viewCount', video_duration: 'long').first
# File lib/yt/collections/base.rb, line 37 def where(requirements = {}) self.tap do @items = [] @where_params = requirements end end
Private Instance Methods
apply_where_params!(params = {})
click to toggle source
# File lib/yt/collections/base.rb, line 53 def apply_where_params!(params = {}) params.merge!(@where_params ||= {}) end
included_relationships()
click to toggle source
# File lib/yt/collections/base.rb, line 57 def included_relationships @included_relationships || [] end