Class: Yt::Collections::PlaylistItems

Inherits:
Resources show all
Defined in:
lib/yt/collections/playlist_items.rb

Instance Method Summary collapse

Methods inherited from Resources

#delete_all

Methods inherited from Base

#initialize, of, #where

Methods included from Actions::List

#first!

Constructor Details

This class inherits a constructor from Yt::Collections::Base

Instance Method Details

#insert(attrs = {}, options = {}) ⇒ Object

attrs are id and kind



8
9
10
11
12
13
14
15
16
# File 'lib/yt/collections/playlist_items.rb', line 8

def insert(attrs = {}, options = {}) #
  resource = {kind: "youtube##{attrs[:kind]}"}
  resource["#{attrs[:kind]}Id"] = attrs[:id]
  snippet = {playlistId: @parent.id, resourceId: resource}
  do_insert body: {snippet: snippet}, params: {part: 'snippet,status'}
rescue Yt::Error => error
  ignorable_errors = error.reasons & ['videoNotFound', 'forbidden']
  raise error unless options[:ignore_errors] && ignorable_errors.any?
end