yt 0.13.12 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61bf48f535309263dd745a133cb3d41c05eb93a2
4
- data.tar.gz: 63bc4f48576730c827894c59b5884067dcac9295
3
+ metadata.gz: 4e12f9ef5c2b615833df8d63a3a821aadd397a3b
4
+ data.tar.gz: e79d293fdbaaeaf10c2c6bc5fc594363e31909a2
5
5
  SHA512:
6
- metadata.gz: b627fd0536a0c09944fb73766d272a7c961dc271cc42aad92cd0a8748a33085e8f52aa5b54d096bdd39e0920ee59d77930b8c311b84aa53ff0c0a8b8961db7e1
7
- data.tar.gz: a27c7014ed9d101d8305456edf31764145827b680cfabcc00c8841451fe73240e77d2e0160ba25342575d87ef88c6126a2b337f1de69c3b49812b451d5bffa4b
6
+ metadata.gz: 8c2d5f5ff6825b5f844903ffec97c794c40b75d44489736b9ba8116d838adceadff3fff0fad0d8f641937c76c27476ed5e322f5e232119483d486420bb60e3c4
7
+ data.tar.gz: d44fc9bcb26d18178da67a651419ca69e3be7bce825cedfc68b22dc2b996b84728b9cf483e152da2947db6a2c4b6ce1691201b443a2675d7bdd6bac2cfad6d6a
@@ -6,6 +6,11 @@ For more information about changelogs, check
6
6
  [Keep a Changelog](http://keepachangelog.com) and
7
7
  [Vandamme](http://tech-angels.github.io/vandamme).
8
8
 
9
+ ## 0.14.0 - 2015-03-25
10
+
11
+ * [FEATURE] New `by: :traffic_source` option for reports, to return views (channels/videos) and estimated watched minutes (channels) by traffic source.
12
+ * [FEATURE] New `by: :video` option for reports, to return views and estimated watched minutes (channels) by video.
13
+
9
14
  ## 0.13.12 - 2015-03-23
10
15
 
11
16
  * [FEATURE] New channel/video reports: `favorites_added`, `favorites_removed`.
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
+ gem 'pry'
3
+ gem 'pry-nav'
2
4
 
3
5
  # Specify your gem's dependencies in yt.gemspec
4
6
  gemspec
data/README.md CHANGED
@@ -148,7 +148,8 @@ Use [Yt::Channel](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Models/Chan
148
148
  * access the channels that the channel is subscribed to
149
149
  * subscribe to and unsubscribe from a channel
150
150
  * delete playlists from a channel
151
- * retrieve the daily earnings, views, comments, likes, dislikes, shares, subscribers gained/lost, estimated/average video watch and impressions of a channel
151
+ * retrieve the daily earnings, views, comments, likes, dislikes, shares, subscribers gained/lost, estimated/average video watch and impressions of a channel by day
152
+ * retrieve the views and estimated minutes watched by traffic source
152
153
  * retrieve the viewer percentage of a channel by gender and age group
153
154
 
154
155
  ```ruby
@@ -210,6 +211,9 @@ channel.average_view_duration #=> {Sun, 22 Feb 2015=>329.0, Mon, 23 Feb 2015=>3
210
211
  channel.average_view_percentage # {Sun, 22 Feb 2015=>38.858253094977265, Mon, 23 Feb 2015=>37.40014235438217, …}
211
212
  channel.viewer_percentages #=> {female: {'18-24' => 12.12, '25-34' => 16.16,…}…}
212
213
  channel.viewer_percentage(gender: :male) #=> 49.12
214
+
215
+ channel.views since: 7.days.ago, by: :traffic_source #=> {advertising: 10.0, related_video: 20.0, promoted: 5.0, subscriber: 1.0, channel: 3.0, other: 7.0}
216
+ channel.estimated_minutes_watched since: 7.days.ago, by: :traffic_source #=> {annotation: 10.0, external_app: 20.0, external_url: 5.0, embedded: 1.0, search: 3.0}
213
217
  ```
214
218
 
215
219
  *The methods above require to be authenticated as the channel’s account (see below).*
@@ -232,6 +236,8 @@ channel.average_view_duration #=> {Sun, 22 Feb 2015=>329.0, Mon, 23 Feb 2015=>3
232
236
  channel.average_view_percentage # {Sun, 22 Feb 2015=>38.858253094977265, Mon, 23 Feb 2015=>37.40014235438217, …}
233
237
  channel.viewer_percentages #=> {female: {'18-24' => 12.12, '25-34' => 16.16,…}…}
234
238
  channel.viewer_percentage(gender: :female) #=> 49.12
239
+ channel.views since: 7.days.ago, by: :traffic_source #=> {advertising: 10.0, related_video: 20.0, promoted: 5.0, subscriber: 1.0, channel: 3.0, other: 7.0}
240
+ channel.estimated_minutes_watched since: 7.days.ago, by: :traffic_source #=> {annotation: 10.0, external_app: 20.0, external_url: 5.0, embedded: 1.0, search: 3.0}
235
241
 
236
242
  channel.content_owner #=> 'CMSname'
237
243
  channel.linked_at #=> Wed, 28 May 2014
@@ -250,7 +256,8 @@ Use [Yt::Video](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Models/Video)
250
256
  * access the annotations of a video
251
257
  * delete a video
252
258
  * like and dislike a video
253
- * retrieve the daily earnings, views, comments, likes, dislikes, shares, subscribers gained/lost, impressions and monetized playbacks of a video
259
+ * retrieve the daily earnings, views, comments, likes, dislikes, shares, subscribers gained/lost, impressions and monetized playbacks of a video by day
260
+ * retrieve the views of a video by traffic source
254
261
  * retrieve the viewer percentage of a video by gender and age group
255
262
  * retrieve data about live-streaming videos
256
263
  * retrieve the advertising options of a video
@@ -346,6 +353,8 @@ video.subscribers_lost from: '2014-08-30', to: '2014-08-31' #=> {Sat, 30 Aug 201
346
353
  video.viewer_percentages #=> {female: {'18-24' => 12.12, '25-34' => 16.16,…}…}
347
354
  video.viewer_percentage(gender: :female) #=> 49.12
348
355
 
356
+ video.views since: 7.days.ago, by: :traffic_source #=> {advertising: 10.0, related_video: 20.0, promoted: 5.0, subscriber: 1.0, channel: 3.0, other: 7.0}
357
+
349
358
  video.delete #=> true
350
359
  ```
351
360
 
@@ -369,6 +378,8 @@ video.monetized_playbacks_on 5.days.ago #=> 123.0
369
378
  video.viewer_percentages #=> {female: {'18-24' => 12.12, '25-34' => 16.16,…}…}
370
379
  video.viewer_percentage(gender: :female) #=> 49.12
371
380
 
381
+ video.views since: 7.days.ago, by: :traffic_source #=> {advertising: 10.0, related_video: 20.0, promoted: 5.0, subscriber: 1.0, channel: 3.0, other: 7.0}
382
+
372
383
  video.ad_formats #=> ["standard_instream", "trueview_instream"]
373
384
  ```
374
385
 
@@ -46,21 +46,27 @@ module Yt
46
46
  from = options[:since] || options[:from] || 5.days.ago
47
47
  to = options[:until] || options[:to] || 1.day.ago
48
48
  range = Range.new *[from, to].map(&:to_date)
49
+ dimension = options[:by] || :day
49
50
 
50
- ivar = instance_variable_get "@#{metric}"
51
- instance_variable_set "@#{metric}", ivar || {}
51
+ ivar = instance_variable_get "@#{metric}_#{dimension}"
52
+ instance_variable_set "@#{metric}_#{dimension}", ivar || {}
52
53
 
53
- Hash[*range.flat_map do |date|
54
- [date, instance_variable_get("@#{metric}")[date] ||= send("range_#{metric}", range)[date]]
55
- end]
54
+ case dimension
55
+ when :day
56
+ Hash[*range.flat_map do |date|
57
+ [date, instance_variable_get("@#{metric}_#{dimension}")[date] ||= send("range_#{metric}", range, dimension)[date]]
58
+ end]
59
+ else
60
+ instance_variable_get("@#{metric}_#{dimension}")[range] ||= send("range_#{metric}", range, dimension)
61
+ end
56
62
  end
57
63
  end
58
64
 
59
65
  def define_range_metric_method(metric)
60
- define_method "range_#{metric}" do |date_range|
61
- ivar = instance_variable_get "@range_#{metric}"
62
- instance_variable_set "@range_#{metric}", ivar || {}
63
- instance_variable_get("@range_#{metric}")[date_range] ||= send("all_#{metric}").within date_range
66
+ define_method "range_#{metric}" do |date_range, dimension|
67
+ ivar = instance_variable_get "@range_#{metric}_#{dimension}"
68
+ instance_variable_set "@range_#{metric}_#{dimension}", ivar || {}
69
+ instance_variable_get("@range_#{metric}_#{dimension}")[date_range] ||= send("all_#{metric}").within date_range, dimension
64
70
  end
65
71
  private "range_#{metric}"
66
72
  end
@@ -3,10 +3,34 @@ require 'yt/collections/base'
3
3
  module Yt
4
4
  module Collections
5
5
  class Reports < Base
6
+ DIMENSIONS = Hash.new({name: 'day', parse: -> (day) {Date.iso8601 day} }).tap do |hash|
7
+ hash[:traffic_source] = {name: 'insightTrafficSourceType', parse: -> (type) {TRAFFIC_SOURCES.key type} }
8
+ hash[:video] = {name: 'video', parse: -> (video_id) { Yt::Video.new id: video_id, auth: @auth } }
9
+ end
10
+
11
+ # @see https://developers.google.com/youtube/analytics/v1/dimsmets/dims#Traffic_Source_Dimensions
12
+ # @note EXT_APP is also returned but it’s not in the documentation above!
13
+ TRAFFIC_SOURCES = {
14
+ advertising: 'ADVERTISING',
15
+ annotation: 'ANNOTATION',
16
+ external_app: 'EXT_APP',
17
+ external_url: 'EXT_URL',
18
+ embedded: 'NO_LINK_EMBEDDED',
19
+ other: 'NO_LINK_OTHER',
20
+ playlist: 'PLAYLIST',
21
+ promoted: 'PROMOTED',
22
+ related_video: 'RELATED_VIDEO',
23
+ subscriber: 'SUBSCRIBER',
24
+ channel: 'YT_CHANNEL',
25
+ other_page: 'YT_OTHER_PAGE',
26
+ search: 'YT_SEARCH',
27
+ }
28
+
6
29
  attr_writer :metric
7
30
 
8
- def within(days_range, try_again = true)
31
+ def within(days_range, dimension, try_again = true)
9
32
  @days_range = days_range
33
+ @dimension = dimension
10
34
  Hash[*flat_map{|daily_value| daily_value}]
11
35
  # NOTE: Once in a while, YouTube responds with 400 Error and the message
12
36
  # "Invalid query. Query did not conform to the expectations."; in this
@@ -15,13 +39,13 @@ module Yt
15
39
  # same query is a workaround that works and can hardly cause any damage.
16
40
  # Similarly, once in while YouTube responds with a random 503 error.
17
41
  rescue Yt::Error => e
18
- try_again && rescue?(e) ? sleep(3) && within(days_range, false) : raise
42
+ try_again && rescue?(e) ? sleep(3) && within(days_range, dimension, false) : raise
19
43
  end
20
44
 
21
45
  private
22
46
 
23
47
  def new_item(data)
24
- [day_of(data), value_of(data)]
48
+ [instance_exec(data.first, &DIMENSIONS[@dimension][:parse]), data.last]
25
49
  end
26
50
 
27
51
  # @see https://developers.google.com/youtube/analytics/v1/content_owner_reports
@@ -38,20 +62,12 @@ module Yt
38
62
  params['start-date'] = @days_range.begin
39
63
  params['end-date'] = @days_range.end
40
64
  params['metrics'] = @metric.to_s.camelize(:lower)
41
- params['dimensions'] = :day
65
+ params['dimensions'] = DIMENSIONS[@dimension][:name]
66
+ params['max-results'] = 10 if @dimension == :video
67
+ params['sort'] = "-#{@metric.to_s.camelize(:lower)}" if @dimension == :video
42
68
  end
43
69
  end
44
70
 
45
- def day_of(data)
46
- # NOTE: could use column headers to be more precise
47
- Date.iso8601 data.first
48
- end
49
-
50
- def value_of(data)
51
- # NOTE: could use column headers to be more precise
52
- data.last
53
- end
54
-
55
71
  def items_key
56
72
  'rows'
57
73
  end
@@ -1,3 +1,3 @@
1
1
  module Yt
2
- VERSION = '0.13.12'
2
+ VERSION = '0.14.0'
3
3
  end
@@ -86,6 +86,40 @@ describe Yt::Channel, :partner do
86
86
  end
87
87
  end
88
88
 
89
+ describe 'views can be grouped by day' do
90
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
91
+ let(:keys) { range.values }
92
+
93
+ specify 'without a :by option (default)' do
94
+ views = channel.views range
95
+ expect(views.keys).to eq range.values
96
+ end
97
+
98
+ specify 'with the :by option set to :day' do
99
+ views = channel.views range.merge by: :day
100
+ expect(views.keys).to eq range.values
101
+ end
102
+ end
103
+
104
+ describe 'views can be grouped by traffic source' do
105
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
106
+ let(:keys) { Yt::Collections::Reports::TRAFFIC_SOURCES.keys }
107
+
108
+ specify 'with the :by option set to :traffic_source' do
109
+ views = channel.views range.merge by: :traffic_source
110
+ expect(views.keys - keys).to be_empty
111
+ end
112
+ end
113
+
114
+ describe 'views can be grouped by video' do
115
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
116
+
117
+ specify 'with the :by option set to :video' do
118
+ views = channel.views range.merge by: :video
119
+ expect(views.keys).to all(be_instance_of Yt::Video)
120
+ end
121
+ end
122
+
89
123
  describe 'comments can be retrieved for a specific day' do
90
124
  context 'in which the channel was partnered' do
91
125
  let(:comments) { channel.comments_on 5.days.ago}
@@ -118,6 +152,21 @@ describe Yt::Channel, :partner do
118
152
  end
119
153
  end
120
154
 
155
+ describe 'comments can be grouped by day' do
156
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
157
+ let(:keys) { range.values }
158
+
159
+ specify 'without a :by option (default)' do
160
+ comments = channel.comments range
161
+ expect(comments.keys).to eq range.values
162
+ end
163
+
164
+ specify 'with the :by option set to :day' do
165
+ comments = channel.comments range.merge by: :day
166
+ expect(comments.keys).to eq range.values
167
+ end
168
+ end
169
+
121
170
  describe 'likes can be retrieved for a specific day' do
122
171
  context 'in which the channel was partnered' do
123
172
  let(:likes) { channel.likes_on 5.days.ago}
@@ -150,6 +199,21 @@ describe Yt::Channel, :partner do
150
199
  end
151
200
  end
152
201
 
202
+ describe 'likes can be grouped by day' do
203
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
204
+ let(:keys) { range.values }
205
+
206
+ specify 'without a :by option (default)' do
207
+ likes = channel.likes range
208
+ expect(likes.keys).to eq range.values
209
+ end
210
+
211
+ specify 'with the :by option set to :day' do
212
+ likes = channel.likes range.merge by: :day
213
+ expect(likes.keys).to eq range.values
214
+ end
215
+ end
216
+
153
217
  describe 'dislikes can be retrieved for a specific day' do
154
218
  context 'in which the channel was partnered' do
155
219
  let(:dislikes) { channel.dislikes_on 5.days.ago}
@@ -182,6 +246,21 @@ describe Yt::Channel, :partner do
182
246
  end
183
247
  end
184
248
 
249
+ describe 'dislikes can be grouped by day' do
250
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
251
+ let(:keys) { range.values }
252
+
253
+ specify 'without a :by option (default)' do
254
+ dislikes = channel.dislikes range
255
+ expect(dislikes.keys).to eq range.values
256
+ end
257
+
258
+ specify 'with the :by option set to :day' do
259
+ dislikes = channel.dislikes range.merge by: :day
260
+ expect(dislikes.keys).to eq range.values
261
+ end
262
+ end
263
+
185
264
  describe 'shares can be retrieved for a specific day' do
186
265
  context 'in which the channel was partnered' do
187
266
  let(:shares) { channel.shares_on 5.days.ago}
@@ -214,6 +293,21 @@ describe Yt::Channel, :partner do
214
293
  end
215
294
  end
216
295
 
296
+ describe 'shares can be grouped by day' do
297
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
298
+ let(:keys) { range.values }
299
+
300
+ specify 'without a :by option (default)' do
301
+ shares = channel.shares range
302
+ expect(shares.keys).to eq range.values
303
+ end
304
+
305
+ specify 'with the :by option set to :day' do
306
+ shares = channel.shares range.merge by: :day
307
+ expect(shares.keys).to eq range.values
308
+ end
309
+ end
310
+
217
311
  describe 'gained subscribers can be retrieved for a specific day' do
218
312
  context 'in which the channel was partnered' do
219
313
  let(:subscribers_gained) { channel.subscribers_gained_on 5.days.ago}
@@ -246,6 +340,21 @@ describe Yt::Channel, :partner do
246
340
  end
247
341
  end
248
342
 
343
+ describe 'gained subscribers can be grouped by day' do
344
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
345
+ let(:keys) { range.values }
346
+
347
+ specify 'without a :by option (default)' do
348
+ subscribers_gained = channel.subscribers_gained range
349
+ expect(subscribers_gained.keys).to eq range.values
350
+ end
351
+
352
+ specify 'with the :by option set to :day' do
353
+ subscribers_gained = channel.subscribers_gained range.merge by: :day
354
+ expect(subscribers_gained.keys).to eq range.values
355
+ end
356
+ end
357
+
249
358
  describe 'lost subscribers can be retrieved for a specific day' do
250
359
  context 'in which the channel was partnered' do
251
360
  let(:subscribers_lost) { channel.subscribers_lost_on 5.days.ago}
@@ -278,6 +387,21 @@ describe Yt::Channel, :partner do
278
387
  end
279
388
  end
280
389
 
390
+ describe 'lost subscribers can be grouped by day' do
391
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
392
+ let(:keys) { range.values }
393
+
394
+ specify 'without a :by option (default)' do
395
+ subscribers_lost = channel.subscribers_lost range
396
+ expect(subscribers_lost.keys).to eq range.values
397
+ end
398
+
399
+ specify 'with the :by option set to :day' do
400
+ subscribers_lost = channel.subscribers_lost range.merge by: :day
401
+ expect(subscribers_lost.keys).to eq range.values
402
+ end
403
+ end
404
+
281
405
  describe 'added favorites can be retrieved for a specific day' do
282
406
  context 'in which the channel was partnered' do
283
407
  let(:favorites_added) { channel.favorites_added_on 5.days.ago}
@@ -310,6 +434,21 @@ describe Yt::Channel, :partner do
310
434
  end
311
435
  end
312
436
 
437
+ describe 'added favorites can be grouped by day' do
438
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
439
+ let(:keys) { range.values }
440
+
441
+ specify 'without a :by option (default)' do
442
+ favorites_added = channel.favorites_added range
443
+ expect(favorites_added.keys).to eq range.values
444
+ end
445
+
446
+ specify 'with the :by option set to :day' do
447
+ favorites_added = channel.favorites_added range.merge by: :day
448
+ expect(favorites_added.keys).to eq range.values
449
+ end
450
+ end
451
+
313
452
  describe 'removed favorites can be retrieved for a specific day' do
314
453
  context 'in which the channel was partnered' do
315
454
  let(:favorites_removed) { channel.favorites_removed_on 5.days.ago}
@@ -342,6 +481,21 @@ describe Yt::Channel, :partner do
342
481
  end
343
482
  end
344
483
 
484
+ describe 'removed favorites can be grouped by day' do
485
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
486
+ let(:keys) { range.values }
487
+
488
+ specify 'without a :by option (default)' do
489
+ favorites_removed = channel.favorites_removed range
490
+ expect(favorites_removed.keys).to eq range.values
491
+ end
492
+
493
+ specify 'with the :by option set to :day' do
494
+ favorites_removed = channel.favorites_removed range.merge by: :day
495
+ expect(favorites_removed.keys).to eq range.values
496
+ end
497
+ end
498
+
345
499
  describe 'estimated minutes watched can be retrieved for a specific day' do
346
500
  context 'in which the channel was partnered' do
347
501
  let(:estimated_minutes_watched) { channel.estimated_minutes_watched_on 5.days.ago}
@@ -374,6 +528,40 @@ describe Yt::Channel, :partner do
374
528
  end
375
529
  end
376
530
 
531
+ describe 'estimated minutes watched can be grouped by day' do
532
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
533
+ let(:keys) { range.values }
534
+
535
+ specify 'without a :by option (default)' do
536
+ estimated_minutes_watched = channel.estimated_minutes_watched range
537
+ expect(estimated_minutes_watched.keys).to eq range.values
538
+ end
539
+
540
+ specify 'with the :by option set to :day' do
541
+ estimated_minutes_watched = channel.estimated_minutes_watched range.merge by: :day
542
+ expect(estimated_minutes_watched.keys).to eq range.values
543
+ end
544
+ end
545
+
546
+ describe 'estimated minutes watched can be grouped by traffic source' do
547
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
548
+ let(:keys) { Yt::Collections::Reports::TRAFFIC_SOURCES.keys }
549
+
550
+ specify 'with the :by option set to :traffic_source' do
551
+ estimated_minutes_watched = channel.estimated_minutes_watched range.merge by: :traffic_source
552
+ expect(estimated_minutes_watched.keys - keys).to be_empty
553
+ end
554
+ end
555
+
556
+ describe 'estimated minutes watched can be grouped by video' do
557
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
558
+
559
+ specify 'with the :by option set to :video' do
560
+ estimated_minutes_watched = channel.estimated_minutes_watched range.merge by: :video
561
+ expect(estimated_minutes_watched.keys).to all(be_instance_of Yt::Video)
562
+ end
563
+ end
564
+
377
565
  describe 'average view duration can be retrieved for a specific day' do
378
566
  context 'in which the channel was partnered' do
379
567
  let(:average_view_duration) { channel.average_view_duration_on 5.days.ago}
@@ -406,6 +594,21 @@ describe Yt::Channel, :partner do
406
594
  end
407
595
  end
408
596
 
597
+ describe 'average view duration can be grouped by day' do
598
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
599
+ let(:keys) { range.values }
600
+
601
+ specify 'without a :by option (default)' do
602
+ average_view_duration = channel.average_view_duration range
603
+ expect(average_view_duration.keys).to eq range.values
604
+ end
605
+
606
+ specify 'with the :by option set to :day' do
607
+ average_view_duration = channel.average_view_duration range.merge by: :day
608
+ expect(average_view_duration.keys).to eq range.values
609
+ end
610
+ end
611
+
409
612
  describe 'average view percentage can be retrieved for a specific day' do
410
613
  context 'in which the channel was partnered' do
411
614
  let(:average_view_percentage) { channel.average_view_percentage_on 5.days.ago}
@@ -438,6 +641,21 @@ describe Yt::Channel, :partner do
438
641
  end
439
642
  end
440
643
 
644
+ describe 'average view percentage can be grouped by day' do
645
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
646
+ let(:keys) { range.values }
647
+
648
+ specify 'without a :by option (default)' do
649
+ average_view_percentage = channel.average_view_percentage range
650
+ expect(average_view_percentage.keys).to eq range.values
651
+ end
652
+
653
+ specify 'with the :by option set to :day' do
654
+ average_view_percentage = channel.average_view_percentage range.merge by: :day
655
+ expect(average_view_percentage.keys).to eq range.values
656
+ end
657
+ end
658
+
441
659
  describe 'impressions can be retrieved for a specific day' do
442
660
  context 'in which the channel was partnered' do
443
661
  let(:impressions) { channel.impressions_on 20.days.ago}
@@ -470,6 +688,21 @@ describe Yt::Channel, :partner do
470
688
  end
471
689
  end
472
690
 
691
+ describe 'impressions can be grouped by day' do
692
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
693
+ let(:keys) { range.values }
694
+
695
+ specify 'without a :by option (default)' do
696
+ impressions = channel.impressions range
697
+ expect(impressions.keys).to eq range.values
698
+ end
699
+
700
+ specify 'with the :by option set to :day' do
701
+ impressions = channel.impressions range.merge by: :day
702
+ expect(impressions.keys).to eq range.values
703
+ end
704
+ end
705
+
473
706
  specify 'viewer percentages by gender and age range can be retrieved' do
474
707
  expect(channel.viewer_percentages[:female]['18-24']).to be_a Float
475
708
  expect(channel.viewer_percentages[:female]['25-34']).to be_a Float
@@ -77,6 +77,31 @@ describe Yt::Video, :partner do
77
77
  end
78
78
  end
79
79
 
80
+ describe 'views can be grouped by day' do
81
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
82
+ let(:keys) { range.values }
83
+
84
+ specify 'without a :by option (default)' do
85
+ views = video.views range
86
+ expect(views.keys).to eq range.values
87
+ end
88
+
89
+ specify 'with the :by option set to :day' do
90
+ views = video.views range.merge by: :day
91
+ expect(views.keys).to eq range.values
92
+ end
93
+ end
94
+
95
+ describe 'views can be grouped by traffic source' do
96
+ let(:range) { {since: 4.days.ago, until: 3.days.ago} }
97
+ let(:keys) { Yt::Collections::Reports::TRAFFIC_SOURCES.keys }
98
+
99
+ specify 'with the :by option set to :traffic_source' do
100
+ views = video.views range.merge by: :traffic_source
101
+ expect(views.keys - keys).to be_empty
102
+ end
103
+ end
104
+
80
105
  describe 'comments can be retrieved for a specific day' do
81
106
  context 'in which the video was partnered' do
82
107
  let(:comments) { video.comments_on 5.days.ago}
@@ -109,6 +134,21 @@ describe Yt::Video, :partner do
109
134
  end
110
135
  end
111
136
 
137
+ describe 'comments can be grouped by day' do
138
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
139
+ let(:keys) { range.values }
140
+
141
+ specify 'without a :by option (default)' do
142
+ comments = video.comments range
143
+ expect(comments.keys).to eq range.values
144
+ end
145
+
146
+ specify 'with the :by option set to :day' do
147
+ comments = video.comments range.merge by: :day
148
+ expect(comments.keys).to eq range.values
149
+ end
150
+ end
151
+
112
152
  describe 'likes can be retrieved for a specific day' do
113
153
  context 'in which the video was partnered' do
114
154
  let(:likes) { video.likes_on 5.days.ago}
@@ -141,6 +181,21 @@ describe Yt::Video, :partner do
141
181
  end
142
182
  end
143
183
 
184
+ describe 'likes can be grouped by day' do
185
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
186
+ let(:keys) { range.values }
187
+
188
+ specify 'without a :by option (default)' do
189
+ likes = video.likes range
190
+ expect(likes.keys).to eq range.values
191
+ end
192
+
193
+ specify 'with the :by option set to :day' do
194
+ likes = video.likes range.merge by: :day
195
+ expect(likes.keys).to eq range.values
196
+ end
197
+ end
198
+
144
199
  describe 'dislikes can be retrieved for a specific day' do
145
200
  context 'in which the video was partnered' do
146
201
  let(:dislikes) { video.dislikes_on 5.days.ago}
@@ -173,6 +228,21 @@ describe Yt::Video, :partner do
173
228
  end
174
229
  end
175
230
 
231
+ describe 'dislikes can be grouped by day' do
232
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
233
+ let(:keys) { range.values }
234
+
235
+ specify 'without a :by option (default)' do
236
+ dislikes = video.dislikes range
237
+ expect(dislikes.keys).to eq range.values
238
+ end
239
+
240
+ specify 'with the :by option set to :day' do
241
+ dislikes = video.dislikes range.merge by: :day
242
+ expect(dislikes.keys).to eq range.values
243
+ end
244
+ end
245
+
176
246
  describe 'shares can be retrieved for a specific day' do
177
247
  context 'in which the video was partnered' do
178
248
  let(:shares) { video.shares_on 5.days.ago}
@@ -205,6 +275,21 @@ describe Yt::Video, :partner do
205
275
  end
206
276
  end
207
277
 
278
+ describe 'shares can be grouped by day' do
279
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
280
+ let(:keys) { range.values }
281
+
282
+ specify 'without a :by option (default)' do
283
+ shares = video.shares range
284
+ expect(shares.keys).to eq range.values
285
+ end
286
+
287
+ specify 'with the :by option set to :day' do
288
+ shares = video.shares range.merge by: :day
289
+ expect(shares.keys).to eq range.values
290
+ end
291
+ end
292
+
208
293
  describe 'gained subscribers can be retrieved for a specific day' do
209
294
  context 'in which the video was partnered' do
210
295
  let(:subscribers_gained) { video.subscribers_gained_on 5.days.ago}
@@ -237,6 +322,21 @@ describe Yt::Video, :partner do
237
322
  end
238
323
  end
239
324
 
325
+ describe 'gained subscribers can be grouped by day' do
326
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
327
+ let(:keys) { range.values }
328
+
329
+ specify 'without a :by option (default)' do
330
+ subscribers_gained = video.subscribers_gained range
331
+ expect(subscribers_gained.keys).to eq range.values
332
+ end
333
+
334
+ specify 'with the :by option set to :day' do
335
+ subscribers_gained = video.subscribers_gained range.merge by: :day
336
+ expect(subscribers_gained.keys).to eq range.values
337
+ end
338
+ end
339
+
240
340
  describe 'lost subscribers can be retrieved for a specific day' do
241
341
  context 'in which the video was partnered' do
242
342
  let(:subscribers_lost) { video.subscribers_lost_on 5.days.ago}
@@ -269,6 +369,21 @@ describe Yt::Video, :partner do
269
369
  end
270
370
  end
271
371
 
372
+ describe 'lost subscribers can be grouped by day' do
373
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
374
+ let(:keys) { range.values }
375
+
376
+ specify 'without a :by option (default)' do
377
+ subscribers_lost = video.subscribers_lost range
378
+ expect(subscribers_lost.keys).to eq range.values
379
+ end
380
+
381
+ specify 'with the :by option set to :day' do
382
+ subscribers_lost = video.subscribers_lost range.merge by: :day
383
+ expect(subscribers_lost.keys).to eq range.values
384
+ end
385
+ end
386
+
272
387
  describe 'added favorites can be retrieved for a specific day' do
273
388
  context 'in which the video was partnered' do
274
389
  let(:favorites_added) { video.favorites_added_on 5.days.ago}
@@ -301,6 +416,21 @@ describe Yt::Video, :partner do
301
416
  end
302
417
  end
303
418
 
419
+ describe 'added favorites can be grouped by day' do
420
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
421
+ let(:keys) { range.values }
422
+
423
+ specify 'without a :by option (default)' do
424
+ favorites_added = video.favorites_added range
425
+ expect(favorites_added.keys).to eq range.values
426
+ end
427
+
428
+ specify 'with the :by option set to :day' do
429
+ favorites_added = video.favorites_added range.merge by: :day
430
+ expect(favorites_added.keys).to eq range.values
431
+ end
432
+ end
433
+
304
434
  describe 'removed favorites can be retrieved for a specific day' do
305
435
  context 'in which the video was partnered' do
306
436
  let(:favorites_removed) { video.favorites_removed_on 5.days.ago}
@@ -333,6 +463,21 @@ describe Yt::Video, :partner do
333
463
  end
334
464
  end
335
465
 
466
+ describe 'removed favorites can be grouped by day' do
467
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
468
+ let(:keys) { range.values }
469
+
470
+ specify 'without a :by option (default)' do
471
+ favorites_removed = video.favorites_removed range
472
+ expect(favorites_removed.keys).to eq range.values
473
+ end
474
+
475
+ specify 'with the :by option set to :day' do
476
+ favorites_removed = video.favorites_removed range.merge by: :day
477
+ expect(favorites_removed.keys).to eq range.values
478
+ end
479
+ end
480
+
336
481
  describe 'impressions can be retrieved for a specific day' do
337
482
  context 'in which the video was partnered' do
338
483
  let(:impressions) { video.impressions_on 20.days.ago}
@@ -365,6 +510,21 @@ describe Yt::Video, :partner do
365
510
  end
366
511
  end
367
512
 
513
+ describe 'impressions can be grouped by day' do
514
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
515
+ let(:keys) { range.values }
516
+
517
+ specify 'without a :by option (default)' do
518
+ impressions = video.impressions range
519
+ expect(impressions.keys).to eq range.values
520
+ end
521
+
522
+ specify 'with the :by option set to :day' do
523
+ impressions = video.impressions range.merge by: :day
524
+ expect(impressions.keys).to eq range.values
525
+ end
526
+ end
527
+
368
528
  describe 'monetized playbacks can be retrieved for a specific day' do
369
529
  context 'in which the video was partnered' do
370
530
  let(:monetized_playbacks) { video.monetized_playbacks_on 20.days.ago}
@@ -397,6 +557,21 @@ describe Yt::Video, :partner do
397
557
  end
398
558
  end
399
559
 
560
+ describe 'monetized_playbacks can be grouped by day' do
561
+ let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
562
+ let(:keys) { range.values }
563
+
564
+ specify 'without a :by option (default)' do
565
+ monetized_playbacks = video.monetized_playbacks range
566
+ expect(monetized_playbacks.keys).to eq range.values
567
+ end
568
+
569
+ specify 'with the :by option set to :day' do
570
+ monetized_playbacks = video.monetized_playbacks range.merge by: :day
571
+ expect(monetized_playbacks.keys).to eq range.values
572
+ end
573
+ end
574
+
400
575
  specify 'viewer percentages by gender and age range can be retrieved' do
401
576
  expect(video.viewer_percentages[:female]['18-24']).to be_a Float
402
577
  expect(video.viewer_percentages[:female]['25-34']).to be_a Float
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.12
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-24 00:00:00.000000000 Z
11
+ date: 2015-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport