class Yt::Collections::PlaylistItems

Public Instance Methods

insert(attributes = {}, options = {}) click to toggle source
Calls superclass method
# File lib/yt/collections/playlist_items.rb, line 7
def insert(attributes = {}, options = {})
  super attributes.merge(playlist_id: @parent.id), options
rescue Yt::Error => error
  ignorable_errors = error.reasons & ['videoNotFound', 'forbidden']
  raise error unless options[:ignore_errors] && ignorable_errors.any?
end

Private Instance Methods

attributes_for_new_item(data) click to toggle source
Calls superclass method
# File lib/yt/collections/playlist_items.rb, line 16
def attributes_for_new_item(data)
  snippet = data.fetch 'snippet', {}
  data['snippet'].reverse_merge! complete: snippet.key?('position')
  super(data).tap do |attributes|
    attributes[:video] = data['video']
  end
end
eager_load_items_from(items) click to toggle source
Calls superclass method
# File lib/yt/collections/playlist_items.rb, line 24
def eager_load_items_from(items)
  if included_relationships.include?(:video)
    video_ids = items.map{|item| item['snippet']['resourceId']['videoId']}.uniq
    conditions = {id: video_ids.join(',')}
    conditions[:part] = 'snippet,status,statistics,contentDetails'
    videos = Collections::Videos.new(auth: @auth).where conditions
    items.each do |item|
      video = videos.find{|v| v.id == item['snippet']['resourceId']['videoId']}
      item['video'] = video
    end
  end
  super
end
insert_params() click to toggle source

For inserting a playlist item with content owner auth. @see developers.google.com/youtube/v3/docs/playlistItems/insert

Calls superclass method
# File lib/yt/collections/playlist_items.rb, line 54
def insert_params
  params = super
  params[:params] ||= {}
  params[:params].merge! @auth.insert_playlist_item_params
  params
end
insert_parts() click to toggle source
# File lib/yt/collections/playlist_items.rb, line 48
def insert_parts
  {snippet: {keys: [:playlist_id, :resource_id, :position]}}
end
list_params() click to toggle source

@return [Hash] the parameters to submit to YouTube to list playlist items. @see developers.google.com/youtube/v3/docs/playlistItems/list

Calls superclass method
# File lib/yt/collections/playlist_items.rb, line 40
def list_params
  super.tap{|params| params[:params] = playlist_items_params}
end
playlist_items_params() click to toggle source
# File lib/yt/collections/playlist_items.rb, line 44
def playlist_items_params
  resources_params.merge playlist_id: @parent.id
end