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
Instance Attribute Details
Returns the playlist’s items.
11
|
# File 'lib/yt/models/playlist.rb', line 11
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.
55
56
57
|
# File 'lib/yt/models/playlist.rb', line 55
def add_video(video_id)
playlist_items.insert video_params(video_id), ignore_errors: true
end
|
#add_video!(video_id) ⇒ Object
59
60
61
|
# File 'lib/yt/models/playlist.rb', line 59
def add_video!(video_id)
playlist_items.insert video_params(video_id)
end
|
#add_videos(video_ids = []) ⇒ Object
63
64
65
|
# File 'lib/yt/models/playlist.rb', line 63
def add_videos(video_ids = [])
video_ids.map{|video_id| add_video video_id}
end
|
#add_videos!(video_ids = []) ⇒ Object
67
68
69
|
# File 'lib/yt/models/playlist.rb', line 67
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.
20
21
22
23
|
# File 'lib/yt/models/playlist.rb', line 20
def delete(options = {})
do_delete {@id = nil}
!exists?
end
|
#delete_playlist_items(attrs = {}) ⇒ Object
71
72
73
|
# File 'lib/yt/models/playlist.rb', line 71
def delete_playlist_items(attrs = {})
playlist_items.delete_all attrs
end
|
#exists? ⇒ Boolean
43
44
45
|
# File 'lib/yt/models/playlist.rb', line 43
def exists?
!@id.nil?
end
|
#update(options = {}) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/yt/models/playlist.rb', line 25
def update(options = {})
options[:title] ||= title
options[:description] ||= description
options[:tags] ||= tags
options[:privacy_status] ||= privacy_status
snippet = options.slice :title, :description, :tags
status = {privacyStatus: options[:privacy_status]}
body = {id: @id, snippet: snippet, status: status}
do_update(params: {part: 'snippet,status'}, body: body) 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
|