yt 0.22.0 → 0.22.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,6 +22,40 @@ describe Yt::Playlist, :partner do
22
22
  end
23
23
  end
24
24
 
25
+ describe 'views can be retrieved for a single country' do
26
+ let(:country_code) { 'US' }
27
+ let(:views) { playlist.views since: date, by: by, in: location }
28
+ let(:date) { 4.days.ago }
29
+
30
+ context 'and grouped by day' do
31
+ let(:by) { :day }
32
+
33
+ context 'with the :in option set to the country code' do
34
+ let(:location) { country_code }
35
+ it { expect(views.keys.min).to eq date.to_date }
36
+ end
37
+
38
+ context 'with the :in option set to {country: country code}' do
39
+ let(:location) { {country: country_code} }
40
+ it { expect(views.keys.min).to eq date.to_date }
41
+ end
42
+ end
43
+
44
+ context 'and grouped by country' do
45
+ let(:by) { :country }
46
+
47
+ context 'with the :in option set to the country code' do
48
+ let(:location) { country_code }
49
+ it { expect(views.keys).to eq [country_code] }
50
+ end
51
+
52
+ context 'with the :in option set to {country: country code}' do
53
+ let(:location) { {country: country_code} }
54
+ it { expect(views.keys).to eq [country_code] }
55
+ end
56
+ end
57
+ end
58
+
25
59
  describe 'views can be retrieved for a range of days' do
26
60
  let(:date) { 4.days.ago }
27
61
 
@@ -124,6 +158,28 @@ describe Yt::Playlist, :partner do
124
158
  end
125
159
  end
126
160
 
161
+ describe 'views can be grouped by country' do
162
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
163
+
164
+ specify 'with the :by option set to :country' do
165
+ views = playlist.views range.merge by: :country
166
+ expect(views.keys).to all(be_a String)
167
+ expect(views.keys.map(&:length).uniq).to eq [2]
168
+ expect(views.values).to all(be_an Integer)
169
+ end
170
+ end
171
+
172
+ describe 'views can be grouped by state' do
173
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
174
+
175
+ specify 'with the :by option set to :state' do
176
+ views = playlist.views range.merge by: :state
177
+ expect(views.keys).to all(be_a String)
178
+ expect(views.keys.map(&:length).uniq).to eq [2]
179
+ expect(views.values).to all(be_an Integer)
180
+ end
181
+ end
182
+
127
183
  describe 'estimated minutes watched can be retrieved for a specific day' do
128
184
  context 'in which the playlist was viewed' do
129
185
  let(:minutes) { playlist.estimated_minutes_watched_on ENV['YT_TEST_PARTNER_PLAYLIST_DATE']}
@@ -136,6 +192,40 @@ describe Yt::Playlist, :partner do
136
192
  end
137
193
  end
138
194
 
195
+ describe 'estimated minutes watched can be retrieved for a single country' do
196
+ let(:country_code) { 'US' }
197
+ let(:estimated_minutes_watched) { playlist.estimated_minutes_watched since: date, by: by, in: location }
198
+ let(:date) { 4.days.ago }
199
+
200
+ context 'and grouped by day' do
201
+ let(:by) { :day }
202
+
203
+ context 'with the :in option set to the country code' do
204
+ let(:location) { country_code }
205
+ it { expect(estimated_minutes_watched.keys.min).to eq date.to_date }
206
+ end
207
+
208
+ context 'with the :in option set to {country: country code}' do
209
+ let(:location) { {country: country_code} }
210
+ it { expect(estimated_minutes_watched.keys.min).to eq date.to_date }
211
+ end
212
+ end
213
+
214
+ context 'and grouped by country' do
215
+ let(:by) { :country }
216
+
217
+ context 'with the :in option set to the country code' do
218
+ let(:location) { country_code }
219
+ it { expect(estimated_minutes_watched.keys).to eq [country_code] }
220
+ end
221
+
222
+ context 'with the :in option set to {country: country code}' do
223
+ let(:location) { {country: country_code} }
224
+ it { expect(estimated_minutes_watched.keys).to eq [country_code] }
225
+ end
226
+ end
227
+ end
228
+
139
229
  describe 'estimated minutes watched can be retrieved for a range of days' do
140
230
  let(:date) { 4.days.ago }
141
231
 
@@ -238,6 +328,28 @@ describe Yt::Playlist, :partner do
238
328
  end
239
329
  end
240
330
 
331
+ describe 'estimated minutes watched can be grouped by country' do
332
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
333
+
334
+ specify 'with the :by option set to :country' do
335
+ minutes = playlist.estimated_minutes_watched range.merge by: :country
336
+ expect(minutes.keys).to all(be_a String)
337
+ expect(minutes.keys.map(&:length).uniq).to eq [2]
338
+ expect(minutes.values).to all(be_a Float)
339
+ end
340
+ end
341
+
342
+ describe 'estimated minutes watched can be grouped by state' do
343
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
344
+
345
+ specify 'with the :by option set to :state' do
346
+ minutes = playlist.estimated_minutes_watched range.merge by: :state
347
+ expect(minutes.keys).to all(be_a String)
348
+ expect(minutes.keys.map(&:length).uniq).to eq [2]
349
+ expect(minutes.values).to all(be_a Float)
350
+ end
351
+ end
352
+
241
353
  describe 'viewer percentage can be retrieved for a range of days' do
242
354
  let(:viewer_percentage) { playlist.viewer_percentage since: 1.year.ago, until: 10.days.ago}
243
355
  it { expect(viewer_percentage).to be_a Hash }
@@ -301,6 +413,40 @@ describe Yt::Playlist, :partner do
301
413
  end
302
414
  end
303
415
 
416
+ describe 'average view duration can be retrieved for a single country' do
417
+ let(:country_code) { 'US' }
418
+ let(:average_view_duration) { playlist.average_view_duration since: date, by: by, in: location }
419
+ let(:date) { 4.days.ago }
420
+
421
+ context 'and grouped by day' do
422
+ let(:by) { :day }
423
+
424
+ context 'with the :in option set to the country code' do
425
+ let(:location) { country_code }
426
+ it { expect(average_view_duration.keys.min).to eq date.to_date }
427
+ end
428
+
429
+ context 'with the :in option set to {country: country code}' do
430
+ let(:location) { {country: country_code} }
431
+ it { expect(average_view_duration.keys.min).to eq date.to_date }
432
+ end
433
+ end
434
+
435
+ context 'and grouped by country' do
436
+ let(:by) { :country }
437
+
438
+ context 'with the :in option set to the country code' do
439
+ let(:location) { country_code }
440
+ it { expect(average_view_duration.keys).to eq [country_code] }
441
+ end
442
+
443
+ context 'with the :in option set to {country: country code}' do
444
+ let(:location) { {country: country_code} }
445
+ it { expect(average_view_duration.keys).to eq [country_code] }
446
+ end
447
+ end
448
+ end
449
+
304
450
  describe 'average view duration can be retrieved for a range of days' do
305
451
  let(:date) { 4.days.ago }
306
452
 
@@ -346,6 +492,28 @@ describe Yt::Playlist, :partner do
346
492
  end
347
493
  end
348
494
 
