yt 0.32.6 → 0.33.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -4
  3. data/CHANGELOG.md +19 -0
  4. data/README.md +22 -32
  5. data/YOUTUBE_IT.md +4 -4
  6. data/lib/yt.rb +0 -1
  7. data/lib/yt/associations/has_reports.rb +9 -14
  8. data/lib/yt/collections/reports.rb +5 -7
  9. data/lib/yt/models/resource.rb +69 -3
  10. data/lib/yt/models/url.rb +2 -60
  11. data/lib/yt/request.rb +6 -2
  12. data/lib/yt/version.rb +1 -1
  13. data/yt.gemspec +5 -2
  14. metadata +31 -169
  15. data/spec/collections/claims_spec.rb +0 -62
  16. data/spec/collections/comment_threads_spec.rb +0 -46
  17. data/spec/collections/playlist_items_spec.rb +0 -44
  18. data/spec/collections/playlists_spec.rb +0 -27
  19. data/spec/collections/policies_spec.rb +0 -30
  20. data/spec/collections/references_spec.rb +0 -30
  21. data/spec/collections/reports_spec.rb +0 -30
  22. data/spec/collections/subscriptions_spec.rb +0 -25
  23. data/spec/collections/videos_spec.rb +0 -43
  24. data/spec/constants/geography_spec.rb +0 -16
  25. data/spec/errors/forbidden_spec.rb +0 -10
  26. data/spec/errors/missing_auth_spec.rb +0 -24
  27. data/spec/errors/no_items_spec.rb +0 -10
  28. data/spec/errors/request_error_spec.rb +0 -44
  29. data/spec/errors/server_error_spec.rb +0 -10
  30. data/spec/errors/unauthorized_spec.rb +0 -10
  31. data/spec/models/account_spec.rb +0 -138
  32. data/spec/models/annotation_spec.rb +0 -180
  33. data/spec/models/asset_spec.rb +0 -32
  34. data/spec/models/channel_spec.rb +0 -127
  35. data/spec/models/claim_event_spec.rb +0 -62
  36. data/spec/models/claim_history_spec.rb +0 -27
  37. data/spec/models/claim_spec.rb +0 -223
  38. data/spec/models/comment_spec.rb +0 -40
  39. data/spec/models/comment_thread_spec.rb +0 -93
  40. data/spec/models/configuration_spec.rb +0 -44
  41. data/spec/models/content_detail_spec.rb +0 -52
  42. data/spec/models/content_owner_detail_spec.rb +0 -6
  43. data/spec/models/file_detail_spec.rb +0 -13
  44. data/spec/models/live_streaming_detail_spec.rb +0 -6
  45. data/spec/models/ownership_spec.rb +0 -59
  46. data/spec/models/player_spec.rb +0 -13
  47. data/spec/models/playlist_item_spec.rb +0 -120
  48. data/spec/models/playlist_spec.rb +0 -138
  49. data/spec/models/policy_rule_spec.rb +0 -63
  50. data/spec/models/policy_spec.rb +0 -41
  51. data/spec/models/rating_spec.rb +0 -12
  52. data/spec/models/reference_spec.rb +0 -249
  53. data/spec/models/request_spec.rb +0 -204
  54. data/spec/models/resource_spec.rb +0 -42
  55. data/spec/models/right_owner_spec.rb +0 -71
  56. data/spec/models/snippet_spec.rb +0 -13
  57. data/spec/models/statistics_set_spec.rb +0 -13
  58. data/spec/models/status_spec.rb +0 -13
  59. data/spec/models/subscription_spec.rb +0 -30
  60. data/spec/models/url_spec.rb +0 -78
  61. data/spec/models/video_category_spec.rb +0 -21
  62. data/spec/models/video_spec.rb +0 -669
  63. data/spec/requests/as_account/account_spec.rb +0 -143
  64. data/spec/requests/as_account/authentications_spec.rb +0 -127
  65. data/spec/requests/as_account/channel_spec.rb +0 -246
  66. data/spec/requests/as_account/channels_spec.rb +0 -18
  67. data/spec/requests/as_account/playlist_item_spec.rb +0 -55
  68. data/spec/requests/as_account/playlist_spec.rb +0 -218
  69. data/spec/requests/as_account/thumbnail.jpg +0 -0
  70. data/spec/requests/as_account/video.mp4 +0 -0
  71. data/spec/requests/as_account/video_spec.rb +0 -408
  72. data/spec/requests/as_content_owner/account_spec.rb +0 -29
  73. data/spec/requests/as_content_owner/advertising_options_set_spec.rb +0 -15
  74. data/spec/requests/as_content_owner/asset_spec.rb +0 -31
  75. data/spec/requests/as_content_owner/bulk_report_job_spec.rb +0 -19
  76. data/spec/requests/as_content_owner/channel_spec.rb +0 -1836
  77. data/spec/requests/as_content_owner/claim_history_spec.rb +0 -20
  78. data/spec/requests/as_content_owner/claim_spec.rb +0 -17
  79. data/spec/requests/as_content_owner/content_owner_spec.rb +0 -370
  80. data/spec/requests/as_content_owner/match_policy_spec.rb +0 -17
  81. data/spec/requests/as_content_owner/ownership_spec.rb +0 -25
  82. data/spec/requests/as_content_owner/playlist_spec.rb +0 -767
  83. data/spec/requests/as_content_owner/video_group_spec.rb +0 -112
  84. data/spec/requests/as_content_owner/video_spec.rb +0 -1223
  85. data/spec/requests/as_server_app/channel_spec.rb +0 -54
  86. data/spec/requests/as_server_app/comment_spec.rb +0 -22
  87. data/spec/requests/as_server_app/comment_thread_spec.rb +0 -27
  88. data/spec/requests/as_server_app/comment_threads_spec.rb +0 -41
  89. data/spec/requests/as_server_app/playlist_item_spec.rb +0 -30
  90. data/spec/requests/as_server_app/playlist_spec.rb +0 -33
  91. data/spec/requests/as_server_app/url_spec.rb +0 -94
  92. data/spec/requests/as_server_app/video_spec.rb +0 -60
  93. data/spec/requests/as_server_app/videos_spec.rb +0 -40
  94. data/spec/requests/unauthenticated/video_spec.rb +0 -14
  95. data/spec/spec_helper.rb +0 -20
  96. data/spec/support/fail_matcher.rb +0 -15
  97. data/spec/support/global_hooks.rb +0 -48
