class Yt::Models::Channel

Provides methods to interact with YouTube channels. @see developers.google.com/youtube/v3/docs/channels

Public Class Methods

new(options = {}) click to toggle source

@private Override Resource's new to set statistics as well if the response includes them

Calls superclass method
# File lib/yt/models/channel.rb, line 281
def initialize(options = {})
  super options
  if options[:statistics]
    @statistics_set = StatisticsSet.new data: options[:statistics]
  end
  if options[:content_owner_details]
    @content_owner_detail = ContentOwnerDetail.new data: options[:content_owner_details]
  end
end

Public Instance Methods

content_owner_details_params() click to toggle source

@private Tells `has_one :content_owner_detail` to retrieve the content owner detail as the Content Owner, it the channel was authorized with one. If it was not, the call will fail, since YouTube only allows content owners to check who is the content owner of a channel.

# File lib/yt/models/channel.rb, line 319
def content_owner_details_params
  {on_behalf_of_content_owner: auth.owner_name || auth.id}
end
delete_playlists(attributes = {}) click to toggle source

Deletes the channel’s playlists matching all the given attributes. @return [Array<Boolean>] whether each playlist matching the given

attributes was deleted.

@raise [Yt::Errors::RequestError] if {Resource#auth auth} is not an

authenticated Yt::Account with permissions to update the channel.

@param [Hash] attributes the attributes to match the playlists by. @option attributes [<String, Regexp>] :title The playlist’s title.

Pass a String for perfect match or a Regexp for advanced match.

@option attributes [<String, Regexp>] :description The playlist’s

description. Pass a String (perfect match) or a Regexp (advanced).

@option attributes [Array<String>] :tags The playlist’s tags.

All tags must match exactly.

@option attributes [String] :privacy_status The playlist’s privacy

status.
# File lib/yt/models/channel.rb, line 272
def delete_playlists(attributes = {})
  playlists.delete_all attributes
end
linked_at() click to toggle source

Returns the time the channel was partnered to a content owner. @return [Time] if the channel is partnered, the time when it was linked

to its content owner.

@return [nil] if the channel is not partnered or if {Resource#auth auth}

is a content owner without permissions to administer the channel.

@raise [Yt::Errors::Forbidden] if {Resource#auth auth} does not

return an authenticated content owner.
# File lib/yt/models/channel.rb, line 252
def linked_at
  content_owner_detail.time_linked
end
made_for_kids?() click to toggle source

@!attribute [r] made_for_kids?

@return [Boolean, nil] This value indicates whether the channel is
  designated as child-directed, and it contains the current "made for
  kids" status of the channel.
# File lib/yt/models/channel.rb, line 38
def made_for_kids?
  status.made_for_kids
end
reports_params() click to toggle source

@private Tells `has_reports` to retrieve the reports from YouTube Analytics API either as a Channel or as a Content Owner. @see developers.google.com/youtube/analytics/channel_reports @see developers.google.com/youtube/analytics/content_owner_reports

# File lib/yt/models/channel.rb, line 303
def reports_params
  {}.tap do |params|
    if auth.owner_name
      params[:ids] = "contentOwner==#{auth.owner_name}"
      params[:filters] = "channel==#{id}"
    else
      params[:ids] = "channel==#{id}"
    end
  end
end
self_declared_made_for_kids?() click to toggle source

@!attribute [r] self_declared_made_for_kids?

@return [Boolean, nil] In a channels.update request, this property
  allows the channel owner to designate the channel as
  child-directed. The property value is only returned if the channel
  owner authorized the API request.
# File lib/yt/models/channel.rb, line 47
def self_declared_made_for_kids?
  status.self_declared_made_for_kids
end
subscribe() click to toggle source

Subscribes the authenticated account to the channel. Unlike {#subscribe!}, does not raise an error if already subscribed. @raise [Yt::Errors::Unauthorized] if {Resource#auth auth} is not an

authenticated Yt::Account.
# File lib/yt/models/channel.rb, line 69
def subscribe
  subscriptions.insert(ignore_errors: true).tap do |subscription|
    throttle_subscriptions
    @subscription = subscription
  end
end
subscribe!() click to toggle source

Subscribes the authenticated account to the channel. Unlike {#subscribe}, raises an error if already subscribed. @raise [Yt::Errors::RequestError] if already subscribed. @raise [Yt::Errors::Unauthorized] if {Resource#auth auth} is not an

authenticated Yt::Account.
# File lib/yt/models/channel.rb, line 81
def subscribe!
  subscriptions.insert.tap do |subscription|
    throttle_subscriptions
    @subscription = subscription
  end
end
subscribed?() click to toggle source

@return [Boolean] whether the account is subscribed to the channel. @raise [Yt::Errors::Unauthorized] if {Resource#auth auth} is not an

authenticated Yt::Account.
# File lib/yt/models/channel.rb, line 58
def subscribed?
  sleep [(@subscriptions_updated_at || Time.now) - Time.now, 0].max
  subscription.exists?
rescue Errors::NoItems
  false
end
subscriber_count_visible?() click to toggle source

@return [Boolean] whether the number of subscribers is publicly visible.

# File lib/yt/models/channel.rb, line 228
def subscriber_count_visible?
  statistics_set.hidden_subscriber_count == false
end
throttle_subscriptions(seconds = 10) click to toggle source

@private @note Google API must have some caching layer by which if we try to delete a subscription that we just created, we encounter an error. To overcome this, if we have just updated the subscription, we must wait some time before requesting it again.

# File lib/yt/models/channel.rb, line 328
def throttle_subscriptions(seconds = 10)
  @subscriptions_updated_at = Time.now + seconds
end
unsubscribe() click to toggle source

Unsubscribes the authenticated account from the channel. Unlike {#unsubscribe!}, does not raise an error if already unsubscribed. @raise [Yt::Errors::Unauthorized] if {Resource#auth auth} is not an

authenticated Yt::Account.
# File lib/yt/models/channel.rb, line 92
def unsubscribe
  unsubscribe! if subscribed?
end
unsubscribe!() click to toggle source

Unsubscribes the authenticated account from the channel. Unlike {#unsubscribe}, raises an error if already unsubscribed.

@raise [Yt::Errors::RequestError] if already unsubscribed. @raise [Yt::Errors::Unauthorized] if {Resource#auth auth} is not an

authenticated Yt::Account.
# File lib/yt/models/channel.rb, line 102
def unsubscribe!
  subscription.delete.tap{ throttle_subscriptions }
end
videos_params() click to toggle source

@private Tells `has_many :videos` that channel.videos should return all the videos publicly available on the channel.

# File lib/yt/models/channel.rb, line 294
def videos_params
  {channel_id: id}
end