class Yt::Models::VideoGroup

Provides methods to interact with YouTube Analytics video-groups. @see developers.google.com/youtube/analytics/v1/reference/groups

Attributes

auth[R]

@private

id[R]

@private

Public Class Methods

new(options = {}) click to toggle source

@private

# File lib/yt/models/video_group.rb, line 122
def initialize(options = {})
  @id = options[:id]
  @auth = options[:auth]
  @group_info = options[:group_info] if options[:group_info]
end

Public Instance Methods

all_channel_ids() click to toggle source
# File lib/yt/models/video_group.rb, line 163
def all_channel_ids
  resource_ids = group_items.map {|item| item.data['resource']['id']}.uniq
  case group_info.data['itemType']
  when "youtube#video"
    resource_ids.flat_map do |video_id|
      Yt::Video.new(id: video_id, auth: @auth).channel_id
    end.uniq
  when "youtube#channel"
    resource_ids
  else
    []
  end
end
all_video_ids() click to toggle source
# File lib/yt/models/video_group.rb, line 141
def all_video_ids
  resource_ids = group_items.map{|item| item.data['resource']['id']}.uniq
  case group_info.data["itemType"]
  when "youtube#video"
    resource_ids
  when "youtube#channel"
    resource_ids.flat_map do |channel_id|
      Yt::Channel.new(id: channel_id, auth: @auth).videos.map(&:id)
    end
  else
    []
  end
end
channels() click to toggle source
# File lib/yt/models/video_group.rb, line 177
def channels
  all_channel_ids.each_slice(50).flat_map do |channel_ids|
    conditions = {id: channel_ids.join(',')}
    conditions[:part] = 'snippet'
    Collections::Channels.new(auth: @auth).where(conditions).map(&:itself)
  end
end
reports_params() click to toggle source

@private Tells `has_reports` to retrieve group reports from the Analytics API.

# File lib/yt/models/video_group.rb, line 130
def reports_params
  {}.tap do |params|
    if auth.owner_name
      params[:ids] = "contentOwner==#{auth.owner_name}"
    else
      params[:ids] = "channel==mine"
    end
    params[:filters] = "group==#{id}"
  end
end
videos() click to toggle source
# File lib/yt/models/video_group.rb, line 155
def videos
  all_video_ids.each_slice(50).flat_map do |video_ids|
    conditions = {id: video_ids.join(',')}
    conditions[:part] = 'snippet,status,statistics,contentDetails'
    Collections::Videos.new(auth: @auth).where(conditions).map(&:itself)
  end
end