Class: Yt::Collections::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/yt/collections/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



13
14
15
16
# File 'lib/yt/collections/base.rb', line 13

def initialize(options = {})
  @parent = options[:parent]
  @auth = options[:auth]
end

Class Method Details

.of(parent) ⇒ Object



18
19
20
# File 'lib/yt/collections/base.rb', line 18

def self.of(parent)
  new parent: parent, auth: parent.auth
end

Instance Method Details

#includes(*relationships) ⇒ Object



44
45
46
47
48
49
# File 'lib/yt/collections/base.rb', line 44

def includes(*relationships)
  self.tap do
    @items = []
    @included_relationships = relationships
  end
end

#where(requirements = {}) ⇒ Object

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

Examples:

Return the first video of a channel (no requirements):

channel.videos.first

Return the first long video of a channel by video count:

channel.videos.where(order: 'viewCount', video_duration: 'long').first


37
38
39
40
41
42
# File 'lib/yt/collections/base.rb', line 37

def where(requirements = {})
  self.tap do
    @items = []
    @where_params = requirements
  end
end