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

#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



84
85
86
# File 'lib/yt/models/channel.rb', line 84

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

#delete_playlists(attrs = {}) ⇒ Object



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

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:



43
44
45
# File 'lib/yt/models/channel.rb', line 43

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:



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

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:



32
33
34
# File 'lib/yt/models/channel.rb', line 32

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:



67
68
69
# File 'lib/yt/models/channel.rb', line 67

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:



80
81
82
# File 'lib/yt/models/channel.rb', line 80

def unsubscribe!
  subscriptions.delete_all
end