Class: Yt::Models::Channel

Inherits:
Resource show all
Includes:
Associations::Earnings, Associations::Views
Defined in:
lib/yt/models/channel.rb

Overview

A channel resource contains information about a YouTube channel.

Instance Attribute Summary collapse

Attributes inherited from Resource

#auth

Instance Method Summary collapse

Methods included from Associations::Views

#views, #views_on

Methods included from Associations::Earnings

#earnings, #earnings_on

Methods inherited from Resource

#initialize, #kind, #username

Constructor Details

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

Instance Attribute Details

#playlistsYt::Collections::Playlists (readonly)

Returns the channel’s playlists.

Returns:



23
# File 'lib/yt/models/channel.rb', line 23

has_many :playlists

#statistics_setYt::Models::StatisticsSet (readonly)

Returns the statistics for the video.

Returns:



28
# File 'lib/yt/models/channel.rb', line 28

has_one :statistics_set

#subscriptionsYt::Collections::Subscriptions (readonly)

Returns the channel’s subscriptions.

Returns:



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

has_many :subscriptions

#videosYt::Collections::Videos (readonly)

Returns the channel’s videos.

Returns:



19
# File 'lib/yt/models/channel.rb', line 19

has_many :videos

Instance Method Details

#create_playlist(params = {}) ⇒ Object



91
92
93
# File 'lib/yt/models/channel.rb', line 91

def create_playlist(params = {})
  playlists.insert params
end

#delete_playlists(attrs = {}) ⇒ Object



95
96
97
# File 'lib/yt/models/channel.rb', line 95

def delete_playlists(attrs = {})
  playlists.delete_all attrs
end

#subscribeObject

Subscribes the authenticated account to the channel. Does not raise an error if the account was already subscribed.

This method requires auth to return an authenticated instance of Account.

Raises:



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

def subscribe
  subscriptions.insert ignore_errors: true
end

#subscribe!Object

Subscribes the authenticated account to the channel. Raises an error if the account was already subscribed.

This method requires auth to return an authenticated instance of Account.

Raises:



63
64
65
# File 'lib/yt/models/channel.rb', line 63

def subscribe!
  subscriptions.insert
end

#subscribed?Boolean

Returns whether the authenticated account is subscribed to the channel.

This method requires auth to return an authenticated instance of Account.

Returns:

  • (Boolean)

    whether the account is subscribed to the channel.

Raises:



39
40
41
# File 'lib/yt/models/channel.rb', line 39

def subscribed?
  subscriptions.any?{|s| s.exists?}
end

#unsubscribeObject

Unsubscribes the authenticated account from the channel. Does not raise an error if the account was not subscribed.

This method requires auth to return an authenticated instance of Account.

Raises:



74
75
76
# File 'lib/yt/models/channel.rb', line 74

def unsubscribe
  subscriptions.delete_all({}, ignore_errors: true)
end

#unsubscribe!Object

Unsubscribes the authenticated account from the channel. Raises an error if the account was not subscribed.

This method requires auth to return an authenticated instance of Account.

Raises:



87
88
89
# File 'lib/yt/models/channel.rb', line 87

def unsubscribe!
  subscriptions.delete_all
end