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,767 +0,0 @@
1
- # encoding: UTF-8
2
- require 'spec_helper'
3
- require 'yt/models/channel'
4
- require 'yt/models/playlist'
5
-
6
- describe Yt::Playlist, :partner do
7
- subject(:playlist) { Yt::Playlist.new id: id, auth: $content_owner }
8
-
9
- context 'given a playlist of a partnered channel', :partner do
10
- context 'managed by the authenticated Content Owner' do
11
- let(:id) { ENV['YT_TEST_PARTNER_PLAYLIST_ID'] }
12
-
13
- describe 'multiple reports can be retrieved at once' do
14
- metrics = {views: Integer, estimated_minutes_watched: Integer,
15
- average_view_duration: Integer, playlist_starts: Integer,
16
- average_time_in_playlist: Float, views_per_playlist_start: Float}
17
-
18
- specify 'by day' do
19
- range = {since: 5.days.ago.to_date, until: 3.days.ago.to_date}
20
- result = playlist.reports range.merge(only: metrics, by: :day)
21
- metrics.each do |metric, type|
22
- expect(result[metric].keys).to all(be_a Date)
23
- expect(result[metric].values).to all(be_a type)
24
- end
25
- end
26
-
27
- specify 'by month' do
28
- result = playlist.reports only: metrics, by: :month, since: 1.month.ago
29
- metrics.each do |metric, type|
30
- expect(result[metric].keys).to all(be_a Range)
31
- expect(result[metric].keys.map &:first).to all(be_a Date)
32
- expect(result[metric].keys.map &:first).to eq result[metric].keys.map(&:first).map(&:beginning_of_month)
33
- expect(result[metric].keys.map &:last).to all(be_a Date)
34
- expect(result[metric].keys.map &:last).to eq result[metric].keys.map(&:last).map(&:end_of_month)
35
- expect(result[metric].values).to all(be_a type)
36
- end
37
- end
38
-
39
- specify 'by week' do
40
- range = {since: ENV['YT_TEST_PARTNER_VIDEO_DATE'], until: Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 9}
41
- result = playlist.reports range.merge(only: metrics, by: :week)
42
- metrics.each do |metric, type|
43
- expect(result[metric].size).to be <= 2
44
- expect(result[metric].keys).to all(be_a Range)
45
- expect(result[metric].keys.map{|range| range.first.wday}.uniq).to be_one
46
- expect(result[metric].keys.map{|range| range.last.wday}.uniq).to be_one
47
- expect(result[metric].values).to all(be_a type)
48
- end
49
- end
50
- end
51
-
52
- {views: Integer, estimated_minutes_watched: Integer,
53
- average_view_duration: Integer, playlist_starts: Integer,
54
- average_time_in_playlist: Float,
55
- views_per_playlist_start: Float}.each do |metric, type|
56
- describe "#{metric} can be retrieved for a range of days" do
57
- let(:date_in) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
58
- let(:date_out) { Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 5 }
59
- let(:metric) { metric }
60
- let(:result) { playlist.public_send metric, options }
61
-
62
- context 'with a given start and end (:since/:until option)' do
63
- let(:options) { {by: :day, since: date_in, until: date_out} }
64
- specify do
65
- expect(result.keys.min).to eq date_in.to_date
66
- expect(result.keys.max).to eq date_out.to_date
67
- end
68
- end
69
-
70
- context 'with a given start and end (:from/:to option)' do
71
- let(:options) { {by: :day, from: date_in, to: date_out} }
72
- specify do
73
- expect(result.keys.min).to eq date_in.to_date
74
- expect(result.keys.max).to eq date_out.to_date
75
- end
76
- end
77
- end
78
-
79
- describe "#{metric} can be grouped by month" do
80
- let(:metric) { metric }
81
- let(:result) { playlist.public_send metric, by: :month, since: 1.month.ago }
82
- specify do
83
- expect(result.keys).to all(be_a Range)
84
- expect(result.keys.map &:first).to all(be_a Date)
85
- expect(result.keys.map &:first).to eq result.keys.map(&:first).map(&:beginning_of_month)
86
- expect(result.keys.map &:last).to all(be_a Date)
87
- expect(result.keys.map &:last).to eq result.keys.map(&:last).map(&:end_of_month)
88
- end
89
- end
90
-
91
- describe "#{metric} can be grouped by week and returns non-overlapping periods" do
92
- let(:metric) { metric }
93
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE'], until: Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 9} }
94
- let(:result) { playlist.public_send metric, range.merge(by: :week)}
95
- specify do
96
- expect(result.size).to be <= 2
97
- expect(result.keys).to all(be_a Range)
98
- expect(result.keys.map{|range| range.first.wday}.uniq).to be_one
99
- expect(result.keys.map{|range| range.last.wday}.uniq).to be_one
100
- end
101
- end
102
-
103
- describe "#{metric} can be grouped by range" do
104
- let(:metric) { metric }
105
-
106
- context 'without a :by option (default)' do
107
- let(:result) { playlist.public_send metric }
108
- specify do
109
- expect(result.size).to be 1
110
- expect(result[:total]).to be_a type
111
- end
112
- end
113
-
114
- context 'with the :by option set to :range' do
115
- let(:result) { playlist.public_send metric, by: :range }
116
- specify do
117
- expect(result.size).to be 1
118
- expect(result[:total]).to be_a type
119
- end
120
- end
121
- end
122
-
123
- describe "#{metric} can be retrieved for a single country" do
124
- let(:result) { playlist.public_send metric, options }
125
-
126
- context 'and grouped by day' do
127
- let(:date_in) { 5.days.ago }
128
- let(:options) { {by: :day, since: date_in, in: location} }
129
-
130
- context 'with the :in option set to the country code' do
131
- let(:location) { 'US' }
132
- it { expect(result.keys.min).to eq date_in.to_date }
133
- end
134
-
135
- context 'with the :in option set to {country: country code}' do
136
- let(:location) { {country: 'US'} }
137
- it { expect(result.keys.min).to eq date_in.to_date }
138
- end
139
- end
140
-
141
- context 'and grouped by country' do
142
- let(:options) { {by: :country, in: location} }
143
-
144
- context 'with the :in option set to the country code' do
145
- let(:location) { 'US' }
146
- it { expect(result.keys).to eq ['US'] }
147
- end
148
-
149
- context 'with the :in option set to {country: country code}' do
150
- let(:location) { {country: 'US'} }
151
- it { expect(result.keys).to eq ['US'] }
152
- end
153
- end
154
- end
155
- end
156
-
157
- describe 'views can be retrieved for a single US state' do
158
- let(:state_code) { 'CA' }
159
- let(:result) { playlist.views since: date, by: by, in: location }
160
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
161
-
162
- context 'and grouped by day' do
163
- let(:by) { :day }
164
-
165
- context 'with the :in option set to {state: state code}' do
166
- let(:location) { {state: state_code} }
167
- it { expect(result.keys.min).to eq date.to_date }
168
- end
169
-
170
- context 'with the :in option set to {country: "US", state: state code}' do
171
- let(:location) { {country: 'US', state: state_code} }
172
- it { expect(result.keys.min).to eq date.to_date }
173
- end
174
- end
175
-
176
- context 'and grouped by US state' do
177
- let(:by) { :state }
178
-
179
- context 'with the :in option set to {state: state code}' do
180
- let(:location) { {state: state_code} }
181
- it { expect(result.keys).to eq [state_code] }
182
- end
183
-
184
- context 'with the :in option set to {country: "US", state: state code}' do
185
- let(:location) { {country: 'US', state: state_code} }
186
- it { expect(result.keys).to eq [state_code] }
187
- end
188
- end
189
- end
190
-
191
- describe 'views can be grouped by day' do
192
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
193
- let(:keys) { range.values }
194
-
195
- specify 'with the :by option set to :day' do
196
- views = playlist.views range.merge by: :day
197
- expect(views.keys).to eq range.values
198
- end
199
- end
200
-
201
- describe 'views can be grouped by traffic source' do
202
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
203
- let(:keys) { Yt::Collections::Reports::TRAFFIC_SOURCES.keys }
204
-
205
- specify 'with the :by option set to :traffic_source' do
206
- views = playlist.views range.merge by: :traffic_source
207
- expect(views.keys - keys).to be_empty
208
- end
209
- end
210
-
211
- describe 'views can be grouped by playback location' do
212
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
213
- let(:keys) { Yt::Collections::Reports::PLAYBACK_LOCATIONS.keys }
214
-
215
- specify 'with the :by option set to :playback_location' do
216
- views = playlist.views range.merge by: :playback_location
217
- expect(views.keys - keys).to be_empty
218
- end
219
- end
220
-
221
- describe 'views can be grouped by related video' do
222
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
223
-
224
- specify 'with the :by option set to :related_video' do
225
- views = playlist.views range.merge by: :related_video
226
- expect(views.keys).to all(be_instance_of Yt::Video)
227
- end
228
- end
229
-
230
- describe 'views can be grouped by search term' do
231
- let(:range) { {since: ENV['YT_TEST_PARTNER_PLAYLIST_DATE']} }
232
-
233
- specify 'with the :by option set to :search_term' do
234
- views = playlist.views range.merge by: :search_term
235
- expect(views.keys).to all(be_a String)
236
- end
237
- end
238
-
239
- describe 'views can be grouped by referrer' do
240
- let(:range) { {since: ENV['YT_TEST_PARTNER_PLAYLIST_DATE']} }
241
-
242
- specify 'with the :by option set to :referrer' do
243
- views = playlist.views range.merge by: :referrer
244
- expect(views.keys).to all(be_a String)
245
- end
246
- end
247
-
248
- describe 'views can be grouped by video' do
249
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
250
-
251
- specify 'with the :by option set to :video' do
252
- views = playlist.views range.merge by: :video
253
- expect(views.keys).to all(be_instance_of Yt::Video)
254
- end
255
- end
256
-
257
- describe 'views can be grouped by playlist' do
258
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
259
-
260
- specify 'with the :by option set to :playlist' do
261
- views = playlist.views range.merge by: :playlist
262
- expect(views.keys).to all(be_instance_of Yt::Playlist)
263
- end
264
- end
265
-
266
- describe 'views can be grouped by device type' do
267
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
268
-
269
- specify 'with the :by option set to :device_type' do
270
- views = playlist.views range.merge by: :device_type
271
- expect(views.keys).to all(be_instance_of Symbol)
272
- expect(views.values).to all(be_an Integer)
273
- end
274
- end
275
-
276
- describe 'views can be grouped by country' do
277
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
278
-
279
- specify 'with the :by option set to :country' do
280
- views = playlist.views range.merge by: :country
281
- expect(views.keys).to all(be_a String)
282
- expect(views.keys.map(&:length).uniq).to eq [2]
283
- expect(views.values).to all(be_an Integer)
284
- end
285
- end
286
-
287
- describe 'views can be grouped by state' do
288
- let(:range) { {since: ENV['YT_TEST_PARTNER_PLAYLIST_DATE']} }
289
-
290
- specify 'with the :by option set to :state' do
291
- views = playlist.views range.merge by: :state
292
- expect(views.keys).to all(be_a String)
293
- expect(views.keys.map(&:length).uniq).to eq [2]
294
- expect(views.values).to all(be_an Integer)
295
- end
296
- end
297
-
298
- describe 'estimated minutes watched can be retrieved for a single US state' do
299
- let(:state_code) { 'CA' }
300
- let(:result) { playlist.estimated_minutes_watched since: date, by: by, in: location }
301
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
302
-
303
- context 'and grouped by day' do
304
- let(:by) { :day }
305
-
306
- context 'with the :in option set to {state: state code}' do
307
- let(:location) { {state: state_code} }
308
- it { expect(result.keys.min).to eq date.to_date }
309
- end
310
-
311
- context 'with the :in option set to {country: "US", state: state code}' do
312
- let(:location) { {country: 'US', state: state_code} }
313
- it { expect(result.keys.min).to eq date.to_date }
314
- end
315
- end
316
-
317
- context 'and grouped by US state' do
318
- let(:by) { :state }
319
-
320
- context 'with the :in option set to {state: state code}' do
321
- let(:location) { {state: state_code} }
322
- it { expect(result.keys).to eq [state_code] }
323
- end
324
-
325
- context 'with the :in option set to {country: "US", state: state code}' do
326
- let(:location) { {country: 'US', state: state_code} }
327
- it { expect(result.keys).to eq [state_code] }
328
- end
329
- end
330
- end
331
-
332
- describe 'estimated minutes watched can be grouped by day' do
333
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
334
- let(:keys) { range.values }
335
-
336
- specify 'with the :by option set to :day' do
337
- minutes = playlist.estimated_minutes_watched range.merge by: :day
338
- expect(minutes.keys).to eq range.values
339
- end
340
- end
341
-
342
- describe 'estimated minutes watched can be grouped by traffic source' do
343
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
344
- let(:keys) { Yt::Collections::Reports::TRAFFIC_SOURCES.keys }
345
-
346
- specify 'with the :by option set to :traffic_source' do
347
- minutes = playlist.estimated_minutes_watched range.merge by: :traffic_source
348
- expect(minutes.keys - keys).to be_empty
349
- end
350
- end
351
-
352
- describe 'estimated minutes watched can be grouped by playback location' do
353
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
354
- let(:keys) { Yt::Collections::Reports::PLAYBACK_LOCATIONS.keys }
355
-
356
- specify 'with the :by option set to :playback_location' do
357
- minutes = playlist.estimated_minutes_watched range.merge by: :playback_location
358
- expect(minutes.keys - keys).to be_empty
359
- end
360
- end
361
-
362
- describe 'estimated minutes watched can be grouped by related video' do
363
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
364
-
365
- specify 'with the :by option set to :related_video' do
366
- minutes = playlist.estimated_minutes_watched range.merge by: :related_video
367
- expect(minutes.keys).to all(be_instance_of Yt::Video)
368
- end
369
- end
370
-
371
- describe 'estimated minutes watched can be grouped by search term' do
372
- let(:range) { {since: ENV['YT_TEST_PARTNER_PLAYLIST_DATE']} }
373
-
374
- specify 'with the :by option set to :search_term' do
375
- minutes = playlist.estimated_minutes_watched range.merge by: :search_term
376
- expect(minutes.keys).to all(be_a String)
377
- end
378
- end
379
-
380
- describe 'estimated minutes watched can be grouped by referrer' do
381
- let(:range) { {since: ENV['YT_TEST_PARTNER_PLAYLIST_DATE']} }
382
-
383
- specify 'with the :by option set to :referrer' do
384
- minutes = playlist.estimated_minutes_watched range.merge by: :referrer
385
- expect(minutes.keys).to all(be_a String)
386
- end
387
- end
388
-
389
- describe 'estimated minutes watched can be grouped by video' do
390
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
391
-
392
- specify 'with the :by option set to :video' do
393
- minutes = playlist.estimated_minutes_watched range.merge by: :video
394
- expect(minutes.keys).to all(be_instance_of Yt::Video)
395
- end
396
- end
397
-
398
- describe 'estimated minutes watched can be grouped by playlist' do
399
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
400
-
401
- specify 'with the :by option set to :playlist' do
402
- minutes = playlist.estimated_minutes_watched range.merge by: :playlist
403
- expect(minutes.keys).to all(be_instance_of Yt::Playlist)
404
- end
405
- end
406
-
407
- describe 'estimated minutes watched can be grouped by device type' do
408
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
409
-
410
- specify 'with the :by option set to :device_type' do
411
- minutes = playlist.estimated_minutes_watched range.merge by: :device_type
412
- expect(minutes.keys).to all(be_instance_of Symbol)
413
- expect(minutes.values).to all(be_an Integer)
414
- end
415
- end
416
-
417
- describe 'estimated minutes watched can be grouped by country' do
418
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
419
-
420
- specify 'with the :by option set to :country' do
421
- minutes = playlist.estimated_minutes_watched range.merge by: :country
422
- expect(minutes.keys).to all(be_a String)
423
- expect(minutes.keys.map(&:length).uniq).to eq [2]
424
- expect(minutes.values).to all(be_an Integer)
425
- end
426
- end
427
-
428
- describe 'estimated minutes watched can be grouped by state' do
429
- let(:range) { {since: ENV['YT_TEST_PARTNER_PLAYLIST_DATE']} }
430
-
431
- specify 'with the :by option set to :state' do
432
- minutes = playlist.estimated_minutes_watched range.merge by: :state
433
- expect(minutes.keys).to all(be_a String)
434
- expect(minutes.keys.map(&:length).uniq).to eq [2]
435
- expect(minutes.values).to all(be_an Integer)
436
- end
437
- end
438
-
439
- describe 'viewer percentage can be retrieved for a range of days' do
440
- let(:viewer_percentage) { playlist.viewer_percentage since: 1.year.ago, until: 10.days.ago}
441
- it { expect(viewer_percentage).to be_a Hash }
442
- end
443
-
444
- describe 'viewer_percentage can be grouped by gender and age group' do
445
- let(:range) { {since: 1.year.ago.to_date, until: 1.week.ago.to_date} }
446
- let(:keys) { range.values }
447
-
448
- specify 'without a :by option (default)' do
449
- viewer_percentage = playlist.viewer_percentage range
450
- expect(viewer_percentage.keys).to match_array [:female, :male]
451
- expect(viewer_percentage[:female].keys - %w(65- 35-44 45-54 13-17 25-34 55-64 18-24)).to be_empty
452
- expect(viewer_percentage[:female].values).to all(be_instance_of Float)
453
- expect(viewer_percentage[:male].keys - %w(65- 35-44 45-54 13-17 25-34 55-64 18-24)).to be_empty
454
- expect(viewer_percentage[:male].values).to all(be_instance_of Float)
455
- end
456
-
457
- specify 'with the :by option set to :gender_age_group' do
458
- viewer_percentage = playlist.viewer_percentage range.merge by: :gender_age_group
459
- expect(viewer_percentage.keys).to match_array [:female, :male]
460
- expect(viewer_percentage[:female].keys - %w(65- 35-44 45-54 13-17 25-34 55-64 18-24)).to be_empty
461
- expect(viewer_percentage[:female].values).to all(be_instance_of Float)
462
- expect(viewer_percentage[:male].keys - %w(65- 35-44 45-54 13-17 25-34 55-64 18-24)).to be_empty
463
- expect(viewer_percentage[:male].values).to all(be_instance_of Float)
464
- end
465
- end
466
-
467
- describe 'viewer_percentage can be grouped by gender' do
468
- let(:range) { {since: 1.year.ago.to_date, until: 1.week.ago.to_date} }
469
- let(:keys) { range.values }
470
-
471
- specify 'with the :by option set to :gender' do
472
- viewer_percentage = playlist.viewer_percentage range.merge by: :gender
473
- expect(viewer_percentage.keys).to match_array [:female, :male]
474
- expect(viewer_percentage[:female]).to be_a Float
475
- expect(viewer_percentage[:male]).to be_a Float
476
- end
477
- end
478
-
479
- describe 'viewer_percentage can be grouped by age group' do
480
- let(:range) { {since: 1.year.ago.to_date, until: 1.week.ago.to_date} }
481
- let(:keys) { range.values }
482
-
483
- specify 'with the :by option set to :age_group' do
484
- viewer_percentage = playlist.viewer_percentage range.merge by: :age_group
485
- expect(viewer_percentage.keys - %w(65- 35-44 45-54 13-17 25-34 55-64 18-24)).to be_empty
486
- expect(viewer_percentage.values).to all(be_instance_of Float)
487
- end
488
- end
489
-
490
-
491
- describe 'average view duration can be retrieved for a single US state' do
492
- let(:state_code) { 'CA' }
493
- let(:result) { playlist.average_view_duration since: date, by: by, in: location }
494
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
495
-
496
- context 'and grouped by day' do
497
- let(:by) { :day }
498
-
499
- context 'with the :in option set to {state: state code}' do
500
- let(:location) { {state: state_code} }
501
- it { expect(result.keys.min).to eq date.to_date }
502
- end
503
-
504
- context 'with the :in option set to {country: "US", state: state code}' do
505
- let(:location) { {country: 'US', state: state_code} }
506
- it { expect(result.keys.min).to eq date.to_date }
507
- end
508
- end
509
-
510
- context 'and grouped by US state' do
511
- let(:by) { :state }
512
-
513
- context 'with the :in option set to {state: state code}' do
514
- let(:location) { {state: state_code} }
515
- it { expect(result.keys).to eq [state_code] }
516
- end
517
-
518
- context 'with the :in option set to {country: "US", state: state code}' do
519
- let(:location) { {country: 'US', state: state_code} }
520
- it { expect(result.keys).to eq [state_code] }
521
- end
522
- end
523
- end
524
-
525
- describe 'average view duration can be grouped by day' do
526
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
527
- let(:keys) { range.values }
528
-
529
- specify 'with the :by option set to :day' do
530
- average_view_duration = playlist.average_view_duration range.merge by: :day
531
- expect(average_view_duration.keys).to eq range.values
532
- end
533
- end
534
-
535
- describe 'average view duration can be grouped by country' do
536
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
537
-
538
- specify 'with the :by option set to :country' do
539
- duration = playlist.average_view_duration range.merge by: :country
540
- expect(duration.keys).to all(be_a String)
541
- expect(duration.keys.map(&:length).uniq).to eq [2]
542
- expect(duration.values).to all(be_an Integer)
543
- end
544
- end
545
-
546
- describe 'average view duration can be grouped by state' do
547
- let(:range) { {since: ENV['YT_TEST_PARTNER_PLAYLIST_DATE']} }
548
-
549
- specify 'with the :by option set to :state' do
550
- duration = playlist.average_view_duration range.merge by: :state
551
- expect(duration.keys).to all(be_a String)
552
- expect(duration.keys.map(&:length).uniq).to eq [2]
553
- expect(duration.values).to all(be_an Integer)
554
- end
555
- end
556
-
557
- describe 'playlist starts can be retrieved for a single US state' do
558
- let(:state_code) { 'CA' }
559
- let(:result) { playlist.playlist_starts since: date, by: by, in: location }
560
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
561
-
562
- context 'and grouped by day' do
563
- let(:by) { :day }
564
-
565
- context 'with the :in option set to {state: state code}' do
566
- let(:location) { {state: state_code} }
567
- it { expect(result.keys.min).to eq date.to_date }
568
- end
569
-
570
- context 'with the :in option set to {country: "US", state: state code}' do
571
- let(:location) { {country: 'US', state: state_code} }
572
- it { expect(result.keys.min).to eq date.to_date }
573
- end
574
- end
575
-
576
- context 'and grouped by US state' do
577
- let(:by) { :state }
578
-
579
- context 'with the :in option set to {state: state code}' do
580
- let(:location) { {state: state_code} }
581
- it { expect(result.keys).to eq [state_code] }
582
- end
583
-
584
- context 'with the :in option set to {country: "US", state: state code}' do
585
- let(:location) { {country: 'US', state: state_code} }
586
- it { expect(result.keys).to eq [state_code] }
587
- end
588
- end
589
- end
590
-
591
- describe 'playlist starts can be grouped by day' do
592
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
593
- let(:keys) { range.values }
594
-
595
- specify 'with the :by option set to :day' do
596
- playlist_starts = playlist.playlist_starts range.merge by: :day
597
- expect(playlist_starts.keys).to eq range.values
598
- end
599
- end
600
-
601
- describe 'playlist starts can be grouped by country' do
602
- let(:range) { {since: ENV['YT_TEST_PARTNER_PLAYLIST_DATE']} }
603
-
604
- specify 'with the :by option set to :country' do
605
- starts = playlist.playlist_starts range.merge by: :country
606
- expect(starts.keys).to all(be_a String)
607
- expect(starts.keys.map(&:length).uniq).to eq [2]
608
- expect(starts.values).to all(be_an Integer)
609
- end
610
- end
611
-
612
- describe 'playlist starts can be grouped by state' do
613
- let(:range) { {since: ENV['YT_TEST_PARTNER_PLAYLIST_DATE']} }
614
-
615
- specify 'with the :by option set to :state' do
616
- starts = playlist.playlist_starts range.merge by: :state
617
- expect(starts.keys).to all(be_a String)
618
- expect(starts.keys.map(&:length).uniq).to eq [2]
619
- expect(starts.values).to all(be_an Integer)
620
- end
621
- end
622
-
623
- describe 'average time in playlist can be retrieved for a single US state' do
624
- let(:state_code) { 'CA' }
625
- let(:result) { playlist.average_time_in_playlist since: date, by: by, in: location }
626
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
627
-
628
- context 'and grouped by day' do
629
- let(:by) { :day }
630
-
631
- context 'with the :in option set to {state: state code}' do
632
- let(:location) { {state: state_code} }
633
- it { expect(result.keys.min).to eq date.to_date }
634
- end
635
-
636
- context 'with the :in option set to {country: "US", state: state code}' do
637
- let(:location) { {country: 'US', state: state_code} }
638
- it { expect(result.keys.min).to eq date.to_date }
639
- end
640
- end
641
-
642
- context 'and grouped by US state' do
643
- let(:by) { :state }
644
-
645
- context 'with the :in option set to {state: state code}' do
646
- let(:location) { {state: state_code} }
647
- it { expect(result.keys).to eq [state_code] }
648
- end
649
-
650
- context 'with the :in option set to {country: "US", state: state code}' do
651
- let(:location) { {country: 'US', state: state_code} }
652
- it { expect(result.keys).to eq [state_code] }
653
- end
654
- end
655
- end
656
-
657
- describe 'average time in playlist can be grouped by day' do
658
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
659
- let(:keys) { range.values }
660
-
661
- specify 'with the :by option set to :day' do
662
- average_time_in_playlist = playlist.average_time_in_playlist range.merge by: :day
663
- expect(average_time_in_playlist.keys).to eq range.values
664
- end
665
- end
666
-
667
- describe 'average time in playlist can be grouped by country' do
668
- let(:range) { {since: ENV['YT_TEST_PARTNER_PLAYLIST_DATE']} }
669
-
670
- specify 'with the :by option set to :country' do
671
- time = playlist.average_time_in_playlist range.merge by: :country
672
- expect(time.keys).to all(be_a String)
673
- expect(time.keys.map(&:length).uniq).to eq [2]
674
- expect(time.values).to all(be_a Float)
675
- end
676
- end
677
-
678
- describe 'average time in playlist can be grouped by state' do
679
- let(:range) { {since: ENV['YT_TEST_PARTNER_PLAYLIST_DATE']} }
680
-
681
- specify 'with the :by option set to :state' do
682
- time = playlist.average_time_in_playlist range.merge by: :state
683
- expect(time.keys).to all(be_a String)
684
- expect(time.keys.map(&:length).uniq).to eq [2]
685
- expect(time.values).to all(be_a Float)
686
- end
687
- end
688
-
689
- describe 'views per playlists start can be retrieved for a single US state' do
690
- let(:state_code) { 'CA' }
691
- let(:result) { playlist.views_per_playlist_start since: date, by: by, in: location }
692
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
693
-
694
- context 'and grouped by day' do
695
- let(:by) { :day }
696
-
697
- context 'with the :in option set to {state: state code}' do
698
- let(:location) { {state: state_code} }
699
- it { expect(result.keys.min).to eq date.to_date }
700
- end
701
-
702
- context 'with the :in option set to {country: "US", state: state code}' do
703
- let(:location) { {country: 'US', state: state_code} }
704
- it { expect(result.keys.min).to eq date.to_date }
705
- end
706
- end
707
-
708
- context 'and grouped by US state' do
709
- let(:by) { :state }
710
-
711
- context 'with the :in option set to {state: state code}' do
712
- let(:location) { {state: state_code} }
713
- it { expect(result.keys).to eq [state_code] }
714
- end
715
-
716
- context 'with the :in option set to {country: "US", state: state code}' do
717
- let(:location) { {country: 'US', state: state_code} }
718
- it { expect(result.keys).to eq [state_code] }
719
- end
720
- end
721
- end
722
-
723
- describe 'views per playlist start can be grouped by day' do
724
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
725
- let(:keys) { range.values }
726
-
727
- specify 'with the :by option set to :day' do
728
- views_per_playlist_start = playlist.views_per_playlist_start range.merge by: :day
729
- expect(views_per_playlist_start.keys).to eq range.values
730
- end
731
- end
732
-
733
- describe 'views per playlist start can be grouped by country' do
734
- let(:range) { {since: ENV['YT_TEST_PARTNER_PLAYLIST_DATE']} }
735
-
736
- specify 'with the :by option set to :country' do
737
- views = playlist.views_per_playlist_start range.merge by: :country
738
- expect(views.keys).to all(be_a String)
739
- expect(views.keys.map(&:length).uniq).to eq [2]
740
- expect(views.values).to all(be_a Float)
741
- end
742
- end
743
-
744
- describe 'views per playlist start can be grouped by state' do
745
- let(:range) { {since: ENV['YT_TEST_PARTNER_PLAYLIST_DATE']} }
746
-
747
- specify 'with the :by option set to :state' do
748
- views = playlist.views_per_playlist_start range.merge by: :state
749
- expect(views.keys).to all(be_a String)
750
- expect(views.keys.map(&:length).uniq).to eq [2]
751
- expect(views.values).to all(be_a Float)
752
- end
753
- end
754
- end
755
-
756
- context 'not managed by the authenticated Content Owner' do
757
- let(:id) { 'PLbpi6ZahtOH6J5oPGySZcmbRfT7Hyq1sZ' }
758
-
759
- specify 'playlist starts cannot be retrieved' do
760
- expect{playlist.views}.to raise_error Yt::Errors::Forbidden
761
- expect{playlist.playlist_starts}.to raise_error Yt::Errors::Forbidden
762
- expect{playlist.average_time_in_playlist}.to raise_error Yt::Errors::Forbidden
763
- expect{playlist.views_per_playlist_start}.to raise_error Yt::Errors::Forbidden
764
- end
765
- end
766
- end
767
- end