@@ -1,112 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/models/video_group'
3
- require 'yt/models/group_item'
4
-
5
- describe Yt::VideoGroup, :partner do
6
- subject(:video_group) { Yt::VideoGroup.new id: id, auth: $content_owner }
7
-
8
- context 'given a channel-group', :partner do
9
- context 'managed by the authenticated Content Owner' do
10
- let(:id) { ENV['YT_TEST_PARTNER_CHANNEL_GROUP_ID'] }
11
-
12
- specify '.videos loads each video of each channel' do
13
- video = video_group.videos.first
14
- expect(video.instance_variable_defined? :@snippet).to be true
15
- expect(video.instance_variable_defined? :@status).to be true
16
- expect(video.instance_variable_defined? :@statistics_set).to be true
17
- end
18
-
19
- specify '.channels loads each channel' do
20
- channel = video_group.channels.first
21
- expect(channel.instance_variable_defined? :@snippet).to be true
22
- end
23
- end
24
- end
25
-
26
- context 'given a video-group', :partner do
27
- context 'managed by the authenticated Content Owner' do
28
- let(:id) { ENV['YT_TEST_PARTNER_VIDEO_GROUP_ID'] }
29
-
30
- specify 'the title can be retrieved' do
31
- expect(video_group.title).to be_a(String)
32
- expect(video_group.title).not_to be_empty
33
- end
34
-
35
- specify 'the number of videos in the group can be retrieved' do
36
- expect(video_group.item_count).to be_an(Integer)
37
- expect(video_group.item_count).not_to be_zero
38
- end
39
-
40
- specify '.group_items retrieves the group items' do
41
- expect(video_group.group_items.count).to be_an(Integer)
42
- expect(video_group.group_items.map{|g| g}).to all(be_a Yt::GroupItem)
43
- end
44
-
45
- specify '.group_items.includes(:video) eager-loads each video' do
46
- item = video_group.group_items.includes(:video).first
47
- expect(item.video.instance_variable_defined? :@snippet).to be true
48
- expect(item.video.instance_variable_defined? :@status).to be true
49
- expect(item.video.instance_variable_defined? :@statistics_set).to be true
50
- end
51
-
52
- specify '.videos loads each video' do
53
- video = video_group.videos.first
54
- expect(video.instance_variable_defined? :@snippet).to be true
55
- expect(video.instance_variable_defined? :@status).to be true
56
- expect(video.instance_variable_defined? :@statistics_set).to be true
57
- end
58
-
59
- specify '.channels loads each channel' do
60
- channel = video_group.channels.first
61
- expect(channel.instance_variable_defined? :@snippet).to be true
62
- end
63
-
64
- describe 'multiple reports can be retrieved at once' do
65
- metrics = {views: Integer,
66
- estimated_minutes_watched: Integer, comments: Integer, likes: Integer,
67
- dislikes: Integer, shares: Integer, subscribers_gained: Integer,
68
- subscribers_lost: Integer,
69
- videos_added_to_playlists: Integer, videos_removed_from_playlists: Integer,
70
- average_view_duration: Integer,
71
- card_impressions: Integer, card_clicks: Integer,
72
- card_click_rate: Float, card_teaser_impressions: Integer,
73
- card_teaser_clicks: Integer, card_teaser_click_rate: Float,
74
- average_view_percentage: Float, annotation_clicks: Integer,
75
- annotation_click_through_rate: Float,
76
- annotation_close_rate: Float, estimated_revenue: Float, ad_impressions: Integer,
77
- monetized_playbacks: Integer}
78
-
79
- specify 'by day, and are chronologically sorted' do
80
- range = {since: 5.days.ago.to_date, until: 3.days.ago.to_date}
81
- result = video_group.reports range.merge(only: metrics, by: :day)
82
- metrics.each do |metric, type|
83
- expect(result[metric].keys).to all(be_a Date)
84
- expect(result[metric].values).to all(be_a type)
85
- expect(result[metric].keys.sort).to eq result[metric].keys
86
- end
87
- end
88
-
89
- # NOTE: all the other filters also apply, not tested for brevity
90
- end
91
-
92
- describe 'viewer_percentage can be grouped by age group' do
93
- let(:range) { {since: 1.year.ago.to_date, until: 1.week.ago.to_date} }
94
- let(:keys) { range.values }
95
-
96
- specify 'with the :by option set to :age_group' do
97
- viewer_percentage = video_group.viewer_percentage range.merge by: :age_group
98
- expect(viewer_percentage.keys - %w(65- 35-44 45-54 13-17 25-34 55-64 18-24)).to be_empty
99
- expect(viewer_percentage.values).to all(be_instance_of Float)
100
- end
101
- end
102
- end
103
-
104
- context 'not managed by the authenticated Content Owner' do
105
- let(:id) { 'ABExJp9gAAA' }
106
-
107
- specify 'views cannot be retrieved' do
108
- expect{video_group.views}.to raise_error Yt::Error
109
- end
110
- end
111
- end
112
- end
@@ -1,1223 +0,0 @@
1
- # encoding: UTF-8
2
- require 'spec_helper'
3
- require 'yt/models/video'
4
-
5
- describe Yt::Video, :partner do
6
- subject(:video) { Yt::Video.new id: id, auth: $content_owner }
7
-
8
- context 'given a video of a partnered channel', :partner do
9
- context 'managed by the authenticated Content Owner' do
10
- let(:id) { ENV['YT_TEST_PARTNER_VIDEO_ID'] }
11
-
12
- describe 'advertising options can be retrieved' do
13
- it { expect{video.advertising_options_set}.not_to raise_error }
14
- end
15
-
16
- [:views, :comments, :likes, :dislikes, :shares,
17
- :subscribers_gained, :subscribers_lost,
18
- :videos_added_to_playlists, :videos_removed_from_playlists,
19
- :estimated_minutes_watched, :average_view_duration,
20
- :average_view_percentage, :ad_impressions, :monetized_playbacks,
21
- :annotation_clicks, :annotation_click_through_rate, :playback_based_cpm,
22
- :card_impressions, :card_clicks, :card_click_rate,
23
- :card_teaser_impressions, :card_teaser_clicks, :card_teaser_click_rate,
24
- :annotation_close_rate, :estimated_revenue].each do |metric|
25
- describe "#{metric} can be retrieved for a range of days" do
26
- let(:date_in) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
27
- let(:date_out) { Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 5 }
28
- let(:metric) { metric }
29
- let(:result) { video.public_send metric, options }
30
-
31
- context 'with a given start and end (:since/:until option)' do
32
- let(:options) { {by: :day, since: date_in, until: date_out} }
33
- specify do
34
- expect(result.keys.min).to eq date_in.to_date
35
- expect(result.keys.max).to eq date_out.to_date
36
- end
37
- end
38
-
39
- context 'with a given start and end (:from/:to option)' do
40
- let(:options) { {by: :day, from: date_in, to: date_out} }
41
- specify do
42
- expect(result.keys.min).to eq date_in.to_date
43
- expect(result.keys.max).to eq date_out.to_date
44
- end
45
- end
46
- end
47
-
48
- describe "#{metric} can be grouped by month" do
49
- let(:metric) { metric }
50
-
51
- let(:result) { video.public_send metric, by: :month, since: 1.month.ago }
52
- specify do
53
- expect(result.keys).to all(be_a Range)
54
- expect(result.keys.map &:first).to all(be_a Date)
55
- expect(result.keys.map &:first).to eq result.keys.map(&:first).map(&:beginning_of_month)
56
- expect(result.keys.map &:last).to all(be_a Date)
57
- expect(result.keys.map &:last).to eq result.keys.map(&:last).map(&:end_of_month)
58
- end
59
- end
60
-
61
- describe "#{metric} can be grouped by week and returns non-overlapping periods" do
62
- let(:metric) { metric }
63
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE'], until: Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 9} }
64
- let(:result) { video.public_send metric, range.merge(by: :week)}
65
- specify do
66
- expect(result.size).to be <= 2
67
- expect(result.keys).to all(be_a Range)
68
- expect(result.keys.map{|range| range.first.wday}.uniq).to be_one
69
- expect(result.keys.map{|range| range.last.wday}.uniq).to be_one
70
- end
71
- end
72
-
73
- describe "#{metric} can be retrieved for a single country" do
74
- let(:result) { video.public_send metric, options }
75
-
76
- context 'and grouped by day' do
77
- let(:date_in) { 5.days.ago }
78
- let(:options) { {by: :day, since: date_in, in: location} }
79
-
80
- context 'with the :in option set to the country code' do
81
- let(:location) { 'US' }
82
- it { expect(result.keys.min).to eq date_in.to_date }
83
- end
84
-
85
- context 'with the :in option set to {country: country code}' do
86
- let(:location) { {country: 'US'} }
87
- it { expect(result.keys.min).to eq date_in.to_date }
88
- end
89
- end
90
- end
91
- end
92
-
93
- {views: Integer, comments: Integer, likes: Integer, dislikes: Integer,
94
- shares: Integer, subscribers_gained: Integer, subscribers_lost: Integer,
95
- videos_added_to_playlists: Integer, videos_removed_from_playlists: Integer,
96
- estimated_minutes_watched: Integer, average_view_duration: Integer,
97
- average_view_percentage: Float, ad_impressions: Integer,
98
- monetized_playbacks: Integer, annotation_clicks: Integer,
99
- annotation_click_through_rate: Float, annotation_close_rate: Float,
100
- card_impressions: Integer, card_clicks: Integer,
101
- card_click_rate: Float, card_teaser_impressions: Integer,
102
- card_teaser_clicks: Integer, card_teaser_click_rate: Float,
103
- estimated_revenue: Float}.each do |metric, type|
104
- describe "#{metric} can be grouped by range" do
105
- let(:metric) { metric }
106
-
107
- context 'without a :by option (default)' do
108
- let(:result) { video.public_send metric }
109
- specify do
110
- expect(result.size).to be 1
111
- expect(result[:total]).to be_a type
112
- end
113
- end
114
-
115
- context 'with the :by option set to :range' do
116
- let(:result) { video.public_send metric, by: :range }
117
- specify do
118
- expect(result.size).to be 1
119
- expect(result[:total]).to be_a type
120
- end
121
- end
122
- end
123
- end
124
-
125
- [:views, :comments, :likes, :dislikes, :shares,
126
- :subscribers_gained, :subscribers_lost,
127
- :videos_added_to_playlists, :videos_removed_from_playlists,
128
- :estimated_minutes_watched, :average_view_duration,
129
- :average_view_percentage, :ad_impressions, :monetized_playbacks,
130
- :card_impressions, :card_clicks, :card_click_rate,
131
- :card_teaser_impressions, :card_teaser_clicks, :card_teaser_click_rate,
132
- :annotation_clicks, :annotation_click_through_rate,
133
- :annotation_close_rate, :estimated_revenue].each do |metric|
134
- describe "#{metric} can be retrieved for a single country" do
135
- let(:result) { video.public_send metric, options }
136
-
137
- context 'and grouped by country' do
138
- let(:options) { {by: :country, in: location} }
139
-
140
- context 'with the :in option set to the country code' do
141
- let(:location) { 'US' }
142
- it { expect(result.keys).to eq ['US'] }
143
- end
144
-
145
- context 'with the :in option set to {country: country code}' do
146
- let(:location) { {country: 'US'} }
147
- it { expect(result.keys).to eq ['US'] }
148
- end
149
- end
150
- end
151
- end
152
-
153
- [:views, :annotation_clicks, :annotation_click_through_rate,
154
- :card_impressions, :card_clicks, :card_click_rate,
155
- :card_teaser_impressions, :card_teaser_clicks, :card_teaser_click_rate,
156
- :annotation_close_rate].each do |metric|
157
- describe "#{metric} can be retrieved for a single country" do
158
- let(:result) { video.public_send metric, options }
159
-
160
- context 'and grouped by state' do
161
- let(:options) { {by: :state, in: location} }
162
-
163
- context 'with the :in option set to the country code' do
164
- let(:location) { 'US' }
165
- it { expect(result.keys.map(&:length).uniq).to eq [2] }
166
- end
167
-
168
- context 'with the :in option set to {country: country code}' do
169
- let(:location) { {country: 'US'} }
170
- it { expect(result.keys.map(&:length).uniq).to eq [2] }
171
- end
172
- end
173
- end
174
- end
175
-
176
- describe 'multiple reports can be retrieved at once' do
177
- metrics = {views: Integer,
178
- estimated_minutes_watched: Integer, comments: Integer, likes: Integer,
179
- dislikes: Integer, shares: Integer, subscribers_gained: Integer,
180
- subscribers_lost: Integer,
181
- videos_added_to_playlists: Integer, videos_removed_from_playlists: Integer,
182
- average_view_duration: Integer,
183
- average_view_percentage: Float, annotation_clicks: Integer,
184
- card_impressions: Integer, card_clicks: Integer,
185
- card_click_rate: Float, card_teaser_impressions: Integer,
186
- card_teaser_clicks: Integer, card_teaser_click_rate: Float,
187
- annotation_click_through_rate: Float,
188
- annotation_close_rate: Float, estimated_revenue: Float, ad_impressions: Integer,
189
- monetized_playbacks: Integer}
190
-
191
- specify 'by day' do
192
- range = {since: 5.days.ago.to_date, until: 3.days.ago.to_date}
193
- result = video.reports range.merge(only: metrics, by: :day)
194
- metrics.each do |metric, type|
195
- expect(result[metric].keys).to all(be_a Date)
196
- expect(result[metric].values).to all(be_a type)
197
- end
198
- end
199
-
200
- specify 'by month' do
201
- result = video.reports only: metrics, by: :month, since: 1.month.ago
202
- metrics.each do |metric, type|
203
- expect(result[metric].keys).to all(be_a Range)
204
- expect(result[metric].keys.map &:first).to all(be_a Date)
205
- expect(result[metric].keys.map &:first).to eq result[metric].keys.map(&:first).map(&:beginning_of_month)
206
- expect(result[metric].keys.map &:last).to all(be_a Date)
207
- expect(result[metric].keys.map &:last).to eq result[metric].keys.map(&:last).map(&:end_of_month)
208
- expect(result[metric].values).to all(be_a type)
209
- end
210
- end
211
-
212
- specify 'by week' do
213
- range = {since: ENV['YT_TEST_PARTNER_VIDEO_DATE'], until: Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 9}
214
- result = video.reports range.merge(only: metrics, by: :week)
215
- metrics.each do |metric, type|
216
- expect(result[metric].size).to be <= 2
217
- expect(result[metric].keys).to all(be_a Range)
218
- expect(result[metric].keys.map{|range| range.first.wday}.uniq).to be_one
219
- expect(result[metric].keys.map{|range| range.last.wday}.uniq).to be_one
220
- expect(result[metric].values).to all(be_a type)
221
- end
222
- end
223
- end
224
-
225
- describe 'estimated_revenue can be grouped by day' do
226
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
227
- let(:keys) { range.values }
228
-
229
- specify 'with the :by option set to :day' do
230
- estimated_revenue = video.estimated_revenue range.merge by: :day
231
- expect(estimated_revenue.keys).to eq range.values
232
- end
233
- end
234
-
235
- describe 'estimated_revenue can be grouped by country' do
236
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
237
-
238
- specify 'with the :by option set to :country' do
239
- estimated_revenue = video.estimated_revenue range.merge by: :country
240
- expect(estimated_revenue.keys).to all(be_a String)
241
- expect(estimated_revenue.keys.map(&:length).uniq).to eq [2]
242
- expect(estimated_revenue.values).to all(be_a Float)
243
- end
244
- end
245
-
246
- describe 'views can be retrieved for a single US state' do
247
- let(:state_code) { 'NY' }
248
- let(:views) { video.views since: date, by: by, in: location }
249
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
250
-
251
- context 'and grouped by day' do
252
- let(:by) { :day }
253
-
254
- context 'with the :in option set to {state: state code}' do
255
- let(:location) { {state: state_code} }
256
- it { expect(views.keys.min).to eq date.to_date }
257
- end
258
-
259
- context 'with the :in option set to {country: "US", state: state code}' do
260
- let(:location) { {country: 'US', state: state_code} }
261
- it { expect(views.keys.min).to eq date.to_date }
262
- end
263
- end
264
-
265
- context 'and grouped by US state' do
266
- let(:by) { :state }
267
-
268
- context 'with the :in option set to {state: state code}' do
269
- let(:location) { {state: state_code} }
270
- it { expect(views.keys).to eq [state_code] }
271
- end
272
-
273
- context 'with the :in option set to {country: "US", state: state code}' do
274
- let(:location) { {country: 'US', state: state_code} }
275
- it { expect(views.keys).to eq [state_code] }
276
- end
277
- end
278
- end
279
-
280
- describe 'views can be grouped by day' do
281
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
282
- let(:keys) { range.values }
283
-
284
- specify 'with the :by option set to :day' do
285
- views = video.views range.merge by: :day
286
- expect(views.keys).to eq range.values
287
- end
288
- end
289
-
290
- describe 'views can be grouped by traffic source' do
291
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
292
- let(:keys) { Yt::Collections::Reports::TRAFFIC_SOURCES.keys }
293
-
294
- specify 'with the :by option set to :traffic_source' do
295
- views = video.views range.merge by: :traffic_source
296
- expect(views.keys - keys).to be_empty
297
- end
298
-
299
- specify 'and are returned sorted by descending views' do
300
- views = video.views range.merge by: :traffic_source
301
- expect(views.values.sort.reverse).to eq views.values
302
- end
303
- end
304
-
305
- describe 'views can be grouped by playback location' do
306
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
307
- let(:keys) { Yt::Collections::Reports::PLAYBACK_LOCATIONS.keys }
308
-
309
- specify 'with the :by option set to :playback_location' do
310
- views = video.views range.merge by: :playback_location
311
- expect(views.keys - keys).to be_empty
312
- end
313
- end
314
-
315
- describe 'views can be grouped by embedded player location' do
316
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
317
-
318
- specify 'with the :by option set to :embedded_player_location' do
319
- views = video.views range.merge by: :embedded_player_location
320
- expect(views).not_to be_empty
321
- end
322
- end
323
-
324
- describe 'views can be grouped by related video' do
325
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
326
-
327
- specify 'with the :by option set to :related_video' do
328
- views = video.views range.merge by: :related_video
329
- expect(views.keys).to all(be_instance_of Yt::Video)
330
- end
331
- end
332
-
333
- describe 'views can be grouped by search term' do
334
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
335
-
336
- specify 'with the :by option set to :search_term' do
337
- views = video.views range.merge by: :search_term
338
- expect(views.keys).to all(be_a String)
339
- end
340
- end
341
-
342
- describe 'views can be grouped by referrer' do
343
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
344
-
345
- specify 'with the :by option set to :referrer' do
346
- views = video.views range.merge by: :referrer
347
- expect(views.keys).to all(be_a String)
348
- end
349
- end
350
-
351
- describe 'views can be grouped by device type' do
352
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
353
- let(:keys) { Yt::Collections::Reports::DEVICE_TYPES.keys }
354
-
355
- specify 'with the :by option set to :device_type' do
356
- views = video.views range.merge by: :device_type
357
- expect(views.keys - keys).to be_empty
358
- expect(views.values).to all(be_an Integer)
359
- end
360
- end
361
-
362
- describe 'views can be grouped by operating system' do
363
- let(:keys) { Yt::Collections::Reports::OPERATING_SYSTEMS.keys }
364
-
365
- specify 'with the :by option set to :operating_system' do
366
- views = video.views by: :operating_system
367
- expect(views.keys - keys).to be_empty
368
- expect(views.values).to all(be_an Integer)
369
- end
370
- end
371
-
372
- describe 'views can be grouped by YouTube product' do
373
- let(:keys) { Yt::Collections::Reports::YOUTUBE_PRODUCTS.keys }
374
-
375
- specify 'with the :by option set to :youtube_product' do
376
- views = video.views by: :youtube_product
377
- expect(views.keys - keys).to be_empty
378
- expect(views.values).to all(be_an Integer)
379
- end
380
- end
381
-
382
- describe 'views can be grouped by country' do
383
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
384
-
385
- specify 'with the :by option set to :country' do
386
- views = video.views range.merge by: :country
387
- expect(views.keys).to all(be_a String)
388
- expect(views.keys.map(&:length).uniq).to eq [2]
389
- expect(views.values).to all(be_an Integer)
390
- end
391
-
392
- specify 'and are returned sorted by descending views' do
393
- views = video.views range.merge by: :country
394
- expect(views.values.sort.reverse).to eq views.values
395
- end
396
- end
397
-
398
- describe 'views can be grouped by state' do
399
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
400
-
401
- specify 'with the :by option set to :state' do
402
- views = video.views range.merge by: :state
403
- expect(views.keys).to all(be_a String)
404
- expect(views.keys.map(&:length).uniq).to eq [2]
405
- expect(views.values).to all(be_an Integer)
406
- end
407
-
408
- specify 'and are returned sorted by descending views' do
409
- views = video.views range.merge by: :state
410
- expect(views.values.sort.reverse).to eq views.values
411
- end
412
- end
413
-
414
- describe 'views can be grouped by subscribed statuses' do
415
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
416
- let(:keys) { Yt::Collections::Reports::SUBSCRIBED_STATUSES.keys }
417
-
418
- specify 'with the :by option set to subscribed statuses' do
419
- views = video.views range.merge by: :subscribed_status
420
- expect(views.keys - keys).to be_empty
421
- expect(views.values).to all(be_an Integer)
422
- end
423
- end
424
-
425
- describe 'comments can be grouped by day' do
426
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
427
- let(:keys) { range.values }
428
-
429
- specify 'with the :by option set to :day' do
430
- comments = video.comments range.merge by: :day
431
- expect(comments.keys).to eq range.values
432
- end
433
- end
434
-
435
- describe 'comments can be grouped by country' do
436
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
437
-
438
- specify 'with the :by option set to :country' do
439
- comments = video.comments range.merge by: :country
440
- expect(comments.keys).to all(be_a String)
441
- expect(comments.keys.map(&:length).uniq).to eq [2]
442
- expect(comments.values).to all(be_an Integer)
443
- end
444
- end
445
-
446
- describe 'likes can be grouped by day' do
447
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
448
- let(:keys) { range.values }
449
-
450
- specify 'with the :by option set to :day' do
451
- likes = video.likes range.merge by: :day
452
- expect(likes.keys).to eq range.values
453
- end
454
- end
455
-
456
- describe 'likes can be grouped by country' do
457
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
458
-
459
- specify 'with the :by option set to :country' do
460
- likes = video.likes range.merge by: :country
461
- expect(likes.keys).to all(be_a String)
462
- expect(likes.keys.map(&:length).uniq).to eq [2]
463
- expect(likes.values).to all(be_an Integer)
464
- end
465
- end
466
-
467
- describe 'dislikes can be grouped by day' do
468
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
469
- let(:keys) { range.values }
470
-
471
- specify 'with the :by option set to :day' do
472
- dislikes = video.dislikes range.merge by: :day
473
- expect(dislikes.keys).to eq range.values
474
- end
475
- end
476
-
477
- describe 'dislikes can be grouped by country' do
478
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
479
-
480
- specify 'with the :by option set to :country' do
481
- dislikes = video.dislikes range.merge by: :country
482
- expect(dislikes.keys).to all(be_a String)
483
- expect(dislikes.keys.map(&:length).uniq).to eq [2]
484
- expect(dislikes.values).to all(be_an Integer)
485
- end
486
- end
487
-
488
- describe 'shares can be grouped by day' do
489
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
490
- let(:keys) { range.values }
491
-
492
- specify 'with the :by option set to :day' do
493
- shares = video.shares range.merge by: :day
494
- expect(shares.keys).to eq range.values
495
- end
496
- end
497
-
498
- describe 'shares can be grouped by country' do
499
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
500
-
501
- specify 'with the :by option set to :country' do
502
- shares = video.shares range.merge by: :country
503
- expect(shares.keys).to all(be_a String)
504
- expect(shares.keys.map(&:length).uniq).to eq [2]
505
- expect(shares.values).to all(be_an Integer)
506
- end
507
- end
508
-
509
- describe 'gained subscribers can be grouped by day' do
510
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
511
- let(:keys) { range.values }
512
-
513
- specify 'with the :by option set to :day' do
514
- subscribers_gained = video.subscribers_gained range.merge by: :day
515
- expect(subscribers_gained.keys).to eq range.values
516
- end
517
- end
518
-
519
- describe 'gained subscribers can be grouped by country' do
520
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
521
-
522
- specify 'with the :by option set to :country' do
523
- subscribers_gained = video.subscribers_gained range.merge by: :country
524
- expect(subscribers_gained.keys).to all(be_a String)
525
- expect(subscribers_gained.keys.map(&:length).uniq).to eq [2]
526
- expect(subscribers_gained.values).to all(be_an Integer)
527
- end
528
- end
529
-
530
- describe 'lost subscribers can be grouped by day' do
531
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
532
- let(:keys) { range.values }
533
-
534
- specify 'with the :by option set to :day' do
535
- subscribers_lost = video.subscribers_lost range.merge by: :day
536
- expect(subscribers_lost.keys).to eq range.values
537
- end
538
- end
539
-
540
- describe 'lost subscribers can be grouped by country' do
541
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
542
-
543
- specify 'with the :by option set to :country' do
544
- subscribers_lost = video.subscribers_lost range.merge by: :country
545
- expect(subscribers_lost.keys).to all(be_a String)
546
- expect(subscribers_lost.keys.map(&:length).uniq).to eq [2]
547
- expect(subscribers_lost.values).to all(be_an Integer)
548
- end
549
- end
550
-
551
- describe 'added to playlists can be grouped by day' do
552
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
553
- let(:keys) { range.values }
554
-
555
- specify 'with the :by option set to :day' do
556
- videos_added_to_playlists = video.videos_added_to_playlists range.merge by: :day
557
- expect(videos_added_to_playlists.keys).to eq range.values
558
- end
559
- end
560
-
561
- describe 'added to playlists can be grouped by country' do
562
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
563
-
564
- specify 'with the :by option set to :country' do
565
- videos_added_to_playlists = video.videos_added_to_playlists range.merge by: :country
566
- expect(videos_added_to_playlists.keys).to all(be_a String)
567
- expect(videos_added_to_playlists.keys.map(&:length).uniq).to eq [2]
568
- expect(videos_added_to_playlists.values).to all(be_an Integer)
569
- end
570
- end
571
-
572
- describe 'removed from playlists can be grouped by day' do
573
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
574
- let(:keys) { range.values }
575
-
576
- specify 'with the :by option set to :day' do
577
- videos_removed_from_playlists = video.videos_removed_from_playlists range.merge by: :day
578
- expect(videos_removed_from_playlists.keys).to eq range.values
579
- end
580
- end
581
-
582
- describe 'removed from playlists can be grouped by country' do
583
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
584
-
585
- specify 'with the :by option set to :country' do
586
- videos_removed_from_playlists = video.videos_removed_from_playlists range.merge by: :country
587
- expect(videos_removed_from_playlists.keys).to all(be_a String)
588
- expect(videos_removed_from_playlists.keys.map(&:length).uniq).to eq [2]
589
- expect(videos_removed_from_playlists.values).to all(be_an Integer)
590
- end
591
- end
592
-
593
- describe 'estimated minutes watched can be retrieved for a single US state' do
594
- let(:state_code) { 'NY' }
595
- let(:minutes) { video.estimated_minutes_watched since: date, by: by, in: location }
596
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
597
-
598
- context 'and grouped by day' do
599
- let(:by) { :day }
600
-
601
- context 'with the :in option set to {state: state code}' do
602
- let(:location) { {state: state_code} }
603
- it { expect(minutes.keys.min).to eq date.to_date }
604
- end
605
-
606
- context 'with the :in option set to {country: "US", state: state code}' do
607
- let(:location) { {country: 'US', state: state_code} }
608
- it { expect(minutes.keys.min).to eq date.to_date }
609
- end
610
- end
611
-
612
- context 'and grouped by US state' do
613
- let(:by) { :state }
614
-
615
- context 'with the :in option set to {state: state code}' do
616
- let(:location) { {state: state_code} }
617
- it { expect(minutes.keys).to eq [state_code] }
618
- end
619
-
620
- context 'with the :in option set to {country: "US", state: state code}' do
621
- let(:location) { {country: 'US', state: state_code} }
622
- it { expect(minutes.keys).to eq [state_code] }
623
- end
624
- end
625
- end
626
-
627
- describe 'estimated minutes watched can be grouped by day' do
628
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
629
- let(:keys) { range.values }
630
-
631
- specify 'with the :by option set to :day' do
632
- estimated_minutes_watched = video.estimated_minutes_watched range.merge by: :day
633
- expect(estimated_minutes_watched.keys).to eq range.values
634
- end
635
- end
636
-
637
- describe 'estimated minutes watched can be grouped by traffic source' do
638
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
639
- let(:keys) { Yt::Collections::Reports::TRAFFIC_SOURCES.keys }
640
-
641
- specify 'with the :by option set to :traffic_source' do
642
- estimated_minutes_watched = video.estimated_minutes_watched range.merge by: :traffic_source
643
- expect(estimated_minutes_watched.keys - keys).to be_empty
644
- end
645
- end
646
-
647
- describe 'estimated minutes watched can be grouped by playback location' do
648
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
649
- let(:keys) { Yt::Collections::Reports::PLAYBACK_LOCATIONS.keys }
650
-
651
- specify 'with the :by option set to :playback_location' do
652
- estimated_minutes_watched = video.estimated_minutes_watched range.merge by: :playback_location
653
- expect(estimated_minutes_watched.keys - keys).to be_empty
654
- end
655
- end
656
-
657
- describe 'estimated minutes watched can be grouped by embedded player location' do
658
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
659
-
660
- specify 'with the :by option set to :embedded_player_location' do
661
- estimated_minutes_watched = video.estimated_minutes_watched range.merge by: :embedded_player_location
662
- expect(estimated_minutes_watched).not_to be_empty
663
- end
664
- end
665
-
666
- describe 'estimated minutes watched can be grouped by related video' do
667
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
668
-
669
- specify 'with the :by option set to :related_video' do
670
- estimated_minutes_watched = video.estimated_minutes_watched range.merge by: :related_video
671
- expect(estimated_minutes_watched.keys).to all(be_instance_of Yt::Video)
672
- end
673
- end
674
-
675
- describe 'estimated minutes watched can be grouped by search term' do
676
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
677
-
678
- specify 'with the :by option set to :search_term' do
679
- estimated_minutes_watched = video.estimated_minutes_watched range.merge by: :search_term
680
- expect(estimated_minutes_watched.keys).to all(be_a String)
681
- end
682
- end
683
-
684
- describe 'estimated minutes watched can be grouped by referrer' do
685
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
686
-
687
- specify 'with the :by option set to :referrer' do
688
- estimated_minutes_watched = video.estimated_minutes_watched range.merge by: :referrer
689
- expect(estimated_minutes_watched.keys).to all(be_a String)
690
- end
691
- end
692
-
693
- describe 'estimated minutes watched can be grouped by device type' do
694
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
695
-
696
- specify 'with the :by option set to :device_type' do
697
- estimated_minutes_watched = video.estimated_minutes_watched range.merge by: :device_type
698
- expect(estimated_minutes_watched.keys).to all(be_instance_of Symbol)
699
- expect(estimated_minutes_watched.values).to all(be_an Integer)
700
- end
701
- end
702
-
703
- describe 'estimated minutes watched can be grouped by country' do
704
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
705
-
706
- specify 'with the :by option set to :country' do
707
- minutes = video.estimated_minutes_watched range.merge by: :country
708
- expect(minutes.keys).to all(be_a String)
709
- expect(minutes.keys.map(&:length).uniq).to eq [2]
710
- expect(minutes.values).to all(be_an Integer)
711
- end
712
- end
713
-
714
- describe 'estimated minutes watched can be grouped by state' do
715
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
716
-
717
- specify 'with the :by option set to :state' do
718
- minutes = video.estimated_minutes_watched range.merge by: :state
719
- expect(minutes.keys).to all(be_a String)
720
- expect(minutes.keys.map(&:length).uniq).to eq [2]
721
- expect(minutes.values).to all(be_an Integer)
722
- end
723
- end
724
-
725
- describe 'average view duration can be retrieved for a single US state' do
726
- let(:state_code) { 'NY' }
727
- let(:duration) { video.average_view_duration since: date, by: by, in: location }
728
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
729
-
730
- context 'and grouped by day' do
731
- let(:by) { :day }
732
-
733
- context 'with the :in option set to {state: state code}' do
734
- let(:location) { {state: state_code} }
735
- it { expect(duration.keys.min).to eq date.to_date }
736
- end
737
-
738
- context 'with the :in option set to {country: "US", state: state code}' do
739
- let(:location) { {country: 'US', state: state_code} }
740
- it { expect(duration.keys.min).to eq date.to_date }
741
- end
742
- end
743
-
744
- context 'and grouped by US state' do
745
- let(:by) { :state }
746
-
747
- context 'with the :in option set to {state: state code}' do
748
- let(:location) { {state: state_code} }
749
- it { expect(duration.keys).to eq [state_code] }
750
- end
751
-
752
- context 'with the :in option set to {country: "US", state: state code}' do
753
- let(:location) { {country: 'US', state: state_code} }
754
- it { expect(duration.keys).to eq [state_code] }
755
- end
756
- end
757
- end
758
-
759
- describe 'average view duration can be grouped by day' do
760
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
761
- let(:keys) { range.values }
762
-
763
- specify 'with the :by option set to :day' do
764
- average_view_duration = video.average_view_duration range.merge by: :day
765
- expect(average_view_duration.keys).to eq range.values
766
- end
767
- end
768
-
769
- describe 'average view duration can be grouped by country' do
770
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
771
-
772
- specify 'with the :by option set to :country' do
773
- duration = video.average_view_duration range.merge by: :country
774
- expect(duration.keys).to all(be_a String)
775
- expect(duration.keys.map(&:length).uniq).to eq [2]
776
- expect(duration.values).to all(be_an Integer)
777
- end
778
- end
779
-
780
- describe 'average view duration can be grouped by state' do
781
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
782
-
783
- specify 'with the :by option set to :state' do
784
- duration = video.average_view_duration range.merge by: :state
785
- expect(duration.keys).to all(be_a String)
786
- expect(duration.keys.map(&:length).uniq).to eq [2]
787
- expect(duration.values).to all(be_an Integer)
788
- end
789
- end
790
-
791
- describe 'average view percentage can be retrieved for a single US state' do
792
- let(:state_code) { 'NY' }
793
- let(:percentage) { video.average_view_percentage since: date, by: by, in: location }
794
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
795
-
796
- context 'and grouped by day' do
797
- let(:by) { :day }
798
-
799
- context 'with the :in option set to {state: state code}' do
800
- let(:location) { {state: state_code} }
801
- it { expect(percentage.keys.min).to eq date.to_date }
802
- end
803
-
804
- context 'with the :in option set to {country: "US", state: state code}' do
805
- let(:location) { {country: 'US', state: state_code} }
806
- it { expect(percentage.keys.min).to eq date.to_date }
807
- end
808
- end
809
-
810
- context 'and grouped by US state' do
811
- let(:by) { :state }
812
-
813
- context 'with the :in option set to {state: state code}' do
814
- let(:location) { {state: state_code} }
815
- it { expect(percentage.keys).to eq [state_code] }
816
- end
817
-
818
- context 'with the :in option set to {country: "US", state: state code}' do
819
- let(:location) { {country: 'US', state: state_code} }
820
- it { expect(percentage.keys).to eq [state_code] }
821
- end
822
- end
823
- end
824
-
825
- describe 'average view percentage can be grouped by day' do
826
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
827
- let(:keys) { range.values }
828
-
829
- specify 'with the :by option set to :day' do
830
- average_view_percentage = video.average_view_percentage range.merge by: :day
831
- expect(average_view_percentage.keys).to eq range.values
832
- end
833
- end
834
-
835
- describe 'average view percentage can be grouped by country' do
836
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
837
-
838
- specify 'with the :by option set to :country' do
839
- percentage = video.average_view_percentage range.merge by: :country
840
- expect(percentage.keys).to all(be_a String)
841
- expect(percentage.keys.map(&:length).uniq).to eq [2]
842
- expect(percentage.values).to all(be_a Float)
843
- end
844
- end
845
-
846
- describe 'average view percentage can be grouped by state' do
847
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
848
-
849
- specify 'with the :by option set to :state' do
850
- percentage = video.average_view_percentage range.merge by: :state
851
- expect(percentage.keys).to all(be_a String)
852
- expect(percentage.keys.map(&:length).uniq).to eq [2]
853
- expect(percentage.values).to all(be_a Float)
854
- end
855
- end
856
-
857
- describe 'ad_impressions can be grouped by day' do
858
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
859
- let(:keys) { range.values }
860
-
861
- specify 'with the :by option set to :day' do
862
- ad_impressions = video.ad_impressions range.merge by: :day
863
- expect(ad_impressions.keys).to eq range.values
864
- end
865
- end
866
-
867
- describe 'ad_impressions can be grouped by country' do
868
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
869
-
870
- specify 'with the :by option set to :country' do
871
- ad_impressions = video.ad_impressions range.merge by: :country
872
- expect(ad_impressions.keys).to all(be_a String)
873
- expect(ad_impressions.keys.map(&:length).uniq).to eq [2]
874
- expect(ad_impressions.values).to all(be_an Integer)
875
- end
876
- end
877
-
878
- describe 'monetized_playbacks can be grouped by day' do
879
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
880
- let(:keys) { range.values }
881
-
882
- specify 'with the :by option set to :day' do
883
- monetized_playbacks = video.monetized_playbacks range.merge by: :day
884
- expect(monetized_playbacks.keys).to eq range.values
885
- end
886
- end
887
-
888
- describe 'monetized playbacks can be grouped by country' do
889
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
890
-
891
- specify 'with the :by option set to :country' do
892
- playbacks = video.monetized_playbacks range.merge by: :country
893
- expect(playbacks.keys).to all(be_a String)
894
- expect(playbacks.keys.map(&:length).uniq).to eq [2]
895
- expect(playbacks.values).to all(be_an Integer)
896
- end
897
- end
898
-
899
- describe 'playback-based CPM can be grouped by day' do
900
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
901
- let(:keys) { range.values }
902
-
903
- specify 'with the :by option set to :day' do
904
- playback_based_cpm = video.playback_based_cpm range.merge by: :day
905
- expect(playback_based_cpm.keys).to eq range.values
906
- end
907
- end
908
-
909
- describe 'playback-based CPM can be grouped by country' do
910
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
911
-
912
- specify 'with the :by option set to :country' do
913
- playbacks = video.playback_based_cpm range.merge by: :country
914
- expect(playbacks.keys).to all(be_a String)
915
- expect(playbacks.keys.map(&:length).uniq).to eq [2]
916
- expect(playbacks.values).to all(be_a Float)
917
- end
918
- end
919
-
920
- describe 'annotation clicks can be retrieved for a single US state' do
921
- let(:state_code) { 'CA' }
922
- let(:clicks) { video.annotation_clicks since: date, by: by, in: location }
923
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
924
-
925
- context 'and grouped by day' do
926
- let(:by) { :day }
927
-
928
- context 'with the :in option set to {state: state code}' do
929
- let(:location) { {state: state_code} }
930
- it { expect(clicks.keys.min).to eq date.to_date }
931
- end
932
-
933
- context 'with the :in option set to {country: "US", state: state code}' do
934
- let(:location) { {country: 'US', state: state_code} }
935
- it { expect(clicks.keys.min).to eq date.to_date }
936
- end
937
- end
938
-
939
- context 'and grouped by US state' do
940
- let(:by) { :state }
941
-
942
- context 'with the :in option set to {state: state code}' do
943
- let(:location) { {state: state_code} }
944
- it { expect(clicks.keys).to eq [state_code] }
945
- end
946
-
947
- context 'with the :in option set to {country: "US", state: state code}' do
948
- let(:location) { {country: 'US', state: state_code} }
949
- it { expect(clicks.keys).to eq [state_code] }
950
- end
951
- end
952
- end
953
-
954
- describe 'annotation clicks can be grouped by day' do
955
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE'], until: Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 5} }
956
-
957
- specify 'with the :by option set to :day' do
958
- annotation_clicks = video.annotation_clicks range.merge by: :day
959
- expect(annotation_clicks.values).to all(be_an Integer)
960
- end
961
- end
962
-
963
- describe 'annotation clicks can be grouped by country' do
964
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
965
-
966
- specify 'with the :by option set to :country' do
967
- clicks = video.annotation_clicks range.merge by: :country
968
- expect(clicks.keys).to all(be_a String)
969
- expect(clicks.keys.map(&:length).uniq).to eq [2]
970
- expect(clicks.values).to all(be_an Integer)
971
- end
972
- end
973
-
974
- describe 'annotation clicks can be grouped by state' do
975
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
976
-
977
- specify 'with the :by option set to :state' do
978
- clicks = video.annotation_clicks range.merge by: :state
979
- expect(clicks.keys).to all(be_a String)
980
- expect(clicks.keys.map(&:length).uniq).to eq [2]
981
- expect(clicks.values).to all(be_an Integer)
982
- end
983
- end
984
-
985
- describe 'annotation click_through_rate can be retrieved for a single US state' do
986
- let(:state_code) { 'CA' }
987
- let(:click_through_rate) { video.annotation_click_through_rate since: date, by: by, in: location }
988
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
989
-
990
- context 'and grouped by day' do
991
- let(:by) { :day }
992
-
993
- context 'with the :in option set to {state: state code}' do
994
- let(:location) { {state: state_code} }
995
- it { expect(click_through_rate.keys.min).to eq date.to_date }
996
- end
997
-
998
- context 'with the :in option set to {country: "US", state: state code}' do
999
- let(:location) { {country: 'US', state: state_code} }
1000
- it { expect(click_through_rate.keys.min).to eq date.to_date }
1001
- end
1002
- end
1003
-
1004
- context 'and grouped by US state' do
1005
- let(:by) { :state }
1006
-
1007
- context 'with the :in option set to {state: state code}' do
1008
- let(:location) { {state: state_code} }
1009
- it { expect(click_through_rate.keys).to eq [state_code] }
1010
- end
1011
-
1012
- context 'with the :in option set to {country: "US", state: state code}' do
1013
- let(:location) { {country: 'US', state: state_code} }
1014
- it { expect(click_through_rate.keys).to eq [state_code] }
1015
- end
1016
- end
1017
- end
1018
-
1019
- describe 'annotation click-through rate can be grouped by day' do
1020
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE'], until: Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 5} }
1021
-
1022
- specify 'with the :by option set to :day' do
1023
- annotation_click_through_rate = video.annotation_click_through_rate range.merge by: :day
1024
- expect(annotation_click_through_rate.values).to all(be_instance_of Float)
1025
- end
1026
- end
1027
-
1028
- describe 'annotation click-through rate can be grouped by country' do
1029
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
1030
-
1031
- specify 'with the :by option set to :country' do
1032
- rate = video.annotation_click_through_rate range.merge by: :country
1033
- expect(rate.keys).to all(be_a String)
1034
- expect(rate.keys.map(&:length).uniq).to eq [2]
1035
- expect(rate.values).to all(be_a Float)
1036
- end
1037
- end
1038
-
1039
- describe 'annotation click-through rate can be grouped by state' do
1040
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
1041
-
1042
- specify 'with the :by option set to :state' do
1043
- rate = video.annotation_click_through_rate range.merge by: :state
1044
- expect(rate.keys).to all(be_a String)
1045
- expect(rate.keys.map(&:length).uniq).to eq [2]
1046
- expect(rate.values).to all(be_a Float)
1047
- end
1048
- end
1049
-
1050
- describe 'annotation close_rate can be retrieved for a single US state' do
1051
- let(:state_code) { 'CA' }
1052
- let(:close_rate) { video.annotation_close_rate since: date, by: by, in: location }
1053
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
1054
-
1055
- context 'and grouped by day' do
1056
- let(:by) { :day }
1057
-
1058
- context 'with the :in option set to {state: state code}' do
1059
- let(:location) { {state: state_code} }
1060
- it { expect(close_rate.keys.min).to eq date.to_date }
1061
- end
1062
-
1063
- context 'with the :in option set to {country: "US", state: state code}' do
1064
- let(:location) { {country: 'US', state: state_code} }
1065
- it { expect(close_rate.keys.min).to eq date.to_date }
1066
- end
1067
- end
1068
-
1069
- context 'and grouped by US state' do
1070
- let(:by) { :state }
1071
-
1072
- context 'with the :in option set to {state: state code}' do
1073
- let(:location) { {state: state_code} }
1074
- it { expect(close_rate.keys).to eq [state_code] }
1075
- end
1076
-
1077
- context 'with the :in option set to {country: "US", state: state code}' do
1078
- let(:location) { {country: 'US', state: state_code} }
1079
- it { expect(close_rate.keys).to eq [state_code] }
1080
- end
1081
- end
1082
- end
1083
-
1084
- describe 'annotation close rate can be grouped by day' do
1085
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE'], until: Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 5} }
1086
-
1087
- specify 'with the :by option set to :day' do
1088
- annotation_close_rate = video.annotation_close_rate range.merge by: :day
1089
- expect(annotation_close_rate.values).to all(be_instance_of Float)
1090
- end
1091
- end
1092
-
1093
- describe 'annotation close rate can be grouped by country' do
1094
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
1095
-
1096
- specify 'with the :by option set to :country' do
1097
- rate = video.annotation_close_rate range.merge by: :country
1098
- expect(rate.keys).to all(be_a String)
1099
- expect(rate.keys.map(&:length).uniq).to eq [2]
1100
- expect(rate.values).to all(be_a Float)
1101
- end
1102
- end
1103
-
1104
- describe 'annotation close rate can be grouped by state' do
1105
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
1106
-
1107
- specify 'with the :by option set to :state' do
1108
- rate = video.annotation_close_rate range.merge by: :state
1109
- expect(rate.keys).to all(be_a String)
1110
- expect(rate.keys.map(&:length).uniq).to eq [2]
1111
- expect(rate.values).to all(be_a Float)
1112
- end
1113
- end
1114
-
1115
- describe 'viewer percentage can be retrieved for a range of days' do
1116
- let(:viewer_percentage) { video.viewer_percentage since: 1.year.ago, until: 10.days.ago}
1117
- it { expect(viewer_percentage).to be_a Hash }
1118
- end
1119
-
1120
- describe 'viewer_percentage can be grouped by gender and age group' do
1121
- let(:range) { {since: 1.year.ago.to_date, until: 1.week.ago.to_date} }
1122
- let(:keys) { range.values }
1123
-
1124
- specify 'without a :by option (default)' do
1125
- viewer_percentage = video.viewer_percentage range
1126
- expect(viewer_percentage.keys).to match_array [:female, :male]
1127
- expect(viewer_percentage[:female].keys - %w(65- 35-44 45-54 13-17 25-34 55-64 18-24)).to be_empty
1128
- expect(viewer_percentage[:female].values).to all(be_instance_of Float)
1129
- expect(viewer_percentage[:male].keys - %w(65- 35-44 45-54 13-17 25-34 55-64 18-24)).to be_empty
1130
- expect(viewer_percentage[:male].values).to all(be_instance_of Float)
1131
- end
1132
-
1133
- specify 'with the :by option set to :gender_age_group' do
1134
- viewer_percentage = video.viewer_percentage range.merge by: :gender_age_group
1135
- expect(viewer_percentage.keys).to match_array [:female, :male]
1136
- expect(viewer_percentage[:female].keys - %w(65- 35-44 45-54 13-17 25-34 55-64 18-24)).to be_empty
1137
- expect(viewer_percentage[:female].values).to all(be_instance_of Float)
1138
- expect(viewer_percentage[:male].keys - %w(65- 35-44 45-54 13-17 25-34 55-64 18-24)).to be_empty
1139
- expect(viewer_percentage[:male].values).to all(be_instance_of Float)
1140
- end
1141
- end
1142
-
1143
- describe 'viewer percentage can be retrieved for a single country' do
1144
- let(:country_code) { 'US' }
1145
- let(:viewer_percentage) { video.viewer_percentage since: date, in: location }
1146
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
1147
-
1148
- context 'with the :in option set to the country code' do
1149
- let(:location) { country_code }
1150
- it { expect(viewer_percentage.keys).to match_array [:female, :male] }
1151
- end
1152
-
1153
- context 'with the :in option set to {country: country code}' do
1154
- let(:location) { {country: country_code} }
1155
- it { expect(viewer_percentage.keys).to match_array [:female, :male] }
1156
- end
1157
- end
1158
-
1159
- describe 'viewer percentage can be retrieved for a single US state' do
1160
- let(:state_code) { 'CA' }
1161
- let(:viewer_percentage) { video.viewer_percentage since: date, in: location }
1162
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
1163
-
1164
- context 'with the :in option set to {state: state code}' do
1165
- let(:location) { {state: state_code} }
1166
- it { expect(viewer_percentage.keys).to match_array [:female, :male] }
1167
- end
1168
-
1169
- context 'with the :in option set to {country: "US", state: state code}' do
1170
- let(:location) { {country: 'US', state: state_code} }
1171
- it { expect(viewer_percentage.keys).to match_array [:female, :male] }
1172
- end
1173
- end
1174
-
1175
- describe 'viewer percentage can be grouped by gender' do
1176
- let(:range) { {since: 1.year.ago.to_date, until: 1.week.ago.to_date} }
1177
- let(:keys) { range.values }
1178
-
1179
- specify 'with the :by option set to :gender' do
1180
- viewer_percentage = video.viewer_percentage range.merge by: :gender
1181
- expect(viewer_percentage.keys).to match_array [:female, :male]
1182
- expect(viewer_percentage[:female]).to be_a Float
1183
- expect(viewer_percentage[:male]).to be_a Float
1184
- end
1185
- end
1186
-
1187
- describe 'viewer_percentage can be grouped by age group' do
1188
- let(:range) { {since: 1.year.ago.to_date, until: 1.week.ago.to_date} }
1189
- let(:keys) { range.values }
1190
-
1191
- specify 'with the :by option set to :age_group' do
1192
- viewer_percentage = video.viewer_percentage range.merge by: :age_group
1193
- expect(viewer_percentage.keys - %w(65- 35-44 45-54 13-17 25-34 55-64 18-24)).to be_empty
1194
- expect(viewer_percentage.values).to all(be_instance_of Float)
1195
- end
1196
- end
1197
- end
1198
-
1199
- context 'given a video claimable by the authenticated Content Owner' do
1200
- let(:id) { ENV['YT_TEST_PARTNER_CLAIMABLE_VIDEO_ID'] }
1201
-
1202
- describe 'the advertising formats can be updated and retrieved' do
1203
- let!(:old_formats) { video.ad_formats }
1204
- let!(:new_formats) { %w(standard_instream overlay trueview_instream).sample(2) }
1205
- before { video.advertising_options_set.update ad_formats: new_formats }
1206
- it { expect(video.ad_formats).to match_array new_formats }
1207
- after { video.advertising_options_set.update ad_formats: old_formats }
1208
- end
1209
- end
1210
- end
1211
-
1212
- context 'given a video of a partnered channel' do
1213
- let(:id) { 'kocTIjlZwGo' }
1214
-
1215
- describe 'title can be updated' do
1216
- let!(:old_title) { video.title }
1217
- let!(:new_title) { old_title.reverse }
1218
- before { video.update title: new_title }
1219
- it { expect(video.title).to eq(new_title) }
1220
- after { video.update title: old_title }
1221
- end
1222
- end
1223
- end