class Yt::Collections::RelatedPlaylists

Private Instance Methods

eager_load_items_from(items) click to toggle source

Since there are at most 5 related playlists, they can be eager-loaded.

# File lib/yt/collections/related_playlists.rb, line 32
def eager_load_items_from(items)
  conditions = {id: items.values.join(','), part: 'snippet,status'}
  Collections::Playlists.new(auth: @auth).where conditions
end
extract_items(list) click to toggle source

The related playlists are nested inside the “relatedPlaylists” key.

Calls superclass method
# File lib/yt/collections/related_playlists.rb, line 25
def extract_items(list)
  if (items = super).any?
    items.first['contentDetails'].fetch 'relatedPlaylists', {}
  end
end
list_resources() click to toggle source

Retrieving related playlists requires to hit the /channels endpoint.

# File lib/yt/collections/related_playlists.rb, line 10
def list_resources
  'channels'
end
new_item(playlist) click to toggle source

Related playlists are eager-loaded, there’s no need to load them again.

# File lib/yt/collections/related_playlists.rb, line 38
def new_item(playlist)
  playlist
end
playlists_params() click to toggle source

The related playlists are included in the content details of a channel.

# File lib/yt/collections/related_playlists.rb, line 15
def playlists_params
  {part: 'contentDetails', id: @parent.id}
end
resource_class() click to toggle source

The object to create is “Yt::Models::Playlist”, not “RelatedPlaylist”

# File lib/yt/collections/related_playlists.rb, line 20
def resource_class
  Yt::Models::Playlist
end