495
+ describe 'average view duration can be grouped by country' do
496
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
497
+
498
+ specify 'with the :by option set to :country' do
499
+ duration = playlist.average_view_duration range.merge by: :country
500
+ expect(duration.keys).to all(be_a String)
501
+ expect(duration.keys.map(&:length).uniq).to eq [2]
502
+ expect(duration.values).to all(be_a Float)
503
+ end
504
+ end
505
+
506
+ describe 'average view duration can be grouped by state' do
507
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
508
+
509
+ specify 'with the :by option set to :state' do
510
+ duration = playlist.average_view_duration range.merge by: :state
511
+ expect(duration.keys).to all(be_a String)
512
+ expect(duration.keys.map(&:length).uniq).to eq [2]
513
+ expect(duration.values).to all(be_a Float)
514
+ end
515
+ end
516
+
349
517
  describe 'playlist starts can be retrieved for a specific day' do
350
518
  context 'in which the playlist was viewed' do
351
519
  let(:playlist_starts) { playlist.playlist_starts_on ENV['YT_TEST_PARTNER_PLAYLIST_DATE']}
@@ -358,6 +526,40 @@ describe Yt::Playlist, :partner do
358
526
  end
359
527
  end
360
528
 
529
+ describe 'playlist starts can be retrieved for a single country' do
530
+ let(:country_code) { 'US' }
531
+ let(:playlist_starts) { playlist.playlist_starts since: date, by: by, in: location }
532
+ let(:date) { 4.days.ago }
533
+
534
+ context 'and grouped by day' do
535
+ let(:by) { :day }
536
+
537
+ context 'with the :in option set to the country code' do
538
+ let(:location) { country_code }
539
+ it { expect(playlist_starts.keys.min).to eq date.to_date }
540
+ end
541
+
542
+ context 'with the :in option set to {country: country code}' do
543
+ let(:location) { {country: country_code} }
544
+ it { expect(playlist_starts.keys.min).to eq date.to_date }
545
+ end
546
+ end
547
+
548
+ context 'and grouped by country' do
549
+ let(:by) { :country }
550
+
551
+ context 'with the :in option set to the country code' do
552
+ let(:location) { country_code }
553
+ it { expect(playlist_starts.keys).to eq [country_code] }
554
+ end
555
+
556
+ context 'with the :in option set to {country: country code}' do
557
+ let(:location) { {country: country_code} }
558
+ it { expect(playlist_starts.keys).to eq [country_code] }
559
+ end
560
+ end
561
+ end
562
+
361
563
  describe 'playlist starts can be retrieved for a range of days' do
362
564
  let(:date) { 4.days.ago }
363
565
 
@@ -403,6 +605,28 @@ describe Yt::Playlist, :partner do
403
605
  end
404
606
  end
405
607
 
608
+ describe 'playlist starts can be grouped by country' do
609
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
610
+
611
+ specify 'with the :by option set to :country' do
612
+ starts = playlist.playlist_starts range.merge by: :country
613
+ expect(starts.keys).to all(be_a String)
614
+ expect(starts.keys.map(&:length).uniq).to eq [2]
615
+ expect(starts.values).to all(be_an Integer)
616
+ end
617
+ end
618
+
619
+ describe 'playlist starts can be grouped by state' do
620
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
621
+
622
+ specify 'with the :by option set to :state' do
623
+ starts = playlist.playlist_starts range.merge by: :state
624
+ expect(starts.keys).to all(be_a String)
625
+ expect(starts.keys.map(&:length).uniq).to eq [2]
626
+ expect(starts.values).to all(be_an Integer)
627
+ end
628
+ end
629
+
406
630
  describe 'average time in playlist can be retrieved for a specific day' do
407
631
  context 'in which the playlist was viewed' do
408
632
  let(:average_time_in_playlist) { playlist.average_time_in_playlist_on ENV['YT_TEST_PARTNER_PLAYLIST_DATE']}
@@ -415,6 +639,40 @@ describe Yt::Playlist, :partner do
415
639
  end
416
640
  end
417
641
 
642
+ describe 'average time in playlist can be retrieved for a single country' do
643
+ let(:country_code) { 'US' }
644
+ let(:average_time_in_playlist) { playlist.average_time_in_playlist since: date, by: by, in: location }
645
+ let(:date) { 4.days.ago }
646
+
647
+ context 'and grouped by day' do
648
+ let(:by) { :day }
649
+
650
+ context 'with the :in option set to the country code' do
651
+ let(:location) { country_code }
652
+ it { expect(average_time_in_playlist.keys.min).to eq date.to_date }
653
+ end
654
+
655
+ context 'with the :in option set to {country: country code}' do
656
+ let(:location) { {country: country_code} }
657
+ it { expect(average_time_in_playlist.keys.min).to eq date.to_date }
658
+ end
659
+ end
660
+
661
+ context 'and grouped by country' do
662
+ let(:by) { :country }
663
+
664
+ context 'with the :in option set to the country code' do
665
+ let(:location) { country_code }
666
+ it { expect(average_time_in_playlist.keys).to eq [country_code] }
667
+ end
668
+
669
+ context 'with the :in option set to {country: country code}' do
670
+ let(:location) { {country: country_code} }
671
+ it { expect(average_time_in_playlist.keys).to eq [country_code] }
672
+ end
673
+ end
674
+ end
675
+
418
676
  describe 'average time in playlist can be retrieved for a range of days' do
419
677
  let(:date) { 4.days.ago }
420
678
 
@@ -460,6 +718,28 @@ describe Yt::Playlist, :partner do
460
718
  end
461
719
  end
462
720
 
721
+ describe 'average time in playlist can be grouped by country' do
722
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
723
+
724
+ specify 'with the :by option set to :country' do
725
+ time = playlist.average_time_in_playlist range.merge by: :country
726
+ expect(time.keys).to all(be_a String)
727
+ expect(time.keys.map(&:length).uniq).to eq [2]
728
+ expect(time.values).to all(be_a Float)
729
+ end
730
+ end
731
+
732
+ describe 'average time in playlist can be grouped by state' do
733
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
734
+
735
+ specify 'with the :by option set to :state' do
736
+ time = playlist.average_time_in_playlist range.merge by: :state
737
+ expect(time.keys).to all(be_a String)
738
+ expect(time.keys.map(&:length).uniq).to eq [2]
739
+ expect(time.values).to all(be_a Float)
740
+ end
741
+ end
742
+
463
743
  describe 'views per playlist start can be retrieved for a specific day' do
464
744
  context 'in which the playlist was viewed' do
465
745
  let(:views_per_playlist_start) { playlist.views_per_playlist_start_on ENV['YT_TEST_PARTNER_PLAYLIST_DATE']}
@@ -472,6 +752,40 @@ describe Yt::Playlist, :partner do
472
752
  end
473
753
  end
474
754
 
