Class: Yt::Models::Playlist

Inherits:
Resource show all
Defined in:
lib/yt/models/playlist.rb

Overview

Provides methods to interact with YouTube playlists.

Instance Attribute Summary collapse

Attributes inherited from Resource

#auth

Instance Method Summary collapse

Methods inherited from Resource

#initialize, #kind, #update, #username

Methods included from Associations::HasReports

#has_report

Methods included from Associations::HasViewerPercentages

#has_viewer_percentages

Methods included from Associations::HasOne

#has_one

Methods included from Associations::HasMany

#has_many

Methods included from Associations::HasAuthentication

#has_authentication

Constructor Details

This class inherits a constructor from Yt::Models::Resource

Instance Attribute Details

#playlist_itemsYt::Collections::PlaylistItems (readonly)



12
# File 'lib/yt/models/playlist.rb', line 12

has_many :playlist_items

Instance Method Details

#add_video(video_id, attributes = {}) ⇒ Yt::PlaylistItem

Adds a video to the playlist Does not raise an error if the video cannot be added (e.g., unknown).

This method requires auth to return an authenticated instance of Account with permissions to update the playlist.

Raises:



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

def add_video(video_id, attributes = {})
  playlist_item_params = playlist_item_params(video_id, attributes)
  playlist_items.insert playlist_item_params, ignore_errors: true
end

#add_video!(video_id, attributes = {}) ⇒ Object



55
56
57
58
# File 'lib/yt/models/playlist.rb', line 55

def add_video!(video_id, attributes = {})
  playlist_item_params = playlist_item_params(video_id, attributes)
  playlist_items.insert playlist_item_params
end

#add_videos(video_ids = [], attributes = {}) ⇒ Object



60
61
62
# File 'lib/yt/models/playlist.rb', line 60

def add_videos(video_ids = [], attributes = {})
  video_ids.map{|video_id| add_video video_id, attributes}
end

#add_videos!(video_ids = [], attributes = {}) ⇒ Object



64
65
66
# File 'lib/yt/models/playlist.rb', line 64

def add_videos!(video_ids = [], attributes = {})
  video_ids.map{|video_id| add_video! video_id, attributes}
end

#average_time_in_playlist(options = {}) ⇒ Hash<Date, Float>

Returns the average_time_in_playlist for a range of a days.

Options Hash (options):

  • :since (#to_date)

    The first day of the range. Also aliased as :from.

  • :until (#to_date)

    The last day of the range. Also aliased as :to.



21
# File 'lib/yt/models/playlist.rb', line 21

has_report :average_time_in_playlist

#average_time_in_playlist_on(date) ⇒ Float



21
# File 'lib/yt/models/playlist.rb', line 21

has_report :average_time_in_playlist

#delete(options = {}) ⇒ Boolean

Deletes the playlist.

This method requires auth to return an authenticated instance of Account with permissions to delete the playlist.

Raises:



33
34
35
36
# File 'lib/yt/models/playlist.rb', line 33

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

#delete_playlist_items(attrs = {}) ⇒ Object



68
69
70
# File 'lib/yt/models/playlist.rb', line 68

def delete_playlist_items(attrs = {})
  playlist_items.delete_all attrs
end

#exists?Boolean



38
39
40
# File 'lib/yt/models/playlist.rb', line 38

def exists?
  !@id.nil?
end

#playlist_starts(options = {}) ⇒ Hash<Date, Float>

Returns the playlist_starts for a range of a days.

Options Hash (options):

  • :since (#to_date)

    The first day of the range. Also aliased as :from.

  • :until (#to_date)

    The last day of the range. Also aliased as :to.



18
# File 'lib/yt/models/playlist.rb', line 18

has_report :playlist_starts

#playlist_starts_on(date) ⇒ Float



18
# File 'lib/yt/models/playlist.rb', line 18

has_report :playlist_starts

#views(options = {}) ⇒ Hash<Date, Float>

Returns the views for a range of a days.

Options Hash (options):

  • :since (#to_date)

    The first day of the range. Also aliased as :from.

  • :until (#to_date)

    The last day of the range. Also aliased as :to.



15
# File 'lib/yt/models/playlist.rb', line 15

has_report :views

#views_on(date) ⇒ Float



15
# File 'lib/yt/models/playlist.rb', line 15

has_report :views

#views_per_playlist_start(options = {}) ⇒ Hash<Date, Float>

Returns the views_per_playlist_start for a range of a days.

Options Hash (options):

  • :since (#to_date)

    The first day of the range. Also aliased as :from.

  • :until (#to_date)

    The last day of the range. Also aliased as :to.



24
# File 'lib/yt/models/playlist.rb', line 24

has_report :views_per_playlist_start

#views_per_playlist_start_on(date) ⇒ Float



24
# File 'lib/yt/models/playlist.rb', line 24

has_report :views_per_playlist_start