Class: Yt::Models::Playlist
- Defined in:
- lib/yt/models/playlist.rb
Overview
Provides methods to interact with YouTube playlists.
Constant Summary
Constants inherited from Resource
Resource::CHANNEL_PATTERNS, Resource::PLAYLIST_PATTERNS, Resource::VIDEO_PATTERNS
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 playlist’s description.
-
#item_count ⇒ Integer
readonly
The number of items in the playlist.
-
#playlist_items ⇒ Yt::Collections::PlaylistItems
readonly
The playlist’s items.
-
#published_at ⇒ Time
readonly
The date and time that the playlist was created.
-
#title ⇒ String
readonly
The playlist’s title.
Attributes inherited from Resource
Instance Method Summary collapse
-
#add_video(video_id, options = {}) ⇒ Yt::PlaylistItem
Adds a video to the playlist.
-
#add_video!(video_id, options = {}) ⇒ Yt::PlaylistItem
Adds a video to the playlist.
-
#add_videos(video_ids = [], options = {}) ⇒ Array<Yt::PlaylistItem>
Adds multiple videos to the playlist.
-
#add_videos!(video_ids = [], options = {}) ⇒ Array<Yt::PlaylistItem>
Adds multiple videos to the playlist.
-
#average_time_in_playlist(options = {}) ⇒ Hash<Date, Float>, ...
Returns the average_time_in_playlist grouped by the given dimension.
-
#average_view_duration(options = {}) ⇒ Hash<Date, Integer>, ...
Returns the average_view_duration grouped by the given dimension.
-
#delete(options = {}) ⇒ Boolean
Deletes the playlist.
-
#delete_playlist_items(attributes = {}) ⇒ Array<Boolean>
Deletes the playlist’s items matching all the given attributes.
-
#estimated_minutes_watched(options = {}) ⇒ Hash<Yt::Video, Integer>, ...
Returns the estimated_minutes_watched grouped by the given dimension.
-
#playlist_starts(options = {}) ⇒ Hash<Date, Integer>, ...
Returns the playlist_starts grouped by the given dimension.
-
#reports(options = {}) ⇒ Hash<Symbol, Hash>
Returns the reports for the given metrics grouped by the given dimension.
-
#thumbnail_url(size = :default) ⇒ String?
Returns the URL of the playlist’s thumbnail.
-
#update(attributes = {}) ⇒ Boolean
Updates the attributes of a playlist.
-
#viewer_percentage(options = {}) ⇒ Hash<Symbol, Float>, ...
Returns the viewer_percentage grouped by the given dimension.
-
#views(options = {}) ⇒ Hash<Yt::Video, Integer>, ...
Returns the views grouped by the given dimension.
-
#views_per_playlist_start(options = {}) ⇒ Hash<Date, Float>, ...
Returns the views_per_playlist_start grouped by the given dimension.
Methods inherited from Resource
#private?, #public?, #unlisted?
Instance Attribute Details
#channel_id ⇒ String (readonly)
Returns the ID of the channel that the playlist belongs to.
34 |
# File 'lib/yt/models/playlist.rb', line 34 delegate :channel_id, to: :snippet |
#channel_title ⇒ String (readonly)
Returns the title of the channel that the playlist belongs to.
38 |
# File 'lib/yt/models/playlist.rb', line 38 delegate :channel_title, to: :snippet |
#description ⇒ String (readonly)
Returns the playlist’s description.
17 |
# File 'lib/yt/models/playlist.rb', line 17 delegate :description, to: :snippet |
#item_count ⇒ Integer (readonly)
Returns the number of items in the playlist.
46 |
# File 'lib/yt/models/playlist.rb', line 46 delegate :item_count, to: :content_detail |
#playlist_items ⇒ Yt::Collections::PlaylistItems (readonly)
Returns the playlist’s items.
154 |
# File 'lib/yt/models/playlist.rb', line 154 has_many :playlist_items |
#published_at ⇒ Time (readonly)
Returns the date and time that the playlist was created.
30 |
# File 'lib/yt/models/playlist.rb', line 30 delegate :published_at, to: :snippet |
#title ⇒ String (readonly)
Returns the playlist’s title.
13 |
# File 'lib/yt/models/playlist.rb', line 13 delegate :title, to: :snippet |
Instance Method Details
#add_video(video_id, options = {}) ⇒ Yt::PlaylistItem
Adds a video to the playlist. Unlike #add_video!, does not raise an error if video can’t be added.
91 92 93 94 |
# File 'lib/yt/models/playlist.rb', line 91 def add_video(video_id, = {}) playlist_item_params = playlist_item_params(video_id, ) playlist_items.insert playlist_item_params, ignore_errors: true end |
#add_video!(video_id, options = {}) ⇒ Yt::PlaylistItem
Adds a video to the playlist. Unlike #add_video, raises an error if video can’t be added.
105 106 107 108 |
# File 'lib/yt/models/playlist.rb', line 105 def add_video!(video_id, = {}) playlist_item_params = playlist_item_params(video_id, ) playlist_items.insert playlist_item_params end |
#add_videos(video_ids = [], options = {}) ⇒ Array<Yt::PlaylistItem>
Adds multiple videos to the playlist. Unlike #add_videos!, does not raise an error if videos can’t be added.
118 119 120 |
# File 'lib/yt/models/playlist.rb', line 118 def add_videos(video_ids = [], = {}) video_ids.map{|video_id| add_video video_id, } end |
#add_videos!(video_ids = [], options = {}) ⇒ Array<Yt::PlaylistItem>
Adds multiple videos to the playlist. Unlike #add_videos, raises an error if videos can’t be added.
130 131 132 |
# File 'lib/yt/models/playlist.rb', line 130 def add_videos!(video_ids = [], = {}) video_ids.map{|video_id| add_video! video_id, } end |
#average_time_in_playlist(options = {}) ⇒ Hash<Date, Float>, ...
Returns the average_time_in_playlist grouped by the given dimension.
176 |
# File 'lib/yt/models/playlist.rb', line 176 has_report :average_time_in_playlist, Float |
#average_view_duration(options = {}) ⇒ Hash<Date, Integer>, ...
Returns the average_view_duration grouped by the given dimension.
170 |
# File 'lib/yt/models/playlist.rb', line 170 has_report :average_view_duration, Integer |
#delete(options = {}) ⇒ Boolean
Deletes the playlist.
54 55 56 57 |
# File 'lib/yt/models/playlist.rb', line 54 def delete( = {}) do_delete {@id = nil} !exists? end |
#delete_playlist_items(attributes = {}) ⇒ Array<Boolean>
Deletes the playlist’s items matching all the given attributes.
146 147 148 |
# File 'lib/yt/models/playlist.rb', line 146 def delete_playlist_items(attributes = {}) playlist_items.delete_all attributes end |
#estimated_minutes_watched(options = {}) ⇒ Hash<Yt::Video, Integer>, ...
Returns the estimated_minutes_watched grouped by the given dimension.
164 |
# File 'lib/yt/models/playlist.rb', line 164 has_report :estimated_minutes_watched, Integer |
#playlist_starts(options = {}) ⇒ Hash<Date, Integer>, ...
Returns the playlist_starts grouped by the given dimension.
173 |
# File 'lib/yt/models/playlist.rb', line 173 has_report :playlist_starts, Integer |
#reports(options = {}) ⇒ Hash<Symbol, Hash>
Returns the reports for the given metrics grouped by the given dimension.
|
# File 'lib/yt/models/playlist.rb', line 158
|
#thumbnail_url(size = :default) ⇒ String?
Returns the URL of the playlist’s thumbnail.
26 |
# File 'lib/yt/models/playlist.rb', line 26 delegate :thumbnail_url, to: :snippet |
#update(attributes = {}) ⇒ Boolean
Updates the attributes of a playlist.
79 80 81 |
# File 'lib/yt/models/playlist.rb', line 79 def update(attributes = {}) super end |
#viewer_percentage(options = {}) ⇒ Hash<Symbol, Float>, ...
Returns the viewer_percentage grouped by the given dimension.
167 |
# File 'lib/yt/models/playlist.rb', line 167 has_report :viewer_percentage, Float |
#views(options = {}) ⇒ Hash<Yt::Video, Integer>, ...
Returns the views grouped by the given dimension.
161 |
# File 'lib/yt/models/playlist.rb', line 161 has_report :views, Integer |
#views_per_playlist_start(options = {}) ⇒ Hash<Date, Float>, ...
Returns the views_per_playlist_start grouped by the given dimension.
179 |
# File 'lib/yt/models/playlist.rb', line 179 has_report :views_per_playlist_start, Float |