755
+ describe 'views per playlist start can be retrieved for a single country' do
756
+ let(:country_code) { 'US' }
757
+ let(:views_per_playlist_start) { playlist.views_per_playlist_start since: date, by: by, in: location }
758
+ let(:date) { 4.days.ago }
759
+
760
+ context 'and grouped by day' do
761
+ let(:by) { :day }
762
+
763
+ context 'with the :in option set to the country code' do
764
+ let(:location) { country_code }
765
+ it { expect(views_per_playlist_start.keys.min).to eq date.to_date }
766
+ end
767
+
768
+ context 'with the :in option set to {country: country code}' do
769
+ let(:location) { {country: country_code} }
770
+ it { expect(views_per_playlist_start.keys.min).to eq date.to_date }
771
+ end
772
+ end
773
+
774
+ context 'and grouped by country' do
775
+ let(:by) { :country }
776
+
777
+ context 'with the :in option set to the country code' do
778
+ let(:location) { country_code }
779
+ it { expect(views_per_playlist_start.keys).to eq [country_code] }
780
+ end
781
+
782
+ context 'with the :in option set to {country: country code}' do
783
+ let(:location) { {country: country_code} }
784
+ it { expect(views_per_playlist_start.keys).to eq [country_code] }
785
+ end
786
+ end
787
+ end
788
+
475
789
  describe 'views per playlist start can be retrieved for a range of days' do
476
790
  let(:date) { 4.days.ago }
477
791
 
@@ -516,6 +830,28 @@ describe Yt::Playlist, :partner do
516
830
  expect(views_per_playlist_start.keys).to eq range.values
517
831
  end
518
832
  end
833
+
834
+ describe 'views per playlist start can be grouped by country' do
835
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
836
+
837
+ specify 'with the :by option set to :country' do
838
+ views = playlist.views_per_playlist_start range.merge by: :country
839
+ expect(views.keys).to all(be_a String)
840
+ expect(views.keys.map(&:length).uniq).to eq [2]
841
+ expect(views.values).to all(be_a Float)
842
+ end
843
+ end
844
+
845
+ describe 'views per playlist start can be grouped by state' do
846
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
847
+
848
+ specify 'with the :by option set to :state' do
849
+ views = playlist.views_per_playlist_start range.merge by: :state
850
+ expect(views.keys).to all(be_a String)
851
+ expect(views.keys.map(&:length).uniq).to eq [2]
852
+ expect(views.values).to all(be_a Float)
853
+ end
854
+ end
519
855
  end
520
856
 
521
857
  context 'not managed by the authenticated Content Owner' do
@@ -25,6 +25,40 @@ describe Yt::Video, :partner do
25
25
  end
26
26
  end
27
27
 
28
+ describe 'earnings can be retrieved for a single country' do
29
+ let(:country_code) { 'US' }
30
+ let(:earnings) { video.earnings since: date, by: by, in: location }
31
+ let(:date) { 4.days.ago }
32
+
33
+ context 'and grouped by day' do
34
+ let(:by) { :day }
35
+
36
+ context 'with the :in option set to the country code' do
37
+ let(:location) { country_code }
38
+ it { expect(earnings.keys.min).to eq date.to_date }
39
+ end
40
+
41
+ context 'with the :in option set to {country: country code}' do
42
+ let(:location) { {country: country_code} }
43
+ it { expect(earnings.keys.min).to eq date.to_date }
44
+ end
45
+ end
46
+
47
+ context 'and grouped by country' do
48
+ let(:by) { :country }
49
+
50
+ context 'with the :in option set to the country code' do
51
+ let(:location) { country_code }
52
+ it { expect(earnings.keys).to eq [country_code] }
53
+ end
54
+
55
+ context 'with the :in option set to {country: country code}' do
56
+ let(:location) { {country: country_code} }
57
+ it { expect(earnings.keys).to eq [country_code] }
58
+ end
59
+ end
60
+ end
61
+
28
62
  describe 'earnings can be retrieved for a range of days' do
29
63
  let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
30
64
 
@@ -63,6 +97,17 @@ describe Yt::Video, :partner do
63
97
  end
64
98
  end
65
99
 
100
+ describe 'earnings can be grouped by country' do
101
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
102
+
103
+ specify 'with the :by option set to :country' do
104
+ earnings = video.earnings range.merge by: :country
105
+ expect(earnings.keys).to all(be_a String)
106
+ expect(earnings.keys.map(&:length).uniq).to eq [2]
107
+ expect(earnings.values).to all(be_a Float)
108
+ end
109
+ end
110
+
66
111
  describe 'views can be retrieved for a specific day' do
67
112
  context 'in which the video was partnered' do
68
113
  let(:views) { video.views_on 5.days.ago}
@@ -75,6 +120,41 @@ describe Yt::Video, :partner do
75
120
  end
76
121
  end
77
122
 
123
+
124
+ describe 'views can be retrieved for a single country' do
125
+ let(:country_code) { 'US' }
126
+ let(:views) { video.views since: date, by: by, in: location }
127
+ let(:date) { 4.days.ago }
128
+
129
+ context 'and grouped by day' do
130
+ let(:by) { :day }
131
+
132
+ context 'with the :in option set to the country code' do
133
+ let(:location) { country_code }
134
+ it { expect(views.keys.min).to eq date.to_date }
135
+ end
136
+
137
+ context 'with the :in option set to {country: country code}' do
138
+ let(:location) { {country: country_code} }
139
+ it { expect(views.keys.min).to eq date.to_date }
140
+ end
141
+ end
142
+
143
+ context 'and grouped by country' do
144
+ let(:by) { :country }
145
+
146
+ context 'with the :in option set to the country code' do
147
+ let(:location) { country_code }
148
+ it { expect(views.keys).to eq [country_code] }
149
+ end
150
+
151
+ context 'with the :in option set to {country: country code}' do
152
+ let(:location) { {country: country_code} }
153
+ it { expect(views.keys).to eq [country_code] }
154
+ end
155
+ end
156
+ end
157
+
78
158
  describe 'views can be retrieved for a range of days' do
79
159
  let(:date) { 4.days.ago }
80
160
 
@@ -141,7 +221,7 @@ describe Yt::Video, :partner do
141
221
  end
142
222
 
143
223
  describe 'views can be grouped by embedded player location' do
144
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE'], until: 3.days.ago} }
224
+ let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
145
225
 
146
226
  specify 'with the :by option set to :embedded_player_location' do
147
227
  views = video.views range.merge by: :embedded_player_location
@@ -168,6 +248,28 @@ describe Yt::Video, :partner do
168
248
  end
169
249
  end
170
250
 
251
+ describe 'views can be grouped by country' do
252
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
253
+
254
+ specify 'with the :by option set to :country' do
255
+ views = video.views range.merge by: :country
256
+ expect(views.keys).to all(be_a String)
257
+ expect(views.keys.map(&:length).uniq).to eq [2]
258
+ expect(views.values).to all(be_an Integer)
259
+ end
260
+ end
261
+
262
+ describe 'views can be grouped by state' do
263
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
264
+
265
+ specify 'with the :by option set to :state' do
266
+ views = video.views range.merge by: :state
267
+ expect(views.keys).to all(be_a String)
268
+ expect(views.keys.map(&:length).uniq).to eq [2]
269
+ expect(views.values).to all(be_an Integer)
270
+ end
271
+ end
272
+
171
273
  describe 'comments can be retrieved for a specific day' do
172
274
  context 'in which the video was partnered' do
173
275
  let(:comments) { video.comments_on ENV['YT_TEST_PARTNER_VIDEO_DATE']}
@@ -180,6 +282,41 @@ describe Yt::Video, :partner do
180
282
  end
181
283
  end
182
284
 
285
+
286
+ describe 'comments can be retrieved for a single country' do
287
+ let(:country_code) { 'US' }
288
+ let(:comments) { video.comments since: date, by: by, in: location }
289
+ let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
290
+
291
+ context 'and grouped by day' do
292
+ let(:by) { :day }
293
+
294
+ context 'with the :in option set to the country code' do
295
+ let(:location) { country_code }
296
+ it { expect(comments.keys.min).to eq date.to_date }
297
+ end
298
+
299
+ context 'with the :in option set to {country: country code}' do
300
+ let(:location) { {country: country_code} }
301
+ it { expect(comments.keys.min).to eq date.to_date }
302
+ end
303
+ end
304
+
305
+ context 'and grouped by country' do
306
+ let(:by) { :country }
307
+
308
+ context 'with the :in option set to the country code' do
309
+ let(:location) { country_code }
310
+ it { expect(comments.keys).to eq [country_code] }
311
+ end
312
+
313
+ context 'with the :in option set to {country: country code}' do
314
+ let(:location) { {country: country_code} }
315
+ it { expect(comments.keys).to eq [country_code] }
316
+ end
317
+ end
318
+ end
319
+
183
320
  describe 'comments can be retrieved for a range of days' do
184
321
  let(:date) { 4.days.ago }
185
322
 
@@ -225,6 +362,17 @@ describe Yt::Video, :partner do
225
362
  end
226
363
  end
227
364
 
365
+ describe 'comments can be grouped by country' do
366
+ let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
367
+
368
+ specify 'with the :by option set to :country' do
369
+ comments = video.comments range.merge by: :country
370
+ expect(comments.keys).to all(be_a String)
371
+ expect(comments.keys.map(&:length).uniq).to eq [2]
372
+ expect(comments.values).to all(be_an Integer)
373
+ end
374
+ end
375
+
228
376
  describe 'likes can be retrieved for a specific day' do
229
377
  context 'in which the video was partnered' do
230
378
  let(:likes) { video.likes_on ENV['YT_TEST_PARTNER_VIDEO_DATE']}
@@ -237,6 +385,40 @@ describe Yt::Video, :partner do
237
385
  end
238
386
  end
239
387
 
388
+ describe 'likes can be retrieved for a single country' do
389
+ let(:country_code) { 'US' }
390
+ let(:likes) { video.likes since: date, by: by, in: location }
391
+ let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
392
+
393
+ context 'and grouped by day' do
394
+ let(:by) { :day }
395
+
396
+ context 'with the :in option set to the country code' do
397
+ let(:location) { country_code }
398
+ it { expect(likes.keys.min).to eq date.to_date }
399
+ end
400
+
401
+ context 'with the :in option set to {country: country code}' do
402
+ let(:location) { {country: country_code} }
403
+ it { expect(likes.keys.min).to eq date.to_date }
404
+ end
405
+ end
406
+
407
+ context 'and grouped by country' do
408
+ let(:by) { :country }
409
+
410
+ context 'with the :in option set to the country code' do
411
+ let(:location) { country_code }
412
+ it { expect(likes.keys).to eq [country_code] }
413
+ end
414
+
415
+ context 'with the :in option set to {country: country code}' do
416
+ let(:location) { {country: country_code} }
417
+ it { expect(likes.keys).to eq [country_code] }
418
+ end
419
+ end
420
+ end
421
+
240
422
  describe 'likes can be retrieved for a range of days' do
241
423
  let(:date) { 4.days.ago }
242
424
 
@@ -282,6 +464,17 @@ describe Yt::Video, :partner do
282
464
  end
283
465
  end
284
466
 
467
+ describe 'likes can be grouped by country' do
468
+ let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
469
+
470
+ specify 'with the :by option set to :country' do
471
+ likes = video.likes range.merge by: :country
472
+ expect(likes.keys).to all(be_a String)
473
+ expect(likes.keys.map(&:length).uniq).to eq [2]
474
+ expect(likes.values).to all(be_an Integer)
475
+ end
476
+ end
477
+
285
478
  describe 'dislikes can be retrieved for a specific day' do
286
479
  context 'in which the video was partnered' do
287
480
  let(:dislikes) { video.dislikes_on ENV['YT_TEST_PARTNER_VIDEO_DATE']}
@@ -294,6 +487,40 @@ describe Yt::Video, :partner do
294
487
  end
295
488
  end
296
489
 
490
+ describe 'dislikes can be retrieved for a single country' do
491
+ let(:country_code) { 'US' }
492
+ let(:dislikes) { video.dislikes since: date, by: by, in: location }
493
+ let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
494
+
495
+ context 'and grouped by day' do
496
+ let(:by) { :day }
497
+
498
+ context 'with the :in option set to the country code' do
499
+ let(:location) { country_code }
500
+ it { expect(dislikes.keys.min).to eq date.to_date }
501
+ end
502
+
503
+ context 'with the :in option set to {country: country code}' do
504
+ let(:location) { {country: country_code} }
505
+ it { expect(dislikes.keys.min).to eq date.to_date }
506
+ end
507
+ end
508
+
509
+ context 'and grouped by country' do
510
+ let(:by) { :country }
511
+
512
+ context 'with the :in option set to the country code' do
513
+ let(:location) { country_code }
514
+ it { expect(dislikes.keys).to eq [country_code] }
515
+ end
516
+
517
+ context 'with the :in option set to {country: country code}' do
518
+ let(:location) { {country: country_code} }
519
+ it { expect(dislikes.keys).to eq [country_code] }
520
+ end
521
+ end
522
+ end
523
+
297
524
  describe 'dislikes can be retrieved for a range of days' do
298
525
  let(:date) { 4.days.ago }
299
526
 
@@ -339,9 +566,21 @@ describe Yt::Video, :partner do
339
566
  end
340
567
  end
341
568
 
569
+ describe 'dislikes can be grouped by country' do
570
+ let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
571
+
572
+ specify 'with the :by option set to :country' do
573
+ dislikes = video.dislikes range.merge by: :country
574
+ expect(dislikes.keys).to all(be_a String)
575
+ expect(dislikes.keys.map(&:length).uniq).to eq [2]
576
+ expect(dislikes.values).to all(be_an Integer)
577
+ end
578
+ end
579
+
342
580
  describe 'shares can be retrieved for a specific day' do
343
581
  context 'in which the video was partnered' do
344
- let(:shares) { video.shares_on ENV['YT_TEST_PARTNER_VIDEO_DATE']}
582
+ let(:date) { Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 95 }
583
+ let(:shares) { video.shares_on date }
345
584
  it { expect(shares).to be_an Integer }
346
585
  end
347
586
 
@@ -351,6 +590,40 @@ describe Yt::Video, :partner do
351
590
  end
352
591
  end
353
592
 
