yt 0.24.6 → 0.24.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d676620de210d93c367be31ffddc1021b99d8408
4
- data.tar.gz: 0984d490fcafdac190230bb010ca406b8e662e2c
3
+ metadata.gz: 8fdec6049878d1f96dfb941ab2716fc3146e61c7
4
+ data.tar.gz: e7d54a900325067ba66fd17e42138dbb197ffec2
5
5
  SHA512:
6
- metadata.gz: a337c85ea2a024edf0ec05ca3ff6767b42e5439994b4e19e0cc23595372ea4f3edf742b56a871313f596c1a9887566040e130f0f4c7bdd390fcc60cb09ddba77
7
- data.tar.gz: 457231ab1328d8ef4704dbc3df67b2831d8c624c5ecc57e2ebeb53317031bdec1ea2e7b9326739386d0c85614e353c37dc10dea305504f8439aeee16469802bf
6
+ metadata.gz: 80cd1f43b207221e568aad90ab1fba921b44a3d33a7265a7d58303b76e5a322e2734872d4a6d825f41fdf8ee01b1e224ad6426dd4cc08199e2e57b1bf849b344
7
+ data.tar.gz: e2cc67add9e2b91a4f0770c31df76d54579d3f0034a4b8aef74783a3f76f0f1afd638d39275396954d0a07886aba39701c46294764eb7f1ee42763b5560ed2a4
@@ -6,6 +6,10 @@ 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.24.7 - 2015-06-08
10
+
11
+ * [ENHANCEMENT] Add `:videos` option to limit channel reports to subset of videos
12
+
9
13
  ## 0.24.6 - 2015-06-08
10
14
 
11
15
  * [ENHANCEMENT] When grouping by day, return results in chronological order
data/README.md CHANGED
@@ -41,7 +41,7 @@ To install on your system, run
41
41
 
42
42
  To use inside a bundled Ruby project, add this line to the Gemfile:
43
43
 
44
- gem 'yt', '~> 0.24.6'
44
+ gem 'yt', '~> 0.24.7'
45
45
 
