Module: Googol::PlaylistItems

Included in:
YoutubeAccount
Defined in:
lib/googol/youtube_account/playlist_items.rb

Overview

Separate module to group YoutubeAccount methods related to playlist items.

Instance Method Summary collapse

Instance Method Details

#add_item_to!(playlist_id, item = {}) ⇒ Object

Note:

Google API allows other types of items to be added to a playlist but for now we are just using videos. If you need other types, we can just expand this method.

Add an item to a Youtube playlist.



16
17
18
19
20
21
# File 'lib/googol/youtube_account/playlist_items.rb', line 16

def add_item_to!(playlist_id, item = {})
  resource = {videoId: fetch!(item, :video_id), kind: 'youtube#video'}
  youtube_request! method: :post, json: true,
    path: '/playlistItems?part=snippet',
    body: {snippet: {playlistId: playlist_id, resourceId: resource}}
end

#add_videos_to!(playlist_id, video_ids = []) ⇒ Object

Adds an array of videos to a Youtube playlist.



43
44
45
# File 'lib/googol/youtube_account/playlist_items.rb', line 43

def add_videos_to!(playlist_id, video_ids = [])
  video_ids.map{|video_id| add_item_to! playlist_id, video_id: video_id}
end

#remove_all_items_from!(playlist_id, filters = {}) ⇒ Object

Remove all items from a Youtube playlist.



30
31
32
33
34
# File 'lib/googol/youtube_account/playlist_items.rb', line 30

def remove_all_items_from!(playlist_id, filters = {})
  items_of(playlist_id, filters).map do |item_id|
    remove_item_from! playlist_id, item_id
  end
end