593
+ describe 'shares can be retrieved for a single country' do
594
+ let(:country_code) { 'PT' }
595
+ let(:shares) { video.shares since: date, by: by, in: location }
596
+ let(:date) { Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 95 }
597
+
598
+ context 'and grouped by day' do
599
+ let(:by) { :day }
600
+
601
+ context 'with the :in option set to the country code' do
602
+ let(:location) { country_code }
603
+ it { expect(shares.keys.min).to eq date.to_date }
604
+ end
605
+
606
+ context 'with the :in option set to {country: country code}' do
607
+ let(:location) { {country: country_code} }
608
+ it { expect(shares.keys.min).to eq date.to_date }
609
+ end
610
+ end
611
+
612
+ context 'and grouped by country' do
613
+ let(:by) { :country }
614
+
615
+ context 'with the :in option set to the country code' do
616
+ let(:location) { country_code }
617
+ it { expect(shares.keys).to eq [country_code] }
618
+ end
619
+
620
+ context 'with the :in option set to {country: country code}' do
621
+ let(:location) { {country: country_code} }
622
+ it { expect(shares.keys).to eq [country_code] }
623
+ end
624
+ end
625
+ end
626
+
354
627
  describe 'shares can be retrieved for a range of days' do
355
628
  let(:date) { 4.days.ago }
356
629
 
@@ -396,6 +669,17 @@ describe Yt::Video, :partner do
396
669
  end
397
670
  end
398
671
 
672
+ describe 'shares can be grouped by country' do
673
+ let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
674
+
675
+ specify 'with the :by option set to :country' do
676
+ shares = video.shares range.merge by: :country
677
+ expect(shares.keys).to all(be_a String)
678
+ expect(shares.keys.map(&:length).uniq).to eq [2]
679
+ expect(shares.values).to all(be_an Integer)
680
+ end
681
+ end
682
+
399
683
  describe 'gained subscribers can be retrieved for a specific day' do
400
684
  context 'in which the video was partnered' do
401
685
  let(:subscribers_gained) { video.subscribers_gained_on ENV['YT_TEST_PARTNER_VIDEO_DATE']}
@@ -408,6 +692,40 @@ describe Yt::Video, :partner do
408
692
  end
409
693
  end
410
694
 
695
+ describe 'gained subscribers can be retrieved for a single country' do
696
+ let(:country_code) { 'US' }
697
+ let(:subscribers_gained) { video.subscribers_gained since: date, by: by, in: location }
698
+ let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
699
+
700
+ context 'and grouped by day' do
701
+ let(:by) { :day }
702
+
703
+ context 'with the :in option set to the country code' do
704
+ let(:location) { country_code }
705
+ it { expect(subscribers_gained.keys.min).to eq date.to_date }
706
+ end
707
+
708
+ context 'with the :in option set to {country: country code}' do
709
+ let(:location) { {country: country_code} }
710
+ it { expect(subscribers_gained.keys.min).to eq date.to_date }
711
+ end
712
+ end
713
+
714
+ context 'and grouped by country' do
715
+ let(:by) { :country }
716
+
717
+ context 'with the :in option set to the country code' do
718
+ let(:location) { country_code }
719
+ it { expect(subscribers_gained.keys).to eq [country_code] }
720
+ end
721
+
722
+ context 'with the :in option set to {country: country code}' do
723
+ let(:location) { {country: country_code} }
724
+ it { expect(subscribers_gained.keys).to eq [country_code] }
725
+ end
726
+ end
727
+ end
728
+
411
729
  describe 'gained subscribers can be retrieved for a range of days' do
412
730
  let(:date) { 4.days.ago }
413
731
 
@@ -453,6 +771,17 @@ describe Yt::Video, :partner do
453
771
  end
454
772
  end
455
773
 
774
+ describe 'gained subscribers can be grouped by country' do
775
+ let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
776
+
777
+ specify 'with the :by option set to :country' do
778
+ subscribers_gained = video.subscribers_gained range.merge by: :country
779
+ expect(subscribers_gained.keys).to all(be_a String)
780
+ expect(subscribers_gained.keys.map(&:length).uniq).to eq [2]
781
+ expect(subscribers_gained.values).to all(be_an Integer)
782
+ end
783
+ end
784
+
456
785
  describe 'lost subscribers can be retrieved for a specific day' do
457
786
  context 'in which the video was partnered' do
458
787
  let(:subscribers_lost) { video.subscribers_lost_on ENV['YT_TEST_PARTNER_VIDEO_DATE']}
@@ -465,6 +794,40 @@ describe Yt::Video, :partner do
465
794
  end
466
795
  end
467
796
 
797
+ describe 'lost subscribers can be retrieved for a single country' do
798
+ let(:country_code) { 'BR' }
799
+ let(:subscribers_lost) { video.subscribers_lost since: date, by: by, in: location }
800
+ let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
801
+
802
+ context 'and grouped by day' do
803
+ let(:by) { :day }
804
+
805
+ context 'with the :in option set to the country code' do
806
+ let(:location) { country_code }
807
+ it { expect(subscribers_lost.keys.min).to eq date.to_date }
808
+ end
809
+
810
+ context 'with the :in option set to {country: country code}' do
811
+ let(:location) { {country: country_code} }
812
+ it { expect(subscribers_lost.keys.min).to eq date.to_date }
813
+ end
814
+ end
815
+
816
+ context 'and grouped by country' do
817
+ let(:by) { :country }
818
+
819
+ context 'with the :in option set to the country code' do
820
+ let(:location) { country_code }
821
+ it { expect(subscribers_lost.keys).to eq [country_code] }
822
+ end
823
+
824
+ context 'with the :in option set to {country: country code}' do
825
+ let(:location) { {country: country_code} }
826
+ it { expect(subscribers_lost.keys).to eq [country_code] }
827
+ end
828
+ end
829
+ end
830
+
468
831
  describe 'lost subscribers can be retrieved for a range of days' do
469
832
  let(:date) { 4.days.ago }
470
833
 
@@ -510,6 +873,17 @@ describe Yt::Video, :partner do
510
873
  end
511
874
  end
512
875
 
876
+ describe 'lost subscribers can be grouped by country' do
877
+ let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
878
+
879
+ specify 'with the :by option set to :country' do
880
+ subscribers_lost = video.subscribers_lost range.merge by: :country
881
+ expect(subscribers_lost.keys).to all(be_a String)
882
+ expect(subscribers_lost.keys.map(&:length).uniq).to eq [2]
883
+ expect(subscribers_lost.values).to all(be_an Integer)
884
+ end
885
+ end
886
+
513
887
  describe 'added favorites can be retrieved for a specific day' do
514
888
  context 'in which the video was partnered' do
515
889
  let(:favorites_added) { video.favorites_added_on ENV['YT_TEST_PARTNER_VIDEO_DATE']}
@@ -522,6 +896,40 @@ describe Yt::Video, :partner do
522
896
  end
523
897
  end
524
898
 