46
46
  Since the gem follows [Semantic Versioning](http://semver.org),
47
47
  indicating the full version in your Gemfile (~> *major*.*minor*.*patch*)
@@ -236,6 +236,7 @@ module Yt
236
236
  country = location.is_a?(Hash) ? location[:country] : location
237
237
  state = location[:state] if location.is_a?(Hash)
238
238
  dimension = options[:by] || (metric == :viewer_percentage ? :gender_age_group : :range)
239
+ videos = options[:videos]
239
240
  if dimension == :month
240
241
  from = from.to_date.beginning_of_month
241
242
  to = to.to_date.beginning_of_month
@@ -246,7 +247,7 @@ module Yt
246
247
  reports = Collections::Reports.of(self).tap do |reports|
247
248
  reports.metrics = self.class.instance_variable_get(:@metrics).select{|k, v| k.in? only}
248
249
  end
249
- reports.within date_range, country, state, dimension
250
+ reports.within date_range, country, state, dimension, videos
250
251
  end unless defined?(reports)
251
252
  end
252
253
 
@@ -258,6 +259,7 @@ module Yt
258
259
  country = location.is_a?(Hash) ? location[:country] : location
259
260
  state = location[:state] if location.is_a?(Hash)
260
261
  dimension = options[:by] || (metric == :viewer_percentage ? :gender_age_group : :range)
262
+ videos = options[:videos]
261
263
  if dimension == :month
262
264
  from = from.to_date.beginning_of_month
263
265
  to = to.to_date.beginning_of_month
@@ -269,10 +271,10 @@ module Yt
269
271
  results = case dimension
270
272
  when :day
271
273
  Hash[*range.flat_map do |date|
272
- [date, instance_variable_get("@#{metric}_#{dimension}_#{country}_#{state}")[date] ||= send("range_#{metric}", range, dimension, country, state)[date]]
274
+ [date, instance_variable_get("@#{metric}_#{dimension}_#{country}_#{state}")[date] ||= send("range_#{metric}", range, dimension, country, state, videos)[date]]
273
275
  end]
274
276
  else
275
- instance_variable_get("@#{metric}_#{dimension}_#{country}_#{state}")[range] ||= send("range_#{metric}", range, dimension, country, state)
277
+ instance_variable_get("@#{metric}_#{dimension}_#{country}_#{state}")[range] ||= send("range_#{metric}", range, dimension, country, state, videos)
276
278
  end
277
279
  lookup_class = case options[:by]
278
280
  when :video, :related_video then Yt::Collections::Videos
@@ -289,10 +291,10 @@ module Yt
289
291
  end
290
292
 
291
293
  def define_range_metric_method(metric)
292
- define_method "range_#{metric}" do |date_range, dimension, country, state|
294
+ define_method "range_#{metric}" do |date_range, dimension, country, state, videos|
293
295
  ivar = instance_variable_get "@range_#{metric}_#{dimension}_#{country}_#{state}"
294
296
  instance_variable_set "@range_#{metric}_#{dimension}_#{country}_#{state}", ivar || {}
295
- instance_variable_get("@range_#{metric}_#{dimension}_#{country}_#{state}")[date_range] ||= send("all_#{metric}").within date_range, country, state, dimension
297
+ instance_variable_get("@range_#{metric}_#{dimension}_#{country}_#{state}")[date_range] ||= send("all_#{metric}").within date_range, country, state, dimension, videos
296
298
  end
297
299
  private "range_#{metric}"
298
300
  end
@@ -56,11 +56,12 @@ module Yt
56
56
 
57
57
  attr_writer :metrics
58
58
 
59
- def within(days_range, country, state, dimension, try_again = true)
59
+ def within(days_range, country, state, dimension, videos, try_again = true)
60
60
  @days_range = days_range
61
61
  @dimension = dimension
62
62
  @country = country
63
63
  @state = state
64
+ @videos = videos
64
65
  if dimension == :gender_age_group # array of array
65
66
  Hash.new{|h,k| h[k] = Hash.new 0.0}.tap do |hash|
66
67
  each{|gender, age_group, value| hash[gender][age_group[3..-1]] = value}
@@ -90,7 +91,7 @@ module Yt
90
91
  # same query is a workaround that works and can hardly cause any damage.
91
92
  # Similarly, once in while YouTube responds with a random 503 error.
92
93
  rescue Yt::Error => e
93
- try_again && rescue?(e) ? sleep(3) && within(days_range, country, state, dimension, false) : raise
94
+ try_again && rescue?(e) ? sleep(3) && within(days_range, country, state, dimension, videos, false) : raise
94
95
  end
95
96
 
96
97
  private
@@ -125,6 +126,7 @@ module Yt
125
126
  params['max-results'] = 200 if @dimension == :playlist
126
127
  params['max-results'] = 25 if @dimension.in? [:embedded_player_location, :related_video, :search_term, :referrer]
127
128
  params['sort'] = "-#{@metrics.keys.join(',').to_s.camelize(:lower)}" if @dimension.in? [:video, :playlist, :embedded_player_location, :related_video, :search_term, :referrer]
129
+ params[:filters] = "video==#{@videos.join ','}" if @videos
128
130
  params[:filters] = ((params[:filters] || '').split(';') + ["country==US"]).compact.uniq.join(';') if @dimension == :state && !@state
129
131
  params[:filters] = ((params[:filters] || '').split(';') + ["country==#{@country}"]).compact.uniq.join(';') if @country && !@state
130
132
  params[:filters] = ((params[:filters] || '').split(';') + ["province==US-#{@state}"]).compact.uniq.join(';') if @state
@@ -1,3 +1,3 @@
1
1
  module Yt
2
- VERSION = '0.24.6'
2
+ VERSION = '0.24.7'
3
3
  end
@@ -9,7 +9,7 @@ describe Yt::Collections::Reports do
9
9
  let(:msg) { {response_body: {error: {errors: [error]}}}.to_json }
10
10
 
11
11
  describe '#within' do
12
- let(:result) { reports.within Range.new(5.days.ago, 4.days.ago), nil, nil, :day }
12
+ let(:result) { reports.within Range.new(5.days.ago, 4.days.ago), nil, nil, :day, nil }
13
13
  context 'given the request raises error 400 with "Invalid Query" message' do
14
14
  let(:reason) { 'badRequest' }
15
15
  let(:message) { 'Invalid query. Query did not conform to the expectations' }
@@ -449,6 +449,17 @@ describe Yt::Channel, :partner do
449
449
  end
450
450
  end
451
451
 
452
+ describe 'views can be limited to a subset of videos' do
453
+ let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
454
+ let(:videos) { channel.videos.first(2) }
455
+
456
+ specify 'with the :videos option listing the video IDs' do
457
+ video_views = videos.inject(0){|total, video| total + video.views(range)[:total]}
458
+ views = channel.views range.merge videos: videos.map(&:id)
459
+ expect(views[:total]).to eq video_views
460
+ end
461
+ end
462
+
452
463
  describe 'uniques can be retrieved for a single country' do
453
464
  let(:country_code) { 'US' }
454
465
  let(:uniques) { channel.uniques since: date, by: by, in: location }
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.24.6
4
+ version: 0.24.7
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-06-08 00:00:00.000000000 Z
11
+ date: 2015-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport