class Yt::PlaylistItem
Provides methods to interact with YouTube playlist items. @see developers.google.com/youtube/v3/docs/playlistItems
Public Class Methods
insert(playlist_id:, video_id:)
click to toggle source
@return [Yt::PlaylistItem] the item created by appending the given
video to the given playlist.
# File lib/yt/playlist_item.rb, line 61 def self.insert(playlist_id:, video_id:) parts = %i(id snippet) items = -> (body) { [body] } # the response body only includes one item resource_id = {kind: 'youtube#video', videoId: video_id} snippet = {playlistId: playlist_id, resourceId: resource_id} Relation.new(self, parts: parts, extract_items: items) do |options| post '/youtube/v3/playlistItems', {part: 'snippet'}, {snippet: snippet} end.first end
Public Instance Methods
delete()
click to toggle source
@return [Boolean] whether the item was removed from the playlist.
# File lib/yt/playlist_item.rb, line 73 def delete items = -> (body) { [{}] } # the response body is empty Relation.new(PlaylistItem, id: id, extract_items: items) do |options| delete '/youtube/v3/playlistItems', id: options[:id] end.any? end
thumbnail_url(size = :default)
click to toggle source
Returns the URL of the item’s thumbnail. @param [Symbol, String] size The size of the item’s thumbnail. @return [String] if size
is :default
, the URL of a 120x90px image. @return [String] if size
is :medium
, the URL of a 320x180px image. @return [String] if size
is :high
, the URL of a 480x360px image. @return [String] if size
is :standard
, the URL of a 640x480px image. @return [String] if size
is :maxres
, the URL of a 1280x720px image. @return [nil] if the size
is none of the above.
# File lib/yt/playlist_item.rb, line 55 def thumbnail_url(size = :default) thumbnails.fetch(size.to_s, {})['url'] end