Class: Yt::PlaylistItem
Overview
Provides methods to interact with YouTube playlist items.
Instance Attribute Summary collapse
-
#channel_id ⇒ String
readonly
The ID of the channel that the playlist belongs to.
-
#channel_title ⇒ String
readonly
The title of the channel that the playlist belongs to.
-
#description ⇒ String
readonly
The item’s description.
-
#playlist_id ⇒ String
readonly
The ID of the playlist that the item belongs to.
-
#position ⇒ Integer
readonly
The order in which the item appears in the playlist.
- #privacy_status ⇒ String? readonly
-
#published_at ⇒ Time
readonly
The date and time that the item was added to the playlist.
-
#thumbnails ⇒ Hash<String, Hash>
readonly
The thumbnails associated with the item.
-
#title ⇒ String
readonly
The item’s title.
-
#video_id ⇒ String
readonly
The ID of the video that the item refers to.
Attributes inherited from Resource
Class Method Summary collapse
-
.insert(playlist_id:, video_id:) ⇒ Yt::PlaylistItem
The item created by appending the given video to the given playlist.
Instance Method Summary collapse
-
#delete ⇒ Boolean
Whether the item was removed from the playlist.
-
#thumbnail_url(size = :default) ⇒ String?
Returns the URL of the item’s thumbnail.
Methods inherited from Resource
#id, #initialize, #inspect, #select, where
Constructor Details
This class inherits a constructor from Yt::Resource
Instance Attribute Details
#channel_id ⇒ String (readonly)
Returns the ID of the channel that the playlist belongs to.
23 |
# File 'lib/yt/playlist_item.rb', line 23 has_attribute :channel_id, in: :snippet |
#channel_title ⇒ String (readonly)
Returns the title of the channel that the playlist belongs to.
27 |
# File 'lib/yt/playlist_item.rb', line 27 has_attribute :channel_title, in: :snippet |
#description ⇒ String (readonly)
Returns the item’s description.
|
# File 'lib/yt/playlist_item.rb', line 9
|
#playlist_id ⇒ String (readonly)
Returns the ID of the playlist that the item belongs to.
31 |
# File 'lib/yt/playlist_item.rb', line 31 has_attribute :playlist_id, in: :snippet |
#position ⇒ Integer (readonly)
Returns the order in which the item appears in the playlist. The value uses a zero-based index so the first item has a position of 0.
36 |
# File 'lib/yt/playlist_item.rb', line 36 has_attribute :position, in: :snippet, type: Integer |
#privacy_status ⇒ String? (readonly)
46 47 48 |
# File 'lib/yt/playlist_item.rb', line 46 def privacy_status status['privacyStatus'] if status end |
#published_at ⇒ Time (readonly)
Returns the date and time that the item was added to the playlist.
15 |
# File 'lib/yt/playlist_item.rb', line 15 has_attribute :published_at, in: :snippet, type: Time |
#thumbnails ⇒ Hash<String, Hash> (readonly)
Returns the thumbnails associated with the item.
19 |
# File 'lib/yt/playlist_item.rb', line 19 has_attribute :thumbnails, in: :snippet |
#title ⇒ String (readonly)
Returns the item’s title.
7 |
# File 'lib/yt/playlist_item.rb', line 7 has_attribute :title, in: :snippet |
#video_id ⇒ String (readonly)
Returns the ID of the video that the item refers to.
40 |
# File 'lib/yt/playlist_item.rb', line 40 has_attribute :video_id, in: %i(snippet resource_id) |
Class Method Details
.insert(playlist_id:, video_id:) ⇒ Yt::PlaylistItem
Returns the item created by appending the given video to the given playlist.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/yt/playlist_item.rb', line 65 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 || post '/youtube/v3/playlistItems', {part: 'snippet'}, {snippet: snippet} end.first end |
Instance Method Details
#delete ⇒ Boolean
Returns whether the item was removed from the playlist.
77 78 79 80 81 82 83 |
# File 'lib/yt/playlist_item.rb', line 77 def delete items = -> (body) { [{}] } # the response body is empty Relation.new(PlaylistItem, id: id, extract_items: items) do || delete '/youtube/v3/playlistItems', id: [:id] end.any? end |
#thumbnail_url(size = :default) ⇒ String?
Returns the URL of the item’s thumbnail.
59 60 61 |
# File 'lib/yt/playlist_item.rb', line 59 def thumbnail_url(size = :default) thumbnails.fetch(size.to_s, {})['url'] end |