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, #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) ⇒ 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:



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

def add_video(video_id)
  playlist_items.insert video_params(video_id), ignore_errors: true
end

#add_video!(video_id) ⇒ Object



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

def add_video!(video_id)
  playlist_items.insert video_params(video_id)
end

#add_videos(video_ids = []) ⇒ Object



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

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

#add_videos!(video_ids = []) ⇒ Object



59
60
61
# File 'lib/yt/models/playlist.rb', line 59

def add_videos!(video_ids = [])
  video_ids.map{|video_id| add_video! video_id}
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



63
64
65
# File 'lib/yt/models/playlist.rb', line 63

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

#exists?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/yt/models/playlist.rb', line 35

def exists?
  !@id.nil?
end

#update(attributes = {}) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/yt/models/playlist.rb', line 26

def update(attributes = {})
  super attributes do |data|
    @id = data['id']
    @snippet = Snippet.new data: data['snippet'] if data['snippet']
    @status = Status.new data: data['status'] if data['status']
    true
  end
end