899
+ describe 'favorites added can be retrieved for a single country' do
900
+ let(:country_code) { 'US' }
901
+ let(:favorites_added) { video.favorites_added since: date, by: by, in: location }
902
+ let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
903
+
904
+ context 'and grouped by day' do
905
+ let(:by) { :day }
906
+
907
+ context 'with the :in option set to the country code' do
908
+ let(:location) { country_code }
909
+ it { expect(favorites_added.keys.min).to eq date.to_date }
910
+ end
911
+
912
+ context 'with the :in option set to {country: country code}' do
913
+ let(:location) { {country: country_code} }
914
+ it { expect(favorites_added.keys.min).to eq date.to_date }
915
+ end
916
+ end
917
+
918
+ context 'and grouped by country' do
919
+ let(:by) { :country }
920
+
921
+ context 'with the :in option set to the country code' do
922
+ let(:location) { country_code }
923
+ it { expect(favorites_added.keys).to eq [country_code] }
924
+ end
925
+
926
+ context 'with the :in option set to {country: country code}' do
927
+ let(:location) { {country: country_code} }
928
+ it { expect(favorites_added.keys).to eq [country_code] }
929
+ end
930
+ end
931
+ end
932
+
525
933
  describe 'added favorites can be retrieved for a range of days' do
526
934
  let(:date) { 4.days.ago }
527
935
 
@@ -567,6 +975,17 @@ describe Yt::Video, :partner do
567
975
  end
568
976
  end
569
977
 
978
+ describe 'added favorites can be grouped by country' do
979
+ let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
980
+
981
+ specify 'with the :by option set to :country' do
982
+ favorites_added = video.favorites_added range.merge by: :country
983
+ expect(favorites_added.keys).to all(be_a String)
984
+ expect(favorites_added.keys.map(&:length).uniq).to eq [2]
985
+ expect(favorites_added.values).to all(be_an Integer)
986
+ end
987
+ end
988
+
570
989
  describe 'removed favorites can be retrieved for a specific day' do
571
990
  context 'in which the video was partnered' do
572
991
  let(:favorites_removed) { video.favorites_removed_on ENV['YT_TEST_PARTNER_VIDEO_DATE']}
@@ -579,6 +998,41 @@ describe Yt::Video, :partner do
579
998
  end
580
999
  end
581
1000
 
1001
+ describe 'favorites removed can be retrieved for a single country' do
1002
+ let(:country_code) { 'US' }
1003
+ let(:favorites_removed) { video.favorites_removed since: date, by: by, in: location }
1004
+ let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
1005
+
1006
+ context 'and grouped by day' do
1007
+ let(:by) { :day }
1008
+
1009
+ context 'with the :in option set to the country code' do
1010
+ let(:location) { country_code }
1011
+ it { expect(favorites_removed.keys.min).to eq date.to_date }
1012
+ end
1013
+
1014
+ context 'with the :in option set to {country: country code}' do
1015
+ let(:location) { {country: country_code} }
1016
+ it { expect(favorites_removed.keys.min).to eq date.to_date }
1017
+ end
1018
+ end
1019
+
1020
+ # TODO: Remove "removed favorites" since it’s deprecated!
1021
+ # context 'and grouped by country' do
1022
+ # let(:by) { :country }
1023
+ #
1024
+ # context 'with the :in option set to the country code' do
1025
+ # let(:location) { country_code }
1026
+ # it { expect(favorites_removed.keys).to eq [country_code] }
1027
+ # end
1028
+ #
1029
+ # context 'with the :in option set to {country: country code}' do
1030
+ # let(:location) { {country: country_code} }
1031
+ # it { expect(favorites_removed.keys).to eq [country_code] }
1032
+ # end
1033
+ # end
1034
+ end
1035
+
582
1036
  describe 'removed favorites can be retrieved for a range of days' do
583
1037
  let(:date) { 4.days.ago }
584
1038
 
@@ -625,6 +1079,18 @@ describe Yt::Video, :partner do
625
1079
  end
626
1080
  end
627
1081
 
1082
+ # TODO: Remove "removed favorites" since it’s deprecated!
1083
+ # describe 'removed favorites can be grouped by country' do
1084
+ # let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
1085
+ #
1086
+ # specify 'with the :by option set to :country' do
1087
+ # favorites_removed = video.favorites_removed range.merge by: :country
1088
+ # expect(favorites_removed.keys).to all(be_a String)
1089
+ # expect(favorites_removed.keys.map(&:length).uniq).to eq [2]
1090
+ # expect(favorites_removed.values).to all(be_an Integer)
1091
+ # end
1092
+ # end
1093
+
628
1094
  describe 'estimated minutes watched can be retrieved for a specific day' do
629
1095
  context 'in which the video was partnered' do
630
1096
  let(:estimated_minutes_watched) { video.estimated_minutes_watched_on 5.days.ago}
@@ -637,6 +1103,40 @@ describe Yt::Video, :partner do
637
1103
  end
638
1104
  end
639
1105
 
1106
+ describe 'estimated minutes watched can be retrieved for a single country' do
1107
+ let(:country_code) { 'US' }
1108
+ let(:estimated_minutes_watched) { video.estimated_minutes_watched since: date, by: by, in: location }
1109
+ let(:date) { 4.days.ago }
1110
+
1111
+ context 'and grouped by day' do
1112
+ let(:by) { :day }
1113
+
1114
+ context 'with the :in option set to the country code' do
1115
+ let(:location) { country_code }
1116
+ it { expect(estimated_minutes_watched.keys.min).to eq date.to_date }
1117
+ end
1118
+
1119
+ context 'with the :in option set to {country: country code}' do
1120
+ let(:location) { {country: country_code} }
1121
+ it { expect(estimated_minutes_watched.keys.min).to eq date.to_date }
1122
+ end
1123
+ end
1124
+
1125
+ context 'and grouped by country' do
1126
+ let(:by) { :country }
1127
+
1128
+ context 'with the :in option set to the country code' do
1129
+ let(:location) { country_code }
1130
+ it { expect(estimated_minutes_watched.keys).to eq [country_code] }
1131
+ end
1132
+
1133
+ context 'with the :in option set to {country: country code}' do
1134
+ let(:location) { {country: country_code} }
1135
+ it { expect(estimated_minutes_watched.keys).to eq [country_code] }
1136
+ end
1137
+ end
1138
+ end
1139
+
640
1140
  describe 'estimated minutes watched can be retrieved for a range of days' do
641
1141
  let(:date) { 4.days.ago }
642
1142
 
@@ -730,6 +1230,28 @@ describe Yt::Video, :partner do
730
1230
  end
731
1231
  end
732
1232
 
1233
+ describe 'estimated minutes watched can be grouped by country' do
1234
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
1235
+
1236
+ specify 'with the :by option set to :country' do
1237
+ minutes = video.estimated_minutes_watched range.merge by: :country
1238
+ expect(minutes.keys).to all(be_a String)
1239
+ expect(minutes.keys.map(&:length).uniq).to eq [2]
1240
+ expect(minutes.values).to all(be_a Float)
1241
+ end
1242
+ end
1243
+
1244
+ describe 'estimated minutes watched can be grouped by state' do
1245
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
1246
+
1247
+ specify 'with the :by option set to :state' do
1248
+ minutes = video.estimated_minutes_watched range.merge by: :state
1249
+ expect(minutes.keys).to all(be_a String)
1250
+ expect(minutes.keys.map(&:length).uniq).to eq [2]
1251
+ expect(minutes.values).to all(be_a Float)
1252
+ end
1253
+ end
1254
+
733
1255
  describe 'average view duration can be retrieved for a specific day' do
734
1256
  context 'in which the video was partnered' do
