Class: Yt::Models::PlaylistItem

Inherits:
Resource
  • Object
show all
Defined in:
lib/yt/models/playlist_item.rb

Overview

Provides methods to interact with YouTube playlist items.

Constant Summary

Constants inherited from Resource

Resource::CHANNEL_PATTERNS, Resource::PLAYLIST_PATTERNS, Resource::VIDEO_PATTERNS

Instance Attribute Summary collapse

Attributes inherited from Resource

#id, #privacy_status

Instance Method Summary collapse

Methods inherited from Resource

#private?, #public?, #unlisted?

Instance Attribute Details

#channel_idString (readonly)

Returns the ID of the channel that the item belongs to.

Returns:

  • (String)

    the ID of the channel that the item belongs to.



34
# File 'lib/yt/models/playlist_item.rb', line 34

delegate :channel_id, to: :snippet

#channel_titleString (readonly)

Returns the title of the channel that the item belongs to.

Returns:

  • (String)

    the title of the channel that the item belongs to.



38
# File 'lib/yt/models/playlist_item.rb', line 38

delegate :channel_title, to: :snippet

#descriptionString (readonly)

Returns the item’s description.

Returns:

  • (String)

    the item’s description.



17
# File 'lib/yt/models/playlist_item.rb', line 17

delegate :description, to: :snippet

#playlist_idString (readonly)

Returns the ID of the playlist that the item is in.

Returns:

  • (String)

    the ID of the playlist that the item is in.



42
# File 'lib/yt/models/playlist_item.rb', line 42

delegate :playlist_id, to: :snippet

#published_atTime (readonly)

Returns the time that the item was added to the playlist.

Returns:

  • (Time)

    the time that the item was added to the playlist.



30
# File 'lib/yt/models/playlist_item.rb', line 30

delegate :published_at, to: :snippet

#titleString (readonly)

Returns the item’s title.

Returns:

  • (String)

    the item’s title.



13
# File 'lib/yt/models/playlist_item.rb', line 13

delegate :title, to: :snippet

Instance Method Details

#delete(options = {}) ⇒ Boolean

Deletes the playlist item.

Returns:

  • (Boolean)

    whether the playlist item does not exist anymore.

Raises:



61
62
63
64
# File 'lib/yt/models/playlist_item.rb', line 61

def delete(options = {})
  do_delete {@id = nil}
  !exists?
end

#positionInteger

Returns the order in which the item appears in a playlist. The value is zero-based, so the first item has a position of 0.

Returns:

  • (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.



51
52
53
# File 'lib/yt/models/playlist_item.rb', line 51

def position
  ensure_complete_snippet :position
end

#thumbnail_url(size = :default) ⇒ String?

Returns the URL of the item’s thumbnail.

Parameters:

  • size (Symbol, String) (defaults to: :default)

    The size of the item’s thumbnail.

Returns:

  • (String)

    if size is default, the URL of a 120x90px image.

  • (String)

    if size is medium, the URL of a 320x180px image.

  • (String)

    if size is high, the URL of a 480x360px image.

  • (nil)

    if the size is not default, medium or high.



26
# File 'lib/yt/models/playlist_item.rb', line 26

delegate :thumbnail_url, to: :snippet

#update(attributes = {}) ⇒ Boolean

Updates the attributes of a playlist item.

Parameters:

  • attributes (Hash) (defaults to: {})

    the attributes to update.

Options Hash (attributes):

  • the (Integer)

    order in which the item should appear in a playlist. The value is zero-based, so the first position of 0.

Returns:

  • (Boolean)

    whether the item was successfully updated.

Raises:



73
74
75
# File 'lib/yt/models/playlist_item.rb', line 73

def update(attributes = {})
  super
end

#videoYt::Models::Video

Returns the video referred by the item.

Returns:



80
81
82
# File 'lib/yt/models/playlist_item.rb', line 80

def video
  @video ||= Video.new id: video_id, auth: @auth if video_id
end

#video_idString

Returns the ID of the video referred by the item.

Returns:

  • (String)

    the ID of the video referred by the item.



45
46
47
# File 'lib/yt/models/playlist_item.rb', line 45

def video_id
  snippet.resource_id['videoId']
end