yt 0.31.2 → 0.32.0
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/yt/associations/has_reports.rb +7 -5
- data/lib/yt/collections/reports.rb +4 -3
- data/lib/yt/version.rb +1 -1
- data/spec/collections/reports_spec.rb +2 -2
- metadata +3 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f06db796f31fee245ad83b3d20908c1e652d61fb
|
|
4
|
+
data.tar.gz: d1d811649caf2f5c4ef4dc689d71b97ef2290c5d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 76902d316c6b13754da0501c52740faf226784e9f47ee002ad0552a1571a61f604caad50bad5b9c560abcbc6a0b863ad234b2b9e56620acf6cdba2aeca723a1a
|
|
7
|
+
data.tar.gz: 3a91d3dbbe592a8b189c301d2a122fb522a32dcb012b82ed5d6c9e3f306be283969b7c6bff01eaf34bb4605e2997fece355245f669cc8d117b89a021f8a16696
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,14 @@ 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.32.0 - 2017-07-05
|
|
10
|
+
|
|
11
|
+
**How to upgrade**
|
|
12
|
+
|
|
13
|
+
If your code is expecting data from `reports` methods to always include historical data (the data from the period before joining), now you have to set `historical: true` specifically. It will not include historical data by default.
|
|
14
|
+
|
|
15
|
+
* [IMPROVEMENT] Include historical data with `historical: true` option.
|
|
16
|
+
|
|
9
17
|
## 0.31.2 - 2017-06-29
|
|
10
18
|
|
|
11
19
|
* [BUGFIX] Return lifetime data correctly even when the channel joined content owner after a while since it's created.
|
|
@@ -235,6 +235,7 @@ module Yt
|
|
|
235
235
|
state = location[:state] if location.is_a?(Hash)
|
|
236
236
|
dimension = options[:by] || (metric == :viewer_percentage ? :gender_age_group : :range)
|
|
237
237
|
videos = options[:videos]
|
|
238
|
+
historical = options[:historical].to_s if [true, false].include?(options[:historical])
|
|
238
239
|
if dimension == :month
|
|
239
240
|
from = from.to_date.beginning_of_month
|
|
240
241
|
to = to.to_date.beginning_of_month
|
|
@@ -245,7 +246,7 @@ module Yt
|
|
|
245
246
|
reports = Collections::Reports.of(self).tap do |reports|
|
|
246
247
|
reports.metrics = self.class.instance_variable_get(:@metrics).select{|k, v| k.in? only}
|
|
247
248
|
end
|
|
248
|
-
reports.within date_range, country, state, dimension, videos
|
|
249
|
+
reports.within date_range, country, state, dimension, videos, historical
|
|
249
250
|
end unless defined?(reports)
|
|
250
251
|
end
|
|
251
252
|
|
|
@@ -258,6 +259,7 @@ module Yt
|
|
|
258
259
|
state = location[:state] if location.is_a?(Hash)
|
|
259
260
|
dimension = options[:by] || (metric == :viewer_percentage ? :gender_age_group : :range)
|
|
260
261
|
videos = options[:videos]
|
|
262
|
+
historical = options[:historical].to_s if [true, false].include?(options[:historical])
|
|
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, videos)[date]]
|
|
274
|
+
[date, instance_variable_get("@#{metric}_#{dimension}_#{country}_#{state}")[date] ||= send("range_#{metric}", range, dimension, country, state, videos, historical)[date]]
|
|
273
275
|
end]
|
|
274
276
|
else
|
|
275
|
-
instance_variable_get("@#{metric}_#{dimension}_#{country}_#{state}")[range] ||= send("range_#{metric}", range, dimension, country, state, videos)
|
|
277
|
+
instance_variable_get("@#{metric}_#{dimension}_#{country}_#{state}")[range] ||= send("range_#{metric}", range, dimension, country, state, videos, historical)
|
|
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, videos|
|
|
294
|
+
define_method "range_#{metric}" do |date_range, dimension, country, state, videos, historical|
|
|
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, videos
|
|
297
|
+
instance_variable_get("@range_#{metric}_#{dimension}_#{country}_#{state}")[date_range] ||= send("all_#{metric}").within date_range, country, state, dimension, videos, historical
|
|
296
298
|
end
|
|
297
299
|
private "range_#{metric}"
|
|
298
300
|
end
|
|
@@ -117,12 +117,13 @@ module Yt
|
|
|
117
117
|
|
|
118
118
|
attr_writer :metrics
|
|
119
119
|
|
|
120
|
-
def within(days_range, country, state, dimension, videos, max_retries = 3)
|
|
120
|
+
def within(days_range, country, state, dimension, videos, historical, max_retries = 3)
|
|
121
121
|
@days_range = days_range
|
|
122
122
|
@country = country
|
|
123
123
|
@state = state
|
|
124
124
|
@dimension = dimension
|
|
125
125
|
@videos = videos
|
|
126
|
+
@historical = historical
|
|
126
127
|
if dimension == :gender_age_group # array of array
|
|
127
128
|
Hash.new{|h,k| h[k] = Hash.new 0.0}.tap do |hash|
|
|
128
129
|
each{|gender, age_group, value| hash[gender][age_group[3..-1]] = value}
|
|
@@ -157,7 +158,7 @@ module Yt
|
|
|
157
158
|
# same query is a workaround that works and can hardly cause any damage.
|
|
158
159
|
# Similarly, once in while YouTube responds with a random 503 error.
|
|
159
160
|
rescue Yt::Error => e
|
|
160
|
-
(max_retries > 0) && rescue?(e) ? sleep(3) && within(days_range, country, state, dimension, videos, max_retries - 1) : raise
|
|
161
|
+
(max_retries > 0) && rescue?(e) ? sleep(3) && within(days_range, country, state, dimension, videos, historical, max_retries - 1) : raise
|
|
161
162
|
end
|
|
162
163
|
|
|
163
164
|
private
|
|
@@ -188,7 +189,7 @@ module Yt
|
|
|
188
189
|
params['end-date'] = @days_range.end
|
|
189
190
|
params['metrics'] = @metrics.keys.join(',').to_s.camelize(:lower)
|
|
190
191
|
params['dimensions'] = DIMENSIONS[@dimension][:name] unless @dimension == :range
|
|
191
|
-
params['include-historical-channel-data'] =
|
|
192
|
+
params['include-historical-channel-data'] = @historical if @historical
|
|
192
193
|
params['max-results'] = 50 if @dimension.in? [:playlist, :video]
|
|
193
194
|
params['max-results'] = 25 if @dimension.in? [:embedded_player_location, :related_video, :search_term, :referrer]
|
|
194
195
|
if @dimension.in? [:video, :playlist, :embedded_player_location, :related_video, :search_term, :referrer]
|
data/lib/yt/version.rb
CHANGED
|
@@ -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, nil }
|
|
12
|
+
let(:result) { reports.within Range.new(5.days.ago, 4.days.ago), nil, nil, :day, nil, 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' }
|
|
@@ -27,4 +27,4 @@ describe Yt::Collections::Reports do
|
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
|
-
end
|
|
30
|
+
end
|
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.
|
|
4
|
+
version: 0.32.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: 2017-
|
|
11
|
+
date: 2017-07-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -337,7 +337,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
337
337
|
version: '0'
|
|
338
338
|
requirements: []
|
|
339
339
|
rubyforge_project:
|
|
340
|
-
rubygems_version: 2.6.
|
|
340
|
+
rubygems_version: 2.6.12
|
|
341
341
|
signing_key:
|
|
342
342
|
specification_version: 4
|
|
343
343
|
summary: Yt makes it easy to interact with Youtube V3 API by providing a modular,
|
|
@@ -421,4 +421,3 @@ test_files:
|
|
|
421
421
|
- spec/spec_helper.rb
|
|
422
422
|
- spec/support/fail_matcher.rb
|
|
423
423
|
- spec/support/global_hooks.rb
|
|
424
|
-
has_rdoc:
|