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.
62
63
64
|
# File 'lib/yt/models/playlist.rb', line 62
def add_video(video_id)
playlist_items.insert video_params(video_id), ignore_errors: true
end
|
#add_video!(video_id) ⇒ Object
66
67
68
|
# File 'lib/yt/models/playlist.rb', line 66
def add_video!(video_id)
playlist_items.insert video_params(video_id)
end
|
#add_videos(video_ids = []) ⇒ Object
70
71
72
|
# File 'lib/yt/models/playlist.rb', line 70
def add_videos(video_ids = [])
video_ids.map{|video_id| add_video video_id}
end
|
#add_videos!(video_ids = []) ⇒ Object
74
75
76
|
# File 'lib/yt/models/playlist.rb', line 74
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
78
79
80
|
# File 'lib/yt/models/playlist.rb', line 78
def delete_playlist_items(attrs = {})
playlist_items.delete_all attrs
end
|
#exists? ⇒ Boolean
50
51
52
|
# File 'lib/yt/models/playlist.rb', line 50
def exists?
!@id.nil?
end
|
#update(attributes = {}) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/yt/models/playlist.rb', line 26
def update(attributes = {})
underscore_keys! attributes
body = {id: @id}.tap do |body|
update_parts.each do |part, options|
if (options[:keys] & attributes.keys).any? || options[:required]
body[part] = {}.tap do |hash|
options[:keys].map do |key|
hash[camelize key] = attributes[key] || send(key)
end
end
end
end
end
part = body.except(:id).keys.join(',')
do_update(params: {part: part}, 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
|