735
1257
  let(:average_view_duration) { video.average_view_duration_on 5.days.ago}
@@ -742,6 +1264,40 @@ describe Yt::Video, :partner do
742
1264
  end
743
1265
  end
744
1266
 
1267
+ describe 'average view duration can be retrieved for a single country' do
1268
+ let(:country_code) { 'US' }
1269
+ let(:average_view_duration) { video.average_view_duration since: date, by: by, in: location }
1270
+ let(:date) { 4.days.ago }
1271
+
1272
+ context 'and grouped by day' do
1273
+ let(:by) { :day }
1274
+
1275
+ context 'with the :in option set to the country code' do
1276
+ let(:location) { country_code }
1277
+ it { expect(average_view_duration.keys.min).to eq date.to_date }
1278
+ end
1279
+
1280
+ context 'with the :in option set to {country: country code}' do
1281
+ let(:location) { {country: country_code} }
1282
+ it { expect(average_view_duration.keys.min).to eq date.to_date }
1283
+ end
1284
+ end
1285
+
1286
+ context 'and grouped by country' do
1287
+ let(:by) { :country }
1288
+
1289
+ context 'with the :in option set to the country code' do
1290
+ let(:location) { country_code }
1291
+ it { expect(average_view_duration.keys).to eq [country_code] }
1292
+ end
1293
+
1294
+ context 'with the :in option set to {country: country code}' do
1295
+ let(:location) { {country: country_code} }
1296
+ it { expect(average_view_duration.keys).to eq [country_code] }
1297
+ end
1298
+ end
1299
+ end
1300
+
745
1301
  describe 'average view duration can be retrieved for a range of days' do
746
1302
  let(:date) { 4.days.ago }
747
1303
 
@@ -787,6 +1343,28 @@ describe Yt::Video, :partner do
787
1343
  end
788
1344
  end
789
1345
 
1346
+ describe 'average view duration can be grouped by country' do
1347
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
1348
+
1349
+ specify 'with the :by option set to :country' do
1350
+ duration = video.average_view_duration range.merge by: :country
1351
+ expect(duration.keys).to all(be_a String)
1352
+ expect(duration.keys.map(&:length).uniq).to eq [2]
1353
+ expect(duration.values).to all(be_a Float)
1354
+ end
1355
+ end
1356
+
1357
+ describe 'average view duration can be grouped by state' do
1358
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
1359
+
1360
+ specify 'with the :by option set to :state' do
1361
+ duration = video.average_view_duration range.merge by: :state
1362
+ expect(duration.keys).to all(be_a String)
1363
+ expect(duration.keys.map(&:length).uniq).to eq [2]
1364
+ expect(duration.values).to all(be_a Float)
1365
+ end
1366
+ end
1367
+
790
1368
  describe 'average view percentage can be retrieved for a specific day' do
791
1369
  context 'in which the video was partnered' do
792
1370
  let(:average_view_percentage) { video.average_view_percentage_on 5.days.ago}
@@ -799,6 +1377,40 @@ describe Yt::Video, :partner do
799
1377
  end
800
1378
  end
801
1379
 
1380
+ describe 'average view percentage can be retrieved for a single country' do
1381
+ let(:country_code) { 'US' }
1382
+ let(:average_view_percentage) { video.average_view_percentage since: date, by: by, in: location }
1383
+ let(:date) { 4.days.ago }
1384
+
1385
+ context 'and grouped by day' do
1386
+ let(:by) { :day }
1387
+
1388
+ context 'with the :in option set to the country code' do
1389
+ let(:location) { country_code }
1390
+ it { expect(average_view_percentage.keys.min).to eq date.to_date }
1391
+ end
1392
+
1393
+ context 'with the :in option set to {country: country code}' do
1394
+ let(:location) { {country: country_code} }
1395
+ it { expect(average_view_percentage.keys.min).to eq date.to_date }
1396
+ end
1397
+ end
1398
+
1399
+ context 'and grouped by country' do
1400
+ let(:by) { :country }
1401
+
1402
+ context 'with the :in option set to the country code' do
1403
+ let(:location) { country_code }
1404
+ it { expect(average_view_percentage.keys).to eq [country_code] }
1405
+ end
1406
+
1407
+ context 'with the :in option set to {country: country code}' do
1408
+ let(:location) { {country: country_code} }
1409
+ it { expect(average_view_percentage.keys).to eq [country_code] }
1410
+ end
1411
+ end
1412
+ end
1413
+
802
1414
  describe 'average view percentage can be retrieved for a range of days' do
803
1415
  let(:date) { 4.days.ago }
804
1416
 
@@ -844,6 +1456,28 @@ describe Yt::Video, :partner do
844
1456
  end
845
1457
  end
846
1458
 
1459
+ describe 'average view percentage can be grouped by country' do
1460
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
1461
+
1462
+ specify 'with the :by option set to :country' do
1463
+ percentage = video.average_view_percentage range.merge by: :country
1464
+ expect(percentage.keys).to all(be_a String)
1465
+ expect(percentage.keys.map(&:length).uniq).to eq [2]
1466
+ expect(percentage.values).to all(be_a Float)
1467
+ end
1468
+ end
1469
+
1470
+ describe 'average view percentage can be grouped by state' do
1471
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
1472
+
1473
+ specify 'with the :by option set to :state' do
1474
+ percentage = video.average_view_percentage range.merge by: :state
1475
+ expect(percentage.keys).to all(be_a String)
1476
+ expect(percentage.keys.map(&:length).uniq).to eq [2]
1477
+ expect(percentage.values).to all(be_a Float)
1478
+ end
1479
+ end
1480
+
847
1481
  describe 'impressions can be retrieved for a specific day' do
848
1482
  context 'in which the video was partnered' do
849
1483
  let(:impressions) { video.impressions_on ENV['YT_TEST_PARTNER_VIDEO_DATE']}
@@ -856,6 +1490,40 @@ describe Yt::Video, :partner do
856
1490
  end
857
1491
  end
858
1492
 
1493
+ describe 'impressions can be retrieved for a single country' do
1494
+ let(:country_code) { 'US' }
1495
+ let(:impressions) { video.impressions since: date, by: by, in: location }
1496
+ let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
1497
+
1498
+ context 'and grouped by day' do
1499
+ let(:by) { :day }
1500
+
1501
+ context 'with the :in option set to the country code' do
1502
+ let(:location) { country_code }
1503
+ it { expect(impressions.keys.min).to eq date.to_date }
1504
+ end
1505
+
1506
+ context 'with the :in option set to {country: country code}' do
1507
+ let(:location) { {country: country_code} }
1508
+ it { expect(impressions.keys.min).to eq date.to_date }
1509
+ end
1510
+ end
1511
+
1512
+ context 'and grouped by country' do
1513
+ let(:by) { :country }
1514
+
1515
+ context 'with the :in option set to the country code' do
1516
+ let(:location) { country_code }
1517
+ it { expect(impressions.keys).to eq [country_code] }
1518
+ end
1519
+
1520
+ context 'with the :in option set to {country: country code}' do
1521
+ let(:location) { {country: country_code} }
1522
+ it { expect(impressions.keys).to eq [country_code] }
1523
+ end
1524
+ end
1525
+ end
1526
+
859
1527
  describe 'impressions can be retrieved for a range of days' do
