Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/yt/collections/reports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ def reports_params
params[:filters] = ((params[:filters] || '').split(';') + ["country==US"]).compact.uniq.join(';') if @dimension == :state && !@state
params[:filters] = ((params[:filters] || '').split(';') + ["country==#{@country}"]).compact.uniq.join(';') if @country && !@state
params[:filters] = ((params[:filters] || '').split(';') + ["province==US-#{@state}"]).compact.uniq.join(';') if @state
params[:filters] = ((params[:filters] || '').split(';') + ['isCurated==1']).compact.uniq.join(';') if @dimension == :playlist
params[:filters] = ((params[:filters] || '').split(';') + ['insightPlaybackLocationType==EMBEDDED']).compact.uniq.join(';') if @dimension == :embedded_player_location
params[:filters] = ((params[:filters] || '').split(';') + ['insightTrafficSourceType==RELATED_VIDEO']).compact.uniq.join(';') if @dimension == :related_video
params[:filters] = ((params[:filters] || '').split(';') + ['insightTrafficSourceType==YT_SEARCH']).compact.uniq.join(';') if @dimension == :search_term
Expand Down
5 changes: 4 additions & 1 deletion lib/yt/models/playlist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ def delete_playlist_items(attributes = {})
# @macro report_by_playlist_dimensions
has_report :views, Integer

# @macro report_by_playlist_dimensions
has_report :engaged_views, Integer

# @macro report_by_playlist_dimensions
has_report :estimated_minutes_watched, Integer

Expand Down Expand Up @@ -202,7 +205,7 @@ def reports_params
else
params[:ids] = "channel==#{channel_id}"
end
params[:filters] = "playlist==#{id};isCurated==1"
params[:filters] = "playlist==#{id}"
end
end

Expand Down
3 changes: 3 additions & 0 deletions lib/yt/models/video_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class VideoGroup < Base
# @macro report_by_video_dimensions
has_report :views, Integer

# @macro report_by_video_dimensions
has_report :engaged_views, Integer

# @macro report_by_video_dimensions
has_report :estimated_minutes_watched, Integer

Expand Down
3 changes: 2 additions & 1 deletion spec/requests/as_account/playlist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,12 @@
let(:id) { test_account.channel.playlists.first.id }

before do
allow(Date).to receive(:today).and_return(Date.new(2020, 2, 5))
allow(Date).to receive(:today).and_return(Date.new(2025, 5, 20))
end

it 'returns valid reports for playlist-related metrics' do
expect{playlist.views}.not_to raise_error
expect{playlist.engaged_views}.not_to raise_error
expect{playlist.playlist_starts}.not_to raise_error
expect{playlist.average_time_in_playlist}.not_to raise_error
expect{playlist.views_per_playlist_start}.not_to raise_error
Expand Down
5 changes: 3 additions & 2 deletions spec/requests/as_content_owner/content_owner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'yt/models/content_owner'
require 'yt/models/match_policy'

describe Yt::ContentOwner, :partner do
describe Yt::ContentOwner, :partner, :vcr do
describe '.partnered_channels' do
let(:partnered_channels) { $content_owner.partnered_channels }

Expand Down Expand Up @@ -66,7 +66,7 @@
end

describe '.video_groups' do
let(:video_group) { $content_owner.video_groups.first }
let(:video_group) { test_content_owner.video_groups.first }

specify 'returns the first video-group created by the account' do
expect(video_group).to be_a Yt::VideoGroup
Expand All @@ -77,6 +77,7 @@

specify 'allows to run reports against each video-group' do
expect(video_group.views).to be
expect(video_group.engaged_views).to be
end
end

Expand Down
14 changes: 14 additions & 0 deletions spec/support/global_hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ module Helpers
def test_account
@test_account ||= Yt::Account.new(refresh_token: ENV['YT_TEST_REFRESH_TOKEN'])
end

# Create one Youtube Partner channel, authenticated as the content owner
def test_content_owner
@test_content_owner ||= begin
attrs = { refresh_token: ENV['YT_TEST_CONTENT_OWNER_REFRESH_TOKEN'] }
attrs[:owner_name] = ENV['YT_TEST_CONTENT_OWNER_NAME']
Yt::ContentOwner.new attrs
end
end
end

RSpec.configure do |config|
Expand All @@ -23,4 +32,9 @@ def test_account
config.before :each, server_app: true do
allow(Yt.configuration).to receive(:api_key).and_return(ENV['YT_TEST_API_KEY'])
end

config.before :each, partner: true do
allow(Yt.configuration).to receive(:client_id).and_return(ENV['YT_TEST_PARTNER_CLIENT_ID'])
allow(Yt.configuration).to receive(:client_secret).and_return(ENV['YT_TEST_PARTNER_CLIENT_SECRET'])
end
end
13 changes: 13 additions & 0 deletions spec/support/vcr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,17 @@
c.filter_sensitive_data("<YT_AUTH_HEADER>") do |interaction|
interaction.request.headers['Authorization'].first rescue nil
end

c.filter_sensitive_data("<YT_TEST_CONTENT_OWNER_NAME>") { ENV['YT_TEST_CONTENT_OWNER_NAME'] }
c.filter_sensitive_data("<YT_TEST_PARTNER_CLIENT_ID>") { ENV['YT_TEST_PARTNER_CLIENT_ID'] }
c.filter_sensitive_data("<YT_TEST_PARTNER_CLIENT_SECRET>") { ENV['YT_TEST_PARTNER_CLIENT_SECRET'] }
c.filter_sensitive_data("<YT_TEST_CONTENT_OWNER_REFRESH_TOKEN>") { CGI.escape(ENV['YT_TEST_CONTENT_OWNER_REFRESH_TOKEN']) }
c.filter_sensitive_data("<YT_TEST_CONTENT_OWNER_ACCESS_TOKEN>") do |interaction|
begin
body = JSON.parse(interaction.response.body)
body['access_token']
rescue
# noop
end
end
end