Class: Yt::Models::Playlist

Inherits:
Resource show all
Defined in:
lib/yt/models/playlist.rb

Overview

Provides methods to interact with YouTube playlists.

Instance Attribute Summary collapse

Attributes inherited from Resource

#auth

Instance Method Summary collapse

Methods inherited from Resource

#initialize, #kind, #update, #username

Methods included from Associations::HasReports

#has_report

Methods included from Associations::HasViewerPercentages

#has_viewer_percentages

Methods included from Associations::HasOne

#has_one

Methods included from Associations::HasMany

#has_many

Methods included from Associations::HasAuthentication

#has_authentication

Constructor Details

This class inherits a constructor from Yt::Models::Resource

Instance Attribute Details

#playlist_itemsYt::Collections::PlaylistItems (readonly)

Returns the playlist’s items.

Returns:



12
# File 'lib/yt/models/playlist.rb', line 12

has_many :playlist_items

Instance Method Details

#add_video(video_id, attributes = {}) ⇒ Yt::PlaylistItem

Adds a video to the playlist Does not raise an error if the video cannot be added (e.g., unknown).

This method requires auth to return an authenticated instance of Account with permissions to update the playlist.

Returns:

Raises:



38
39
40
41
# File 'lib/yt/models/playlist.rb', line 38

def add_video(video_id, attributes = {})
  playlist_item_params = playlist_item_params(video_id, attributes)
  playlist_items.insert playlist_item_params, ignore_errors: true
end

#add_video!(video_id, attributes = {}) ⇒ Object



43
44
45
46
# File 'lib/yt/models/playlist.rb', line 43

def add_video!(video_id, attributes = {})
  playlist_item_params = playlist_item_params(video_id, attributes)
  playlist_items.insert playlist_item_params
end

#add_videos(video_ids = [], attributes = {}) ⇒ Object



48
49
50
# File 'lib/yt/models/playlist.rb', line 48

def add_videos(video_ids = [], attributes = {})
  video_ids.map{|video_id| add_video video_id, attributes}
end

#add_videos!(video_ids = [], attributes = {}) ⇒ Object



52
53
54
# File 'lib/yt/models/playlist.rb', line 52

def add_videos!(video_ids = [], attributes = {})
  video_ids.map{|video_id| add_video! video_id, attributes}
end

#delete(options = {}) ⇒ Boolean

Deletes the playlist.

This method requires auth to return an authenticated instance of Account with permissions to delete the playlist.

Returns:

  • (Boolean)

    whether the playlist does not exist anymore.

Raises:



21
22
23
24
# File 'lib/yt/models/playlist.rb', line 21

def delete(options = {})
  do_delete {@id = nil}
  !exists?
end

#delete_playlist_items(attrs = {}) ⇒ Object



56
57
58
# File 'lib/yt/models/playlist.rb', line 56

def delete_playlist_items(attrs = {})
  playlist_items.delete_all attrs
end

#exists?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/yt/models/playlist.rb', line 26

def exists?
  !@id.nil?
end