Class: Yt::Models::Playlist
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
#has_report
#has_viewer_percentages
#has_one
#has_many
#has_authentication
Instance Attribute Details
Returns the playlist’s items.
12
|
# File 'lib/yt/models/playlist.rb', line 12
has_many :playlist_items
|
Instance Method Details
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.
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.
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
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
|