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)

Returns the playlist’s items.

Returns:



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.

Returns:

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.

Parameters:

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

    the range of days to get the average_time_in_playlist for.

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.

Returns:

  • (Hash<Date, Float>)

    the average_time_in_playlist for a range of a days.



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

has_report :average_time_in_playlist

#average_time_in_playlist_on(date) ⇒ Float

Returns the average_time_in_playlist for a single day.

Parameters:

  • date (#to_date)

    The single day to get the average_time_in_playlist for.

Returns:

  • (Float)

    the average_time_in_playlist for a single day.



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.

Returns:

  • (Boolean)

    whether the playlist does not exist anymore.

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

Returns:

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

Parameters:

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

    the range of days to get the playlist_starts for.

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.

Returns:

  • (Hash<Date, Float>)

    the playlist_starts for a range of a days.



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

has_report :playlist_starts

#playlist_starts_on(date) ⇒ Float

Returns the playlist_starts for a single day.

Parameters:

  • date (#to_date)

    The single day to get the playlist_starts for.

Returns:

  • (Float)

    the playlist_starts for a single day.



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.

Parameters:

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

    the range of days to get the views for.

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.

Returns:

  • (Hash<Date, Float>)

    the views for a range of a days.



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

has_report :views

#views_on(date) ⇒ Float

Returns the views for a single day.

Parameters:

  • date (#to_date)

    The single day to get the views for.

Returns:

  • (Float)

    the views for a single day.



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.

Parameters:

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

    the range of days to get the views_per_playlist_start for.

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.

Returns:

  • (Hash<Date, Float>)

    the views_per_playlist_start for a range of a days.



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

has_report :views_per_playlist_start

#views_per_playlist_start_on(date) ⇒ Float

Returns the views_per_playlist_start for a single day.

Parameters:

  • date (#to_date)

    The single day to get the views_per_playlist_start for.

Returns:

  • (Float)

    the views_per_playlist_start for a single day.



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

has_report :views_per_playlist_start