860
1528
  let(:date) { 4.days.ago }
861
1529
 
@@ -901,6 +1569,17 @@ describe Yt::Video, :partner do
901
1569
  end
902
1570
  end
903
1571
 
1572
+ describe 'impressions can be grouped by country' do
1573
+ let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
1574
+
1575
+ specify 'with the :by option set to :country' do
1576
+ impressions = video.impressions range.merge by: :country
1577
+ expect(impressions.keys).to all(be_a String)
1578
+ expect(impressions.keys.map(&:length).uniq).to eq [2]
1579
+ expect(impressions.values).to all(be_an Integer)
1580
+ end
1581
+ end
1582
+
904
1583
  describe 'monetized playbacks can be retrieved for a specific day' do
905
1584
  context 'in which the video was partnered' do
906
1585
  let(:monetized_playbacks) { video.monetized_playbacks_on ENV['YT_TEST_PARTNER_VIDEO_DATE']}
@@ -913,6 +1592,40 @@ describe Yt::Video, :partner do
913
1592
  end
914
1593
  end
915
1594
 
1595
+ describe 'monetized playbacks can be retrieved for a single country' do
1596
+ let(:country_code) { 'US' }
1597
+ let(:monetized_playbacks) { video.monetized_playbacks since: date, by: by, in: location }
1598
+ let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
1599
+
1600
+ context 'and grouped by day' do
1601
+ let(:by) { :day }
1602
+
1603
+ context 'with the :in option set to the country code' do
1604
+ let(:location) { country_code }
1605
+ it { expect(monetized_playbacks.keys.min).to eq date.to_date }
1606
+ end
1607
+
1608
+ context 'with the :in option set to {country: country code}' do
1609
+ let(:location) { {country: country_code} }
1610
+ it { expect(monetized_playbacks.keys.min).to eq date.to_date }
1611
+ end
1612
+ end
1613
+
1614
+ context 'and grouped by country' do
1615
+ let(:by) { :country }
1616
+
1617
+ context 'with the :in option set to the country code' do
1618
+ let(:location) { country_code }
1619
+ it { expect(monetized_playbacks.keys).to eq [country_code] }
1620
+ end
1621
+
1622
+ context 'with the :in option set to {country: country code}' do
1623
+ let(:location) { {country: country_code} }
1624
+ it { expect(monetized_playbacks.keys).to eq [country_code] }
1625
+ end
1626
+ end
1627
+ end
1628
+
916
1629
  describe 'monetized playbacks can be retrieved for a range of days' do
917
1630
  let(:date) { 4.days.ago }
918
1631
 
@@ -958,6 +1671,17 @@ describe Yt::Video, :partner do
958
1671
  end
959
1672
  end
960
1673
 
1674
+ describe 'monetized playbacks can be grouped by country' do
1675
+ let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
1676
+
1677
+ specify 'with the :by option set to :country' do
1678
+ playbacks = video.monetized_playbacks range.merge by: :country
1679
+ expect(playbacks.keys).to all(be_a String)
1680
+ expect(playbacks.keys.map(&:length).uniq).to eq [2]
1681
+ expect(playbacks.values).to all(be_an Integer)
1682
+ end
1683
+ end
1684
+
961
1685
  describe 'annotation clicks can be retrieved for a range of days' do
962
1686
  let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
963
1687
  let(:date_to) { Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 5 }
@@ -995,6 +1719,28 @@ describe Yt::Video, :partner do
995
1719
  end
996
1720
  end
997
1721
 
1722
+ describe 'annotation clicks can be grouped by country' do
1723
+ let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
1724
+
1725
+ specify 'with the :by option set to :country' do
1726
+ clicks = video.annotation_clicks range.merge by: :country
1727
+ expect(clicks.keys).to all(be_a String)
1728
+ expect(clicks.keys.map(&:length).uniq).to eq [2]
1729
+ expect(clicks.values).to all(be_an Integer)
1730
+ end
1731
+ end
1732
+
1733
+ describe 'annotation clicks can be grouped by state' do
1734
+ let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
1735
+
1736
+ specify 'with the :by option set to :state' do
1737
+ clicks = video.annotation_clicks range.merge by: :state
1738
+ expect(clicks.keys).to all(be_a String)
1739
+ expect(clicks.keys.map(&:length).uniq).to eq [2]
1740
+ expect(clicks.values).to all(be_an Integer)
1741
+ end
1742
+ end
1743
+
998
1744
  describe 'annotation click-through rate can be retrieved for a range of days' do
999
1745
  let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
1000
1746
  let(:date_to) { Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 5 }
@@ -1032,6 +1778,28 @@ describe Yt::Video, :partner do
1032
1778
  end
1033
1779
  end
1034
1780
 
1781
+ describe 'annotation click-through rate can be grouped by country' do
1782
+ let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
1783
+
1784
+ specify 'with the :by option set to :country' do
1785
+ rate = video.annotation_click_through_rate range.merge by: :country
1786
+ expect(rate.keys).to all(be_a String)
1787
+ expect(rate.keys.map(&:length).uniq).to eq [2]
1788
+ expect(rate.values).to all(be_a Float)
1789
+ end
1790
+ end
1791
+
1792
+ describe 'annotation click-through rate can be grouped by state' do
1793
+ let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
1794
+
1795
+ specify 'with the :by option set to :state' do
1796
+ rate = video.annotation_click_through_rate range.merge by: :state
1797
+ expect(rate.keys).to all(be_a String)
1798
+ expect(rate.keys.map(&:length).uniq).to eq [2]
1799
+ expect(rate.values).to all(be_a Float)
1800
+ end
1801
+ end
1802
+
1035
1803
  describe 'annotation close rate can be retrieved for a range of days' do
1036
1804
  let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
1037
1805
  let(:date_to) { Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 5 }
@@ -1069,6 +1837,28 @@ describe Yt::Video, :partner do
1069
1837
  end
1070
1838
  end
1071
1839
 
1840
+ describe 'annotation close rate can be grouped by country' do
1841
+ let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
1842
+
1843
+ specify 'with the :by option set to :country' do
1844
+ rate = video.annotation_close_rate range.merge by: :country
1845
+ expect(rate.keys).to all(be_a String)
1846
+ expect(rate.keys.map(&:length).uniq).to eq [2]
1847
+ expect(rate.values).to all(be_a Float)
1848
+ end
1849
+ end
1850
+
1851
+ describe 'annotation close rate can be grouped by state' do
1852
+ let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
1853
+
1854
+ specify 'with the :by option set to :state' do
1855
+ rate = video.annotation_close_rate range.merge by: :state
1856
+ expect(rate.keys).to all(be_a String)
1857
+ expect(rate.keys.map(&:length).uniq).to eq [2]
1858
+ expect(rate.values).to all(be_a Float)
1859
+ end
1860
+ end
1861
+
1072
1862
  describe 'viewer percentage can be retrieved for a range of days' do
1073
1863
  let(:viewer_percentage) { video.viewer_percentage since: 1.year.ago, until: 10.days.ago}
1074
1864
  it { expect(viewer_percentage).to be_a Hash }