class Yt::Models::PlaylistItem

Provides methods to interact with YouTube playlist items. @see developers.google.com/youtube/v3/docs/playlistItems

Public Class Methods

new(options = {}) click to toggle source

@private Override Resource's new to set video if the response includes it

Calls superclass method
# File lib/yt/models/playlist_item.rb, line 93
def initialize(options = {})
  super options
  @video = options[:video] if options[:video]
end

Public Instance Methods

delete(options = {}) click to toggle source

Deletes the playlist item. @return [Boolean] whether the playlist item does not exist anymore. @raise [Yt::Errors::Unauthorized] if {Resource#auth auth} is not an

authenticated Yt::Account with permissions to delete the item.
# File lib/yt/models/playlist_item.rb, line 61
def delete(options = {})
  do_delete {@id = nil}
  !exists?
end
exists?() click to toggle source

@private

# File lib/yt/models/playlist_item.rb, line 87
def exists?
  !@id.nil?
end
position() click to toggle source

@return [Integer] the order in which the item appears in a playlist.

The value is zero-based, so the first item has a position of 0.
# File lib/yt/models/playlist_item.rb, line 51
def position
  ensure_complete_snippet :position
end
update(attributes = {}) click to toggle source

Updates the attributes of a playlist item. @return [Boolean] whether the item was successfully updated. @raise [Yt::Errors::Unauthorized] if {Resource#auth auth} is not an

authenticated Yt::Account with permissions to update the item.

@param [Hash] attributes the attributes to update. @option attributes [Integer] the order in which the item should appear

in a playlist. The value is zero-based, so the first position of 0.
Calls superclass method
# File lib/yt/models/playlist_item.rb, line 73
def update(attributes = {})
  super
end
video() click to toggle source

@return [Yt::Models::Video] the video referred by the item.

# File lib/yt/models/playlist_item.rb, line 80
def video
  @video ||= Video.new id: video_id, auth: @auth if video_id
end
video_id() click to toggle source

@return [String] the ID of the video referred by the item.

# File lib/yt/models/playlist_item.rb, line 45
def video_id
  snippet.resource_id['videoId']
end

Private Instance Methods

delete_params() click to toggle source
Calls superclass method
# File lib/yt/models/playlist_item.rb, line 104
def delete_params
  super.tap do |params|
    params[:params] ||= {}
    params[:params].merge! @auth.playlist_items_params
  end
end
resource_id() click to toggle source
# File lib/yt/models/playlist_item.rb, line 100
def resource_id
  {kind: 'youtube#video', videoId: video_id}
end
update_parts() click to toggle source

@see developers.google.com/youtube/v3/docs/playlistItems/update

# File lib/yt/models/playlist_item.rb, line 112
def update_parts
  keys = [:position, :playlist_id, :resource_id]
  snippet = {keys: keys, required: true}
  {snippet: snippet}
end