yt 0.32.6 → 0.33.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -4
  3. data/CHANGELOG.md +36 -0
  4. data/README.md +22 -33
  5. data/YOUTUBE_IT.md +4 -4
  6. data/lib/yt.rb +1 -1
  7. data/lib/yt/actions/list.rb +1 -1
  8. data/lib/yt/associations/has_reports.rb +9 -14
  9. data/lib/yt/collections/reports.rb +5 -7
  10. data/lib/yt/models/account.rb +13 -3
  11. data/lib/yt/models/channel.rb +19 -4
  12. data/lib/yt/models/resource.rb +74 -3
  13. data/lib/yt/models/status.rb +3 -1
  14. data/lib/yt/models/url.rb +2 -60
  15. data/lib/yt/models/video.rb +16 -1
  16. data/lib/yt/request.rb +7 -4
  17. data/lib/yt/version.rb +1 -1
  18. data/yt.gemspec +5 -2
  19. metadata +32 -170
  20. data/spec/collections/claims_spec.rb +0 -62
  21. data/spec/collections/comment_threads_spec.rb +0 -46
  22. data/spec/collections/playlist_items_spec.rb +0 -44
  23. data/spec/collections/playlists_spec.rb +0 -27
  24. data/spec/collections/policies_spec.rb +0 -30
  25. data/spec/collections/references_spec.rb +0 -30
  26. data/spec/collections/reports_spec.rb +0 -30
  27. data/spec/collections/subscriptions_spec.rb +0 -25
  28. data/spec/collections/videos_spec.rb +0 -43
  29. data/spec/constants/geography_spec.rb +0 -16
  30. data/spec/errors/forbidden_spec.rb +0 -10
  31. data/spec/errors/missing_auth_spec.rb +0 -24
  32. data/spec/errors/no_items_spec.rb +0 -10
  33. data/spec/errors/request_error_spec.rb +0 -44
  34. data/spec/errors/server_error_spec.rb +0 -10
  35. data/spec/errors/unauthorized_spec.rb +0 -10
  36. data/spec/models/account_spec.rb +0 -138
  37. data/spec/models/annotation_spec.rb +0 -180
  38. data/spec/models/asset_spec.rb +0 -32
  39. data/spec/models/channel_spec.rb +0 -127
  40. data/spec/models/claim_event_spec.rb +0 -62
  41. data/spec/models/claim_history_spec.rb +0 -27
  42. data/spec/models/claim_spec.rb +0 -223
  43. data/spec/models/comment_spec.rb +0 -40
  44. data/spec/models/comment_thread_spec.rb +0 -93
  45. data/spec/models/configuration_spec.rb +0 -44
  46. data/spec/models/content_detail_spec.rb +0 -52
  47. data/spec/models/content_owner_detail_spec.rb +0 -6
  48. data/spec/models/file_detail_spec.rb +0 -13
  49. data/spec/models/live_streaming_detail_spec.rb +0 -6
  50. data/spec/models/ownership_spec.rb +0 -59
  51. data/spec/models/player_spec.rb +0 -13
  52. data/spec/models/playlist_item_spec.rb +0 -120
  53. data/spec/models/playlist_spec.rb +0 -138
  54. data/spec/models/policy_rule_spec.rb +0 -63
  55. data/spec/models/policy_spec.rb +0 -41
  56. data/spec/models/rating_spec.rb +0 -12
  57. data/spec/models/reference_spec.rb +0 -249
  58. data/spec/models/request_spec.rb +0 -204
  59. data/spec/models/resource_spec.rb +0 -42
  60. data/spec/models/right_owner_spec.rb +0 -71
  61. data/spec/models/snippet_spec.rb +0 -13
  62. data/spec/models/statistics_set_spec.rb +0 -13
  63. data/spec/models/status_spec.rb +0 -13
  64. data/spec/models/subscription_spec.rb +0 -30
  65. data/spec/models/url_spec.rb +0 -78
  66. data/spec/models/video_category_spec.rb +0 -21
  67. data/spec/models/video_spec.rb +0 -669
  68. data/spec/requests/as_account/account_spec.rb +0 -143
  69. data/spec/requests/as_account/authentications_spec.rb +0 -127
  70. data/spec/requests/as_account/channel_spec.rb +0 -246
  71. data/spec/requests/as_account/channels_spec.rb +0 -18
  72. data/spec/requests/as_account/playlist_item_spec.rb +0 -55
  73. data/spec/requests/as_account/playlist_spec.rb +0 -218
  74. data/spec/requests/as_account/thumbnail.jpg +0 -0
  75. data/spec/requests/as_account/video.mp4 +0 -0
  76. data/spec/requests/as_account/video_spec.rb +0 -408
  77. data/spec/requests/as_content_owner/account_spec.rb +0 -29
  78. data/spec/requests/as_content_owner/advertising_options_set_spec.rb +0 -15
  79. data/spec/requests/as_content_owner/asset_spec.rb +0 -31
  80. data/spec/requests/as_content_owner/bulk_report_job_spec.rb +0 -19
  81. data/spec/requests/as_content_owner/channel_spec.rb +0 -1836
  82. data/spec/requests/as_content_owner/claim_history_spec.rb +0 -20
  83. data/spec/requests/as_content_owner/claim_spec.rb +0 -17
  84. data/spec/requests/as_content_owner/content_owner_spec.rb +0 -370
  85. data/spec/requests/as_content_owner/match_policy_spec.rb +0 -17
  86. data/spec/requests/as_content_owner/ownership_spec.rb +0 -25
  87. data/spec/requests/as_content_owner/playlist_spec.rb +0 -767
  88. data/spec/requests/as_content_owner/video_group_spec.rb +0 -112
  89. data/spec/requests/as_content_owner/video_spec.rb +0 -1223
  90. data/spec/requests/as_server_app/channel_spec.rb +0 -54
  91. data/spec/requests/as_server_app/comment_spec.rb +0 -22
  92. data/spec/requests/as_server_app/comment_thread_spec.rb +0 -27
  93. data/spec/requests/as_server_app/comment_threads_spec.rb +0 -41
  94. data/spec/requests/as_server_app/playlist_item_spec.rb +0 -30
  95. data/spec/requests/as_server_app/playlist_spec.rb +0 -33
  96. data/spec/requests/as_server_app/url_spec.rb +0 -94
  97. data/spec/requests/as_server_app/video_spec.rb +0 -60
  98. data/spec/requests/as_server_app/videos_spec.rb +0 -40
  99. data/spec/requests/unauthenticated/video_spec.rb +0 -14
  100. data/spec/spec_helper.rb +0 -20
  101. data/spec/support/fail_matcher.rb +0 -15
  102. data/spec/support/global_hooks.rb +0 -48
@@ -1,29 +0,0 @@
1
- # encoding: UTF-8
2
- require 'spec_helper'
3
- require 'yt/models/account'
4
-
5
- describe Yt::Account, :partner do
6
- subject(:account) { Yt::Account.new id: id, authentication: $content_owner.authentication }
7
-
8
- describe '.content_owners' do
9
- let(:content_owners) { account.content_owners }
10
-
11
- context 'given a partenered account with content owners', :partner do
12
- let(:id) { $content_owner.id }
13
-
14
- specify 'returns the associated content owners' do
15
- expect(content_owners.size).to be > 0
16
- expect(content_owners.first).to be_a Yt::ContentOwner
17
- end
18
-
19
- specify 'includes the display name for each content owner' do
20
- expect(content_owners.first.display_name).to be_a String
21
- end
22
-
23
- specify 'ensures the content owners have the same credentials as the account' do
24
- expect(content_owners.first.access_token).to eq account.access_token
25
- expect(content_owners.first.refresh_token).to eq account.refresh_token
26
- end
27
- end
28
- end
29
- end
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/models/advertising_options_set'
3
-
4
- describe Yt::AdvertisingOptionsSet, :partner do
5
- subject(:advertising_options_set) { Yt::AdvertisingOptionsSet.new video_id: video_id, auth: $content_owner }
6
-
7
- context 'given a video managed by the authenticated Content Owner' do
8
- let(:video_id) { ENV['YT_TEST_PARTNER_CLAIMABLE_VIDEO_ID'] }
9
-
10
- describe 'the advertising options can be updated' do
11
- let(:params) { {ad_formats: %w(standard_instream long)} }
12
- it { expect(advertising_options_set.update params).to be true }
13
- end
14
- end
15
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/models/content_owner'
3
-
4
- describe Yt::Asset, :partner do
5
- describe '.ownership' do
6
- let(:asset) { Yt::Asset.new id: asset_id, auth: $content_owner }
7
-
8
- describe 'given an asset administered by the content owner' do
9
- let(:asset_id) { ENV['YT_TEST_PARTNER_ASSET_ID'] }
10
-
11
- describe 'when performing an update' do
12
- specify 'the ownership can be obtained' do
13
- expect(asset.ownership).to be_a Yt::Ownership
14
- end
15
-
16
- describe 'the asset can be updated' do
17
- let(:attrs) { {metadata_mine: {notes: 'Yt notes'}} }
18
- it { expect(asset.update attrs).to be true }
19
- end
20
- end
21
-
22
- describe 'when performing a get' do
23
- let(:asset_with_metadata_mine) { Yt::Asset.new id: asset_id, auth: $content_owner, params: {fetch_metadata: 'mine'} }
24
-
25
- specify 'the metadata mine can be obtained' do
26
- expect(asset_with_metadata_mine.get.metadata_mine.custom_id).to be_a String
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/models/bulk_report_job'
3
-
4
- describe Yt::BulkReportJob, :partner do
5
-
6
- describe '.bulk_reports' do
7
- describe 'given the bulk report job has bulk reports' do
8
- let(:job) { $content_owner.bulk_report_jobs.first }
9
- let(:report) { job.bulk_reports.first }
10
-
11
- it 'returns valid bulk reports' do
12
- expect(report.id).to be_a String
13
- expect(report.start_time).to be_a Time
14
- expect(report.end_time).to be_a Time
15
- expect(report.download_url).to be_a String
16
- end
17
- end
18
- end
19
- end
@@ -1,1836 +0,0 @@
1
- # encoding: UTF-8
2
- require 'spec_helper'
3
- require 'yt/models/channel'
4
- require 'yt/models/playlist'
5
-
6
- describe Yt::Channel, :partner do
7
- subject(:channel) { Yt::Channel.new id: id, auth: $content_owner }
8
-
9
- context 'given a partnered channel', :partner do
10
- context 'managed by the authenticated Content Owner' do
11
- let(:id) { ENV['YT_TEST_PARTNER_CHANNEL_ID'] }
12
-
13
- describe 'multiple reports can be retrieved at once' do
14
- metrics = {views: Integer,
15
- estimated_minutes_watched: Integer, comments: Integer, likes: Integer,
16
- dislikes: Integer, shares: Integer, subscribers_gained: Integer,
17
- subscribers_lost: Integer,
18
- videos_added_to_playlists: Integer, videos_removed_from_playlists: Integer,
19
- average_view_duration: Integer,
20
- average_view_percentage: Float, annotation_clicks: Integer,
21
- annotation_click_through_rate: Float, annotation_close_rate: Float,
22
- card_impressions: Integer, card_clicks: Integer,
23
- card_click_rate: Float, card_teaser_impressions: Integer,
24
- card_teaser_clicks: Integer, card_teaser_click_rate: Float,
25
- estimated_revenue: Float, ad_impressions: Integer,
26
- monetized_playbacks: Integer, playback_based_cpm: Float}
27
- specify 'by day, and are chronologically sorted' do
28
- range = {since: 5.days.ago.to_date, until: 3.days.ago.to_date}
29
- result = channel.reports range.merge(only: metrics, by: :day)
30
- metrics.each do |metric, type|
31
- expect(result[metric].keys).to all(be_a Date)
32
- expect(result[metric].values).to all(be_a type)
33
- expect(result[metric].keys.sort).to eq result[metric].keys
34
- end
35
- end
36
-
37
- specify 'by month, and are chronologically sorted' do
38
- result = channel.reports only: metrics, by: :month, since: 1.month.ago
39
- metrics.each do |metric, type|
40
- expect(result[metric].keys).to all(be_a Range)
41
- expect(result[metric].keys.map &:first).to all(be_a Date)
42
- expect(result[metric].keys.map &:first).to eq result[metric].keys.map(&:first).map(&:beginning_of_month)
43
- expect(result[metric].keys.map &:last).to all(be_a Date)
44
- expect(result[metric].keys.map &:last).to eq result[metric].keys.map(&:last).map(&:end_of_month)
45
- expect(result[metric].values).to all(be_a type)
46
- end
47
- end
48
-
49
- specify 'by week' do
50
- range = {since: ENV['YT_TEST_PARTNER_VIDEO_DATE'], until: Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 9}
51
- result = channel.reports range.merge(only: metrics, by: :week)
52
- metrics.each do |metric, type|
53
- expect(result[metric].size).to be <= 2
54
- expect(result[metric].keys).to all(be_a Range)
55
- expect(result[metric].keys.map{|range| range.first.wday}.uniq).to be_one
56
- expect(result[metric].keys.map{|range| range.last.wday}.uniq).to be_one
57
- expect(result[metric].values).to all(be_a type)
58
- end
59
- end
60
- end
61
-
62
- [:views, :comments, :likes, :dislikes, :shares,
63
- :subscribers_gained, :subscribers_lost,
64
- :videos_added_to_playlists, :videos_removed_from_playlists,
65
- :estimated_minutes_watched, :average_view_duration,
66
- :average_view_percentage, :ad_impressions, :monetized_playbacks,
67
- :annotation_clicks, :annotation_click_through_rate,
68
- :card_impressions, :card_clicks, :card_click_rate,
69
- :card_teaser_impressions, :card_teaser_clicks, :card_teaser_click_rate,
70
- :playback_based_cpm, :annotation_close_rate, :estimated_revenue].each do |metric|
71
- describe "#{metric} can be retrieved for a range of days" do
72
- let(:date_in) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
73
- let(:date_out) { Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 5 }
74
- let(:metric) { metric }
75
- let(:result) { channel.public_send metric, options }
76
-
77
- context 'with a given start and end (:since/:until option)' do
78
- let(:options) { {by: :day, since: date_in, until: date_out} }
79
- specify do
80
- expect(result.keys.min).to eq date_in.to_date
81
- expect(result.keys.max).to eq date_out.to_date
82
- end
83
- end
84
-
85
- context 'with a given start and end (:from/:to option)' do
86
- let(:options) { {by: :day, from: date_in, to: date_out} }
87
- specify do
88
- expect(result.keys.min).to eq date_in.to_date
89
- expect(result.keys.max).to eq date_out.to_date
90
- end
91
- end
92
- end
93
-
94
- describe "#{metric} can be grouped by month" do
95
- let(:metric) { metric }
96
-
97
- let(:result) { channel.public_send metric, by: :month, since: 3.months.ago }
98
- specify do
99
- expect(result.keys).to eq(result.keys.sort_by{|range| range.first})
100
- expect(result.keys).to all(be_a Range)
101
- expect(result.keys.map &:first).to all(be_a Date)
102
- expect(result.keys.map &:first).to eq result.keys.map(&:first).map(&:beginning_of_month)
103
- expect(result.keys.map &:last).to all(be_a Date)
104
- expect(result.keys.map &:last).to eq result.keys.map(&:last).map(&:end_of_month)
105
- end
106
- end
107
-
108
- describe "#{metric} can be grouped by week and returns non-overlapping periods" do
109
- let(:metric) { metric }
110
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE'], until: Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 9} }
111
- let(:result) { channel.public_send metric, range.merge(by: :week)}
112
- specify do
113
- expect(result.size).to be <= 2
114
- expect(result.keys).to all(be_a Range)
115
- expect(result.keys.map{|range| range.first.wday}.uniq).to be_one
116
- expect(result.keys.map{|range| range.last.wday}.uniq).to be_one
117
- end
118
- end
119
- end
120
-
121
- {views: Integer, comments: Integer, likes: Integer, dislikes: Integer,
122
- subscribers_gained: Integer, subscribers_lost: Integer,
123
- estimated_minutes_watched: Integer, average_view_duration: Integer,
124
- annotation_clicks: Integer, annotation_click_through_rate: Float,
125
- card_impressions: Integer, card_clicks: Integer,
126
- card_click_rate: Float, card_teaser_impressions: Integer,
127
- card_teaser_clicks: Integer, card_teaser_click_rate: Float,
128
- videos_added_to_playlists: Integer, videos_removed_from_playlists: Integer,
129
- average_view_percentage: Float, ad_impressions: Integer,
130
- shares: Integer, playback_based_cpm: Float,
131
- monetized_playbacks: Integer, annotation_close_rate: Float,
132
- estimated_revenue: Float}.each do |metric, type|
133
- describe "#{metric} can be grouped by range" do
134
- let(:metric) { metric }
135
-
136
- context 'without a :by option (default)' do
137
- let(:result) { channel.public_send metric }
138
- specify do
139
- expect(result.size).to be 1
140
- expect(result[:total]).to be_a type
141
- end
142
- end
143
-
144
- context 'with the :by option set to :range' do
145
- let(:result) { channel.public_send metric, by: :range }
146
- specify do
147
- expect(result.size).to be 1
148
- expect(result[:total]).to be_a type
149
- end
150
- end
151
- end
152
- end
153
-
154
- describe 'estimated_revenue can be retrieved for a specific day' do
155
- # NOTE: This test sounds redundant, but it’s actually a reflection of
156
- # another irrational behavior of YouTube API. In short, if you ask for
157
- # the "estimated_revenue" metric of a day in which a channel made 0 USD, then
158
- # the API returns "nil". But if you also for the "estimated_revenue" metric AND
159
- # the "estimatedMinutesWatched" metric, then the API returns the
160
- # correct value of "0", while still returning nil for those days in
161
- # which the estimated_revenue have not been estimated yet.
162
- context 'in which the channel did not make any money' do
163
- let(:zero_date) { ENV['YT_TEST_PARTNER_CHANNEL_NO_estimated_revenue_DATE'] }
164
- let(:estimated_revenue) { channel.estimated_revenue_on zero_date}
165
- it { expect(estimated_revenue).to eq 0 }
166
- end
167
- end
168
-
169
- describe 'estimated_revenue can be retrieved for a single country' do
170
- let(:country_code) { 'US' }
171
- let(:estimated_revenue) { channel.estimated_revenue since: date, by: by, in: location }
172
- let(:date) { 4.days.ago }
173
-
174
- context 'and grouped by day' do
175
- let(:by) { :day }
176
-
177
- context 'with the :in option set to the country code' do
178
- let(:location) { country_code }
179
- it { expect(estimated_revenue.keys.min).to eq date.to_date }
180
- end
181
-
182
- context 'with the :in option set to {country: country code}' do
183
- let(:location) { {country: country_code} }
184
- it { expect(estimated_revenue.keys.min).to eq date.to_date }
185
- end
186
- end
187
-
188
- context 'and grouped by country' do
189
- let(:by) { :country }
190
-
191
- context 'with the :in option set to the country code' do
192
- let(:location) { country_code }
193
- it { expect(estimated_revenue.keys).to eq [country_code] }
194
- end
195
-
196
- context 'with the :in option set to {country: country code}' do
197
- let(:location) { {country: country_code} }
198
- it { expect(estimated_revenue.keys).to eq [country_code] }
199
- end
200
- end
201
- end
202
-
203
- describe 'estimated_revenue can be grouped by day' do
204
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
205
- let(:keys) { range.values }
206
-
207
- specify 'with the :by option set to :day' do
208
- estimated_revenue = channel.estimated_revenue range.merge by: :day
209
- expect(estimated_revenue.keys).to eq range.values
210
- end
211
- end
212
-
213
- describe 'estimated_revenue can be grouped by country' do
214
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
215
-
216
- specify 'with the :by option set to :country' do
217
- estimated_revenue = channel.estimated_revenue range.merge by: :country
218
- expect(estimated_revenue.keys).to all(be_a String)
219
- expect(estimated_revenue.keys.map(&:length).uniq).to eq [2]
220
- expect(estimated_revenue.values).to all(be_a Float)
221
- end
222
- end
223
-
224
- describe 'views can be retrieved for a single country' do
225
- let(:country_code) { 'US' }
226
- let(:views) { channel.views since: date, by: by, in: location }
227
- let(:date) { 4.days.ago }
228
-
229
- context 'and grouped by day' do
230
- let(:by) { :day }
231
-
232
- context 'with the :in option set to the country code' do
233
- let(:location) { country_code }
234
- it { expect(views.keys.min).to eq date.to_date }
235
- end
236
-
237
- context 'with the :in option set to {country: country code}' do
238
- let(:location) { {country: country_code} }
239
- it { expect(views.keys.min).to eq date.to_date }
240
- end
241
- end
242
-
243
- context 'and grouped by country' do
244
- let(:by) { :country }
245
-
246
- context 'with the :in option set to the country code' do
247
- let(:location) { country_code }
248
- it { expect(views.keys).to eq [country_code] }
249
- end
250
-
251
- context 'with the :in option set to {country: country code}' do
252
- let(:location) { {country: country_code} }
253
- it { expect(views.keys).to eq [country_code] }
254
- end
255
- end
256
-
257
- context 'and grouped by state' do
258
- let(:by) { :state }
259
-
260
- context 'with the :in option set to the country code' do
261
- let(:location) { country_code }
262
- it { expect(views.keys.map(&:length).uniq).to eq [2] }
263
- end
264
-
265
- context 'with the :in option set to {country: country code}' do
266
- let(:location) { {country: country_code} }
267
- it { expect(views.keys.map(&:length).uniq).to eq [2] }
268
- end
269
- end
270
- end
271
-
272
- describe 'views can be retrieved for a single US state' do
273
- let(:state_code) { 'NY' }
274
- let(:result) { channel.views since: date, by: by, in: location }
275
- let(:date) { 4.days.ago }
276
-
277
- context 'and grouped by day' do
278
- let(:by) { :day }
279
-
280
- context 'with the :in option set to {state: state code}' do
281
- let(:location) { {state: state_code} }
282
- it { expect(result.keys.min).to eq date.to_date }
283
- end
284
-
285
- context 'with the :in option set to {country: "US", state: state code}' do
286
- let(:location) { {country: 'US', state: state_code} }
287
- it { expect(result.keys.min).to eq date.to_date }
288
- end
289
- end
290
-
291
- context 'and grouped by US state' do
292
- let(:by) { :state }
293
-
294
- context 'with the :in option set to {state: state code}' do
295
- let(:location) { {state: state_code} }
296
- it { expect(result.keys).to eq [state_code] }
297
- end
298
-
299
- context 'with the :in option set to {country: "US", state: state code}' do
300
- let(:location) { {country: 'US', state: state_code} }
301
- it { expect(result.keys).to eq [state_code] }
302
- end
303
- end
304
- end
305
-
306
- describe 'views can be grouped by day' do
307
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
308
- let(:keys) { range.values }
309
-
310
- specify 'with the :by option set to :day' do
311
- views = channel.views range.merge by: :day
312
- expect(views.keys).to eq range.values
313
- end
314
-
315
- specify 'and are returned chronologically sorted' do
316
- views = channel.views range.merge by: :day
317
- expect(views.keys.sort).to eq views.keys
318
- end
319
- end
320
-
321
- describe 'views can be grouped by traffic source' do
322
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
323
- let(:keys) { Yt::Collections::Reports::TRAFFIC_SOURCES.keys }
324
-
325
- specify 'with the :by option set to :traffic_source' do
326
- views = channel.views range.merge by: :traffic_source
327
- expect(views.keys - keys).to be_empty
328
- end
329
-
330
- specify 'and are returned sorted by descending views' do
331
- views = channel.views range.merge by: :traffic_source
332
- expect(views.values.sort.reverse).to eq views.values
333
- end
334
- end
335
-
336
- describe 'views can be grouped by playback location' do
337
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
338
- let(:keys) { Yt::Collections::Reports::PLAYBACK_LOCATIONS.keys }
339
-
340
- specify 'with the :by option set to :playback_location' do
341
- views = channel.views range.merge by: :playback_location
342
- expect(views.keys - keys).to be_empty
343
- end
344
-
345
- specify 'and are returned sorted by descending views' do
346
- views = channel.views range.merge by: :playback_location
347
- expect(views.values.sort.reverse).to eq views.values
348
- end
349
- end
350
-
351
- describe 'views can be grouped by embedded player location' do
352
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
353
-
354
- specify 'with the :by option set to :embedded_player_location' do
355
- views = channel.views range.merge by: :embedded_player_location
356
- expect(views).not_to be_empty
357
- end
358
- end
359
-
360
- describe 'views can be grouped by related video' do
361
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
362
-
363
- specify 'with the :by option set to :related_video' do
364
- views = channel.views range.merge by: :related_video
365
- expect(views.keys).to all(be_instance_of Yt::Video)
366
- end
367
-
368
- specify 'and provided with an :includes option to preload parts' do
369
- views = channel.views range.merge by: :related_video, includes: [:statistics]
370
- expect(views.keys.map{|v| v.instance_variable_defined? :@status}).to all(be false)
371
- expect(views.keys.map{|v| v.instance_variable_defined? :@statistics_set}).to all(be true)
372
- end
373
- end
374
-
375
- describe 'views can be grouped by search term' do
376
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
377
-
378
- specify 'with the :by option set to :search_term' do
379
- views = channel.views range.merge by: :search_term
380
- expect(views.keys).to all(be_a String)
381
- end
382
- end
383
-
384
- describe 'views can be grouped by referrer' do
385
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
386
-
387
- specify 'with the :by option set to :referrer' do
388
- views = channel.views range.merge by: :referrer
389
- expect(views.keys).to all(be_a String)
390
- end
391
- end
392
-
393
- describe 'views can be grouped by video' do
394
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
395
-
396
- specify 'with the :by option set to :video' do
397
- views = channel.views range.merge by: :video
398
- expect(views.keys).to all(be_instance_of Yt::Video)
399
- end
400
-
401
- specify 'and provided with an :includes option to preload parts' do
402
- views = channel.views range.merge by: :video, includes: [:statistics]
403
- expect(views.keys.map{|v| v.instance_variable_defined? :@status}).to all(be false)
404
- expect(views.keys.map{|v| v.instance_variable_defined? :@statistics_set}).to all(be true)
405
- end
406
- end
407
-
408
- describe 'views can be grouped by playlist' do
409
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
410
-
411
- specify 'with the :by option set to :playlist' do
412
- views = channel.views range.merge by: :playlist
413
- expect(views.keys).to all(be_instance_of Yt::Playlist)
414
- end
415
-
416
- specify 'and provided with an :includes option to preload parts' do
417
- views = channel.views range.merge by: :playlist, includes: [:status]
418
- expect(views.keys.map{|playlist| playlist.instance_variable_defined? :@content_details}).to all(be false)
419
- expect(views.keys.map{|playlist| playlist.instance_variable_defined? :@status}).to all(be true)
420
- end
421
- end
422
-
423
- describe 'views can be grouped by device type' do
424
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
425
-
426
- specify 'with the :by option set to :device_type' do
427
- views = channel.views range.merge by: :device_type
428
- expect(views.keys).to all(be_instance_of Symbol)
429
- expect(views.values).to all(be_an Integer)
430
- end
431
-
432
- specify 'and are returned sorted by descending views' do
433
- views = channel.views range.merge by: :device_type
434
- expect(views.values.sort.reverse).to eq views.values
435
- end
436
- end
437
-
438
- describe 'views can be grouped by country' do
439
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
440
-
441
- specify 'with the :by option set to :country' do
442
- views = channel.views range.merge by: :country
443
- expect(views.keys).to all(be_a String)
444
- expect(views.keys.map(&:length).uniq).to eq [2]
445
- expect(views.values).to all(be_an Integer)
446
- end
447
-
448
- specify 'and are returned sorted by descending views' do
449
- views = channel.views range.merge by: :country
450
- expect(views.values.sort.reverse).to eq views.values
451
- end
452
- end
453
-
454
- describe 'views can be grouped by state' do
455
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
456
-
457
- specify 'with the :by option set to :state' do
458
- views = channel.views range.merge by: :state
459
- expect(views.keys).to all(be_a String)
460
- expect(views.keys.map(&:length).uniq).to eq [2]
461
- expect(views.values).to all(be_an Integer)
462
- end
463
-
464
- specify 'and are returned sorted by descending views' do
465
- views = channel.views range.merge by: :state
466
- expect(views.values.sort.reverse).to eq views.values
467
- end
468
- end
469
-
470
- describe 'views can be limited to a subset of videos' do
471
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
472
- let(:videos) { channel.videos.first(2) }
473
- let(:video_views) { videos.inject(0){|total, video| total + video.views(range)[:total]} }
474
-
475
- specify 'with the :videos option listing the video IDs' do
476
- views = channel.views range.merge videos: videos.map(&:id)
477
- expect(views[:total]).to eq video_views
478
- end
479
-
480
- specify 'with a maximum of 200 video IDs' do
481
- views = channel.views range.merge videos: (videos*100).map(&:id)
482
- expect(views[:total]).to eq video_views
483
- end
484
-
485
- specify 'but fails with more than 200 video IDs' do
486
- expect{channel.views range.merge videos: (videos*101).map(&:id)}.to raise_error Yt::Errors::RequestError
487
- end
488
- end
489
-
490
- describe 'comments can be retrieved for a single country' do
491
- let(:country_code) { 'US' }
492
- let(:comments) { channel.comments since: date, by: by, in: location }
493
- let(:date) { 4.days.ago }
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(comments.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(comments.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(comments.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(comments.keys).to eq [country_code] }
520
- end
521
- end
522
- end
523
-
524
- describe 'comments can be grouped by day' do
525
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
526
- let(:keys) { range.values }
527
-
528
- specify 'with the :by option set to :day' do
529
- comments = channel.comments range.merge by: :day
530
- expect(comments.keys).to eq range.values
531
- end
532
- end
533
-
534
- describe 'comments can be grouped by country' do
535
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
536
-
537
- specify 'with the :by option set to :country' do
538
- comments = channel.comments range.merge by: :country
539
- expect(comments.keys).to all(be_a String)
540
- expect(comments.keys.map(&:length).uniq).to eq [2]
541
- expect(comments.values).to all(be_an Integer)
542
- end
543
- end
544
-
545
- describe 'likes can be retrieved for a single country' do
546
- let(:country_code) { 'US' }
547
- let(:likes) { channel.likes since: date, by: by, in: location }
548
- let(:date) { 4.days.ago }
549
-
550
- context 'and grouped by day' do
551
- let(:by) { :day }
552
-
553
- context 'with the :in option set to the country code' do
554
- let(:location) { country_code }
555
- it { expect(likes.keys.min).to eq date.to_date }
556
- end
557
-
558
- context 'with the :in option set to {country: country code}' do
559
- let(:location) { {country: country_code} }
560
- it { expect(likes.keys.min).to eq date.to_date }
561
- end
562
- end
563
-
564
- context 'and grouped by country' do
565
- let(:by) { :country }
566
-
567
- context 'with the :in option set to the country code' do
568
- let(:location) { country_code }
569
- it { expect(likes.keys).to eq [country_code] }
570
- end
571
-
572
- context 'with the :in option set to {country: country code}' do
573
- let(:location) { {country: country_code} }
574
- it { expect(likes.keys).to eq [country_code] }
575
- end
576
- end
577
- end
578
-
579
- describe 'likes can be grouped by day' do
580
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
581
- let(:keys) { range.values }
582
-
583
- specify 'with the :by option set to :day' do
584
- likes = channel.likes range.merge by: :day
585
- expect(likes.keys).to eq range.values
586
- end
587
- end
588
-
589
- describe 'likes can be grouped by country' do
590
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
591
-
592
- specify 'with the :by option set to :country' do
593
- likes = channel.likes range.merge by: :country
594
- expect(likes.keys).to all(be_a String)
595
- expect(likes.keys.map(&:length).uniq).to eq [2]
596
- expect(likes.values).to all(be_an Integer)
597
- end
598
- end
599
-
600
- describe 'dislikes can be retrieved for a single country' do
601
- let(:country_code) { 'US' }
602
- let(:dislikes) { channel.dislikes since: date, by: by, in: location }
603
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
604
-
605
- context 'and grouped by day' do
606
- let(:by) { :day }
607
-
608
- context 'with the :in option set to the country code' do
609
- let(:location) { country_code }
610
- it { expect(dislikes.keys.min).to eq date.to_date }
611
- end
612
-
613
- context 'with the :in option set to {country: country code}' do
614
- let(:location) { {country: country_code} }
615
- it { expect(dislikes.keys.min).to eq date.to_date }
616
- end
617
- end
618
-
619
- context 'and grouped by country' do
620
- let(:by) { :country }
621
-
622
- context 'with the :in option set to the country code' do
623
- let(:location) { country_code }
624
- it { expect(dislikes.keys).to eq [country_code] }
625
- end
626
-
627
- context 'with the :in option set to {country: country code}' do
628
- let(:location) { {country: country_code} }
629
- it { expect(dislikes.keys).to eq [country_code] }
630
- end
631
- end
632
- end
633
-
634
- describe 'dislikes can be grouped by day' do
635
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
636
- let(:keys) { range.values }
637
-
638
- specify 'with the :by option set to :day' do
639
- dislikes = channel.dislikes range.merge by: :day
640
- expect(dislikes.keys).to eq range.values
641
- end
642
- end
643
-
644
- describe 'dislikes can be grouped by country' do
645
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
646
-
647
- specify 'with the :by option set to :country' do
648
- dislikes = channel.dislikes range.merge by: :country
649
- expect(dislikes.keys).to all(be_a String)
650
- expect(dislikes.keys.map(&:length).uniq).to eq [2]
651
- expect(dislikes.values).to all(be_an Integer)
652
- end
653
- end
654
-
655
- describe 'shares can be retrieved for a single country' do
656
- let(:country_code) { 'US' }
657
- let(:shares) { channel.shares since: date, by: by, in: location }
658
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
659
-
660
- context 'and grouped by day' do
661
- let(:by) { :day }
662
-
663
- context 'with the :in option set to the country code' do
664
- let(:location) { country_code }
665
- it { expect(shares.keys.min).to eq date.to_date }
666
- end
667
-
668
- context 'with the :in option set to {country: country code}' do
669
- let(:location) { {country: country_code} }
670
- it { expect(shares.keys.min).to eq date.to_date }
671
- end
672
- end
673
-
674
- context 'and grouped by country' do
675
- let(:by) { :country }
676
-
677
- context 'with the :in option set to the country code' do
678
- let(:location) { country_code }
679
- it { expect(shares.keys).to eq [country_code] }
680
- end
681
-
682
- context 'with the :in option set to {country: country code}' do
683
- let(:location) { {country: country_code} }
684
- it { expect(shares.keys).to eq [country_code] }
685
- end
686
- end
687
- end
688
-
689
- describe 'shares can be grouped by day' do
690
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
691
- let(:keys) { range.values }
692
-
693
- specify 'with the :by option set to :day' do
694
- shares = channel.shares range.merge by: :day
695
- expect(shares.keys).to eq range.values
696
- end
697
- end
698
-
699
- describe 'shares can be grouped by country' do
700
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
701
-
702
- specify 'with the :by option set to :country' do
703
- shares = channel.shares range.merge by: :country
704
- expect(shares.keys).to all(be_a String)
705
- expect(shares.keys.map(&:length).uniq).to eq [2]
706
- expect(shares.values).to all(be_an Integer)
707
- end
708
- end
709
-
710
- describe 'gained subscribers can be retrieved for a single country' do
711
- let(:country_code) { 'US' }
712
- let(:subscribers_gained) { channel.subscribers_gained since: date, by: by, in: location }
713
- let(:date) { 4.days.ago }
714
-
715
- context 'and grouped by day' do
716
- let(:by) { :day }
717
-
718
- context 'with the :in option set to the country code' do
719
- let(:location) { country_code }
720
- it { expect(subscribers_gained.keys.min).to eq date.to_date }
721
- end
722
-
723
- context 'with the :in option set to {country: country code}' do
724
- let(:location) { {country: country_code} }
725
- it { expect(subscribers_gained.keys.min).to eq date.to_date }
726
- end
727
- end
728
-
729
- context 'and grouped by country' do
730
- let(:by) { :country }
731
-
732
- context 'with the :in option set to the country code' do
733
- let(:location) { country_code }
734
- it { expect(subscribers_gained.keys).to eq [country_code] }
735
- end
736
-
737
- context 'with the :in option set to {country: country code}' do
738
- let(:location) { {country: country_code} }
739
- it { expect(subscribers_gained.keys).to eq [country_code] }
740
- end
741
- end
742
- end
743
-
744
- describe 'gained subscribers can be grouped by day' do
745
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
746
- let(:keys) { range.values }
747
-
748
- specify 'with the :by option set to :day' do
749
- subscribers_gained = channel.subscribers_gained range.merge by: :day
750
- expect(subscribers_gained.keys).to eq range.values
751
- end
752
- end
753
-
754
- describe 'gained subscribers can be grouped by country' do
755
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
756
-
757
- specify 'with the :by option set to :country' do
758
- subscribers_gained = channel.subscribers_gained range.merge by: :country
759
- expect(subscribers_gained.keys).to all(be_a String)
760
- expect(subscribers_gained.keys.map(&:length).uniq).to eq [2]
761
- expect(subscribers_gained.values).to all(be_an Integer)
762
- end
763
- end
764
-
765
- describe 'lost subscribers can be retrieved for a single country' do
766
- let(:country_code) { 'US' }
767
- let(:subscribers_lost) { channel.subscribers_lost since: date, by: by, in: location }
768
- let(:date) { 4.days.ago }
769
-
770
- context 'and grouped by day' do
771
- let(:by) { :day }
772
-
773
- context 'with the :in option set to the country code' do
774
- let(:location) { country_code }
775
- it { expect(subscribers_lost.keys.min).to eq date.to_date }
776
- end
777
-
778
- context 'with the :in option set to {country: country code}' do
779
- let(:location) { {country: country_code} }
780
- it { expect(subscribers_lost.keys.min).to eq date.to_date }
781
- end
782
- end
783
-
784
- context 'and grouped by country' do
785
- let(:by) { :country }
786
-
787
- context 'with the :in option set to the country code' do
788
- let(:location) { country_code }
789
- it { expect(subscribers_lost.keys).to eq [country_code] }
790
- end
791
-
792
- context 'with the :in option set to {country: country code}' do
793
- let(:location) { {country: country_code} }
794
- it { expect(subscribers_lost.keys).to eq [country_code] }
795
- end
796
- end
797
- end
798
-
799
- describe 'lost subscribers can be grouped by day' do
800
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
801
- let(:keys) { range.values }
802
-
803
- specify 'with the :by option set to :day' do
804
- subscribers_lost = channel.subscribers_lost range.merge by: :day
805
- expect(subscribers_lost.keys).to eq range.values
806
- end
807
- end
808
-
809
- describe 'lost subscribers can be grouped by country' do
810
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
811
-
812
- specify 'with the :by option set to :country' do
813
- subscribers_lost = channel.subscribers_lost range.merge by: :country
814
- expect(subscribers_lost.keys).to all(be_a String)
815
- expect(subscribers_lost.keys.map(&:length).uniq).to eq [2]
816
- expect(subscribers_lost.values).to all(be_an Integer)
817
- end
818
- end
819
-
820
- describe 'videos added to playlists can be retrieved for a single country' do
821
- let(:country_code) { 'US' }
822
- let(:videos_added_to_playlists) { channel.videos_added_to_playlists since: date, by: by, in: location }
823
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
824
-
825
- context 'and grouped by day' do
826
- let(:by) { :day }
827
-
828
- context 'with the :in option set to the country code' do
829
- let(:location) { country_code }
830
- it { expect(videos_added_to_playlists.keys.min).to eq date.to_date }
831
- end
832
-
833
- context 'with the :in option set to {country: country code}' do
834
- let(:location) { {country: country_code} }
835
- it { expect(videos_added_to_playlists.keys.min).to eq date.to_date }
836
- end
837
- end
838
-
839
- context 'and grouped by country' do
840
- let(:by) { :country }
841
-
842
- context 'with the :in option set to the country code' do
843
- let(:location) { country_code }
844
- it { expect(videos_added_to_playlists.keys).to eq [country_code] }
845
- end
846
-
847
- context 'with the :in option set to {country: country code}' do
848
- let(:location) { {country: country_code} }
849
- it { expect(videos_added_to_playlists.keys).to eq [country_code] }
850
- end
851
- end
852
- end
853
-
854
- describe 'videos removed from playlists can be retrieved for a single country' do
855
- let(:country_code) { 'US' }
856
- let(:videos_removed_from_playlists) { channel.videos_removed_from_playlists since: date, by: by, in: location }
857
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
858
-
859
- context 'and grouped by day' do
860
- let(:by) { :day }
861
-
862
- context 'with the :in option set to the country code' do
863
- let(:location) { country_code }
864
- it { expect(videos_removed_from_playlists.keys.min).to eq date.to_date }
865
- end
866
-
867
- context 'with the :in option set to {country: country code}' do
868
- let(:location) { {country: country_code} }
869
- it { expect(videos_removed_from_playlists.keys.min).to eq date.to_date }
870
- end
871
- end
872
-
873
- context 'and grouped by country' do
874
- let(:by) { :country }
875
-
876
- context 'with the :in option set to the country code' do
877
- let(:location) { country_code }
878
- it { expect(videos_removed_from_playlists.keys).to eq [country_code] }
879
- end
880
-
881
- context 'with the :in option set to {country: country code}' do
882
- let(:location) { {country: country_code} }
883
- it { expect(videos_removed_from_playlists.keys).to eq [country_code] }
884
- end
885
- end
886
- end
887
-
888
- describe 'estimated minutes watched can be retrieved for a single country' do
889
- let(:country_code) { 'US' }
890
- let(:estimated_minutes_watched) { channel.estimated_minutes_watched since: date, by: by, in: location }
891
- let(:date) { 4.days.ago }
892
-
893
- context 'and grouped by day' do
894
- let(:by) { :day }
895
-
896
- context 'with the :in option set to the country code' do
897
- let(:location) { country_code }
898
- it { expect(estimated_minutes_watched.keys.min).to eq date.to_date }
899
- end
900
-
901
- context 'with the :in option set to {country: country code}' do
902
- let(:location) { {country: country_code} }
903
- it { expect(estimated_minutes_watched.keys.min).to eq date.to_date }
904
- end
905
- end
906
-
907
- context 'and grouped by country' do
908
- let(:by) { :country }
909
-
910
- context 'with the :in option set to the country code' do
911
- let(:location) { country_code }
912
- it { expect(estimated_minutes_watched.keys).to eq [country_code] }
913
- end
914
-
915
- context 'with the :in option set to {country: country code}' do
916
- let(:location) { {country: country_code} }
917
- it { expect(estimated_minutes_watched.keys).to eq [country_code] }
918
- end
919
- end
920
- end
921
-
922
- describe 'estimated minutes watched can be retrieved for a single US state' do
923
- let(:state_code) { 'NY' }
924
- let(:result) { channel.estimated_minutes_watched since: date, by: by, in: location }
925
- let(:date) { 4.days.ago }
926
-
927
- context 'and grouped by day' do
928
- let(:by) { :day }
929
-
930
- context 'with the :in option set to {state: state code}' do
931
- let(:location) { {state: state_code} }
932
- it { expect(result.keys.min).to eq date.to_date }
933
- end
934
-
935
- context 'with the :in option set to {country: "US", state: state code}' do
936
- let(:location) { {country: 'US', state: state_code} }
937
- it { expect(result.keys.min).to eq date.to_date }
938
- end
939
- end
940
-
941
- context 'and grouped by US state' do
942
- let(:by) { :state }
943
-
944
- context 'with the :in option set to {state: state code}' do
945
- let(:location) { {state: state_code} }
946
- it { expect(result.keys).to eq [state_code] }
947
- end
948
-
949
- context 'with the :in option set to {country: "US", state: state code}' do
950
- let(:location) { {country: 'US', state: state_code} }
951
- it { expect(result.keys).to eq [state_code] }
952
- end
953
- end
954
- end
955
-
956
- describe 'estimated minutes watched can be grouped by day' do
957
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
958
- let(:keys) { range.values }
959
-
960
- specify 'with the :by option set to :day' do
961
- estimated_minutes_watched = channel.estimated_minutes_watched range.merge by: :day
962
- expect(estimated_minutes_watched.keys).to eq range.values
963
- end
964
- end
965
-
966
- describe 'estimated minutes watched can be grouped by traffic source' do
967
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
968
- let(:keys) { Yt::Collections::Reports::TRAFFIC_SOURCES.keys }
969
-
970
- specify 'with the :by option set to :traffic_source' do
971
- estimated_minutes_watched = channel.estimated_minutes_watched range.merge by: :traffic_source
972
- expect(estimated_minutes_watched.keys - keys).to be_empty
973
- end
974
- end
975
-
976
- describe 'estimated minutes watched can be grouped by playback location' do
977
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
978
- let(:keys) { Yt::Collections::Reports::PLAYBACK_LOCATIONS.keys }
979
-
980
- specify 'with the :by option set to :playback_location' do
981
- estimated_minutes_watched = channel.estimated_minutes_watched range.merge by: :playback_location
982
- expect(estimated_minutes_watched.keys - keys).to be_empty
983
- end
984
- end
985
-
986
- describe 'estimated minutes watched can be grouped by embedded player location' do
987
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
988
-
989
- specify 'with the :by option set to :embedded_player_location' do
990
- estimated_minutes_watched = channel.estimated_minutes_watched range.merge by: :embedded_player_location
991
- expect(estimated_minutes_watched).not_to be_empty
992
- end
993
- end
994
-
995
- describe 'estimated minutes watched can be grouped by related video' do
996
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
997
-
998
- specify 'with the :by option set to :related_video' do
999
- estimated_minutes_watched = channel.estimated_minutes_watched range.merge by: :related_video
1000
- expect(estimated_minutes_watched.keys).to all(be_instance_of Yt::Video)
1001
- end
1002
- end
1003
-
1004
- describe 'estimated minutes watched can be grouped by search term' do
1005
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
1006
-
1007
- specify 'with the :by option set to :search_term' do
1008
- estimated_minutes_watched = channel.estimated_minutes_watched range.merge by: :search_term
1009
- expect(estimated_minutes_watched.keys).to all(be_a String)
1010
- end
1011
- end
1012
-
1013
- describe 'estimated minutes watched can be grouped by referrer' do
1014
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
1015
-
1016
- specify 'with the :by option set to :referrer' do
1017
- estimated_minutes_watched = channel.estimated_minutes_watched range.merge by: :referrer
1018
- expect(estimated_minutes_watched.keys).to all(be_a String)
1019
- end
1020
- end
1021
-
1022
- describe 'estimated minutes watched can be grouped by video' do
1023
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
1024
-
1025
- specify 'with the :by option set to :video' do
1026
- estimated_minutes_watched = channel.estimated_minutes_watched range.merge by: :video
1027
- expect(estimated_minutes_watched.keys).to all(be_instance_of Yt::Video)
1028
- end
1029
- end
1030
-
1031
- describe 'estimated minutes watched can be grouped by playlist' do
1032
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
1033
-
1034
- specify 'with the :by option set to :playlist' do
1035
- estimated_minutes_watched = channel.estimated_minutes_watched range.merge by: :playlist
1036
- expect(estimated_minutes_watched.keys).to all(be_instance_of Yt::Playlist)
1037
- end
1038
- end
1039
-
1040
- describe 'estimated minutes watched can be grouped by device type' do
1041
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
1042
-
1043
- specify 'with the :by option set to :device_type' do
1044
- estimated_minutes_watched = channel.estimated_minutes_watched range.merge by: :device_type
1045
- expect(estimated_minutes_watched.keys).to all(be_instance_of Symbol)
1046
- expect(estimated_minutes_watched.values).to all(be_an Integer)
1047
- end
1048
- end
1049
-
1050
- describe 'estimated minutes watched can be grouped by country' do
1051
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
1052
-
1053
- specify 'with the :by option set to :country' do
1054
- minutes = channel.estimated_minutes_watched range.merge by: :country
1055
- expect(minutes.keys).to all(be_a String)
1056
- expect(minutes.keys.map(&:length).uniq).to eq [2]
1057
- expect(minutes.values).to all(be_an Integer)
1058
- end
1059
- end
1060
-
1061
- describe 'estimated minutes watched can be grouped by state' do
1062
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
1063
-
1064
- specify 'with the :by option set to :state' do
1065
- minutes = channel.estimated_minutes_watched range.merge by: :state
1066
- expect(minutes.keys).to all(be_a String)
1067
- expect(minutes.keys.map(&:length).uniq).to eq [2]
1068
- expect(minutes.values).to all(be_an Integer)
1069
- end
1070
- end
1071
-
1072
- describe 'average view duration can be retrieved for a single country' do
1073
- let(:country_code) { 'US' }
1074
- let(:average_view_duration) { channel.average_view_duration since: date, by: by, in: location }
1075
- let(:date) { 4.days.ago }
1076
-
1077
- context 'and grouped by day' do
1078
- let(:by) { :day }
1079
-
1080
- context 'with the :in option set to the country code' do
1081
- let(:location) { country_code }
1082
- it { expect(average_view_duration.keys.min).to eq date.to_date }
1083
- end
1084
-
1085
- context 'with the :in option set to {country: country code}' do
1086
- let(:location) { {country: country_code} }
1087
- it { expect(average_view_duration.keys.min).to eq date.to_date }
1088
- end
1089
- end
1090
-
1091
- context 'and grouped by country' do
1092
- let(:by) { :country }
1093
-
1094
- context 'with the :in option set to the country code' do
1095
- let(:location) { country_code }
1096
- it { expect(average_view_duration.keys).to eq [country_code] }
1097
- end
1098
-
1099
- context 'with the :in option set to {country: country code}' do
1100
- let(:location) { {country: country_code} }
1101
- it { expect(average_view_duration.keys).to eq [country_code] }
1102
- end
1103
- end
1104
- end
1105
-
1106
- describe 'average view duration can be retrieved for a single US state' do
1107
- let(:state_code) { 'NY' }
1108
- let(:result) { channel.average_view_duration 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 {state: state code}' do
1115
- let(:location) { {state: state_code} }
1116
- it { expect(result.keys.min).to eq date.to_date }
1117
- end
1118
-
1119
- context 'with the :in option set to {country: "US", state: state code}' do
1120
- let(:location) { {country: 'US', state: state_code} }
1121
- it { expect(result.keys.min).to eq date.to_date }
1122
- end
1123
- end
1124
-
1125
- context 'and grouped by US state' do
1126
- let(:by) { :state }
1127
-
1128
- context 'with the :in option set to {state: state code}' do
1129
- let(:location) { {state: state_code} }
1130
- it { expect(result.keys).to eq [state_code] }
1131
- end
1132
-
1133
- context 'with the :in option set to {country: "US", state: state code}' do
1134
- let(:location) { {country: 'US', state: state_code} }
1135
- it { expect(result.keys).to eq [state_code] }
1136
- end
1137
- end
1138
- end
1139
-
1140
- describe 'average view duration can be grouped by day' do
1141
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
1142
- let(:keys) { range.values }
1143
-
1144
- specify 'with the :by option set to :day' do
1145
- average_view_duration = channel.average_view_duration range.merge by: :day
1146
- expect(average_view_duration.keys).to eq range.values
1147
- end
1148
- end
1149
-
1150
- describe 'average view duration can be grouped by country' do
1151
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
1152
-
1153
- specify 'with the :by option set to :country' do
1154
- duration = channel.average_view_duration range.merge by: :country
1155
- expect(duration.keys).to all(be_a String)
1156
- expect(duration.keys.map(&:length).uniq).to eq [2]
1157
- expect(duration.values).to all(be_an Integer)
1158
- end
1159
- end
1160
-
1161
- describe 'average view duration can be grouped by state' do
1162
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
1163
-
1164
- specify 'with the :by option set to :state' do
1165
- duration = channel.average_view_duration range.merge by: :state
1166
- expect(duration.keys).to all(be_a String)
1167
- expect(duration.keys.map(&:length).uniq).to eq [2]
1168
- expect(duration.values).to all(be_an Integer)
1169
- end
1170
- end
1171
-
1172
- describe 'average view percentage can be retrieved for a single country' do
1173
- let(:country_code) { 'US' }
1174
- let(:average_view_percentage) { channel.average_view_percentage since: date, by: by, in: location }
1175
- let(:date) { 4.days.ago }
1176
-
1177
- context 'and grouped by day' do
1178
- let(:by) { :day }
1179
-
1180
- context 'with the :in option set to the country code' do
1181
- let(:location) { country_code }
1182
- it { expect(average_view_percentage.keys.min).to eq date.to_date }
1183
- end
1184
-
1185
- context 'with the :in option set to {country: country code}' do
1186
- let(:location) { {country: country_code} }
1187
- it { expect(average_view_percentage.keys.min).to eq date.to_date }
1188
- end
1189
- end
1190
-
1191
- context 'and grouped by country' do
1192
- let(:by) { :country }
1193
-
1194
- context 'with the :in option set to the country code' do
1195
- let(:location) { country_code }
1196
- it { expect(average_view_percentage.keys).to eq [country_code] }
1197
- end
1198
-
1199
- context 'with the :in option set to {country: country code}' do
1200
- let(:location) { {country: country_code} }
1201
- it { expect(average_view_percentage.keys).to eq [country_code] }
1202
- end
1203
- end
1204
- end
1205
-
1206
- describe 'average view percentage can be retrieved for a single US state' do
1207
- let(:state_code) { 'NY' }
1208
- let(:result) { channel.average_view_percentage since: date, by: by, in: location }
1209
- let(:date) { 4.days.ago }
1210
-
1211
- context 'and grouped by day' do
1212
- let(:by) { :day }
1213
-
1214
- context 'with the :in option set to {state: state code}' do
1215
- let(:location) { {state: state_code} }
1216
- it { expect(result.keys.min).to eq date.to_date }
1217
- end
1218
-
1219
- context 'with the :in option set to {country: "US", state: state code}' do
1220
- let(:location) { {country: 'US', state: state_code} }
1221
- it { expect(result.keys.min).to eq date.to_date }
1222
- end
1223
- end
1224
-
1225
- context 'and grouped by US state' do
1226
- let(:by) { :state }
1227
-
1228
- context 'with the :in option set to {state: state code}' do
1229
- let(:location) { {state: state_code} }
1230
- it { expect(result.keys).to eq [state_code] }
1231
- end
1232
-
1233
- context 'with the :in option set to {country: "US", state: state code}' do
1234
- let(:location) { {country: 'US', state: state_code} }
1235
- it { expect(result.keys).to eq [state_code] }
1236
- end
1237
- end
1238
- end
1239
-
1240
- describe 'average view percentage can be grouped by day' do
1241
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
1242
- let(:keys) { range.values }
1243
-
1244
- specify 'with the :by option set to :day' do
1245
- average_view_percentage = channel.average_view_percentage range.merge by: :day
1246
- expect(average_view_percentage.keys).to eq range.values
1247
- end
1248
- end
1249
-
1250
- describe 'average view percentage can be grouped by country' do
1251
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
1252
-
1253
- specify 'with the :by option set to :country' do
1254
- percentage = channel.average_view_percentage range.merge by: :country
1255
- expect(percentage.keys).to all(be_a String)
1256
- expect(percentage.keys.map(&:length).uniq).to eq [2]
1257
- expect(percentage.values).to all(be_a Float)
1258
- end
1259
- end
1260
-
1261
- describe 'average view percentage can be grouped by state' do
1262
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
1263
-
1264
- specify 'with the :by option set to :state' do
1265
- percentage = channel.average_view_percentage range.merge by: :state
1266
- expect(percentage.keys).to all(be_a String)
1267
- expect(percentage.keys.map(&:length).uniq).to eq [2]
1268
- expect(percentage.values).to all(be_a Float)
1269
- end
1270
- end
1271
-
1272
- describe 'ad_impressions can be retrieved for a single country' do
1273
- let(:country_code) { 'US' }
1274
- let(:ad_impressions) { channel.ad_impressions since: date, by: by, in: location }
1275
- let(:date) { ENV['YT_TEST_PARTNER_PLAYLIST_DATE'] }
1276
-
1277
- context 'and grouped by day' do
1278
- let(:by) { :day }
1279
-
1280
- context 'with the :in option set to the country code' do
1281
- let(:location) { country_code }
1282
- it { expect(ad_impressions.keys.min).to eq date.to_date }
1283
- end
1284
-
1285
- context 'with the :in option set to {country: country code}' do
1286
- let(:location) { {country: country_code} }
1287
- it { expect(ad_impressions.keys.min).to eq date.to_date }
1288
- end
1289
- end
1290
-
1291
- context 'and grouped by country' do
1292
- let(:by) { :country }
1293
-
1294
- context 'with the :in option set to the country code' do
1295
- let(:location) { country_code }
1296
- it { expect(ad_impressions.keys).to eq [country_code] }
1297
- end
1298
-
1299
- context 'with the :in option set to {country: country code}' do
1300
- let(:location) { {country: country_code} }
1301
- it { expect(ad_impressions.keys).to eq [country_code] }
1302
- end
1303
- end
1304
- end
1305
-
1306
- describe 'ad_impressions can be grouped by day' do
1307
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
1308
- let(:keys) { range.values }
1309
-
1310
- specify 'with the :by option set to :day' do
1311
- ad_impressions = channel.ad_impressions range.merge by: :day
1312
- expect(ad_impressions.keys).to eq range.values
1313
- end
1314
- end
1315
-
1316
- describe 'ad_impressions can be grouped by country' do
1317
- let(:range) { {since: ENV['YT_TEST_PARTNER_PLAYLIST_DATE']} }
1318
-
1319
- specify 'with the :by option set to :country' do
1320
- ad_impressions = channel.ad_impressions range.merge by: :country
1321
- expect(ad_impressions.keys).to all(be_a String)
1322
- expect(ad_impressions.keys.map(&:length).uniq).to eq [2]
1323
- expect(ad_impressions.values).to all(be_an Integer)
1324
- end
1325
- end
1326
-
1327
- describe 'monetized playbacks can be retrieved for a single country' do
1328
- let(:country_code) { 'US' }
1329
- let(:monetized_playbacks) { channel.monetized_playbacks since: date, by: by, in: location }
1330
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
1331
-
1332
- context 'and grouped by day' do
1333
- let(:by) { :day }
1334
-
1335
- context 'with the :in option set to the country code' do
1336
- let(:location) { country_code }
1337
- it { expect(monetized_playbacks.keys.min).to eq date.to_date }
1338
- end
1339
-
1340
- context 'with the :in option set to {country: country code}' do
1341
- let(:location) { {country: country_code} }
1342
- it { expect(monetized_playbacks.keys.min).to eq date.to_date }
1343
- end
1344
- end
1345
-
1346
- context 'and grouped by country' do
1347
- let(:by) { :country }
1348
-
1349
- context 'with the :in option set to the country code' do
1350
- let(:location) { country_code }
1351
- it { expect(monetized_playbacks.keys).to eq [country_code] }
1352
- end
1353
-
1354
- context 'with the :in option set to {country: country code}' do
1355
- let(:location) { {country: country_code} }
1356
- it { expect(monetized_playbacks.keys).to eq [country_code] }
1357
- end
1358
- end
1359
- end
1360
-
1361
- describe 'monetized_playbacks can be grouped by day' do
1362
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
1363
- let(:keys) { range.values }
1364
-
1365
- specify 'with the :by option set to :day' do
1366
- monetized_playbacks = channel.monetized_playbacks range.merge by: :day
1367
- expect(monetized_playbacks.keys).to eq range.values
1368
- end
1369
- end
1370
-
1371
- describe 'monetized playbacks can be grouped by country' do
1372
- let(:range) { {since: ENV['YT_TEST_PARTNER_PLAYLIST_DATE']} }
1373
-
1374
- specify 'with the :by option set to :country' do
1375
- playbacks = channel.monetized_playbacks range.merge by: :country
1376
- expect(playbacks.keys).to all(be_a String)
1377
- expect(playbacks.keys.map(&:length).uniq).to eq [2]
1378
- expect(playbacks.values).to all(be_an Integer)
1379
- end
1380
- end
1381
-
1382
- describe 'playback-based CPM can be retrieved for a single country' do
1383
- let(:country_code) { 'US' }
1384
- let(:playback_based_cpm) { channel.playback_based_cpm since: date, by: by, in: location }
1385
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
1386
-
1387
- context 'and grouped by day' do
1388
- let(:by) { :day }
1389
-
1390
- context 'with the :in option set to the country code' do
1391
- let(:location) { country_code }
1392
- it { expect(playback_based_cpm.keys.min).to eq date.to_date }
1393
- end
1394
-
1395
- context 'with the :in option set to {country: country code}' do
1396
- let(:location) { {country: country_code} }
1397
- it { expect(playback_based_cpm.keys.min).to eq date.to_date }
1398
- end
1399
- end
1400
-
1401
- context 'and grouped by country' do
1402
- let(:by) { :country }
1403
-
1404
- context 'with the :in option set to the country code' do
1405
- let(:location) { country_code }
1406
- it { expect(playback_based_cpm.keys).to eq [country_code] }
1407
- end
1408
-
1409
- context 'with the :in option set to {country: country code}' do
1410
- let(:location) { {country: country_code} }
1411
- it { expect(playback_based_cpm.keys).to eq [country_code] }
1412
- end
1413
- end
1414
- end
1415
-
1416
- describe 'playback-based CPM can be grouped by day' do
1417
- let(:range) { {since: 4.days.ago.to_date, until: 3.days.ago.to_date} }
1418
- let(:keys) { range.values }
1419
-
1420
- specify 'with the :by option set to :day' do
1421
- playback_based_cpm = channel.playback_based_cpm range.merge by: :day
1422
- expect(playback_based_cpm.keys).to eq range.values
1423
- end
1424
- end
1425
-
1426
- describe 'playback-based CPM can be grouped by country' do
1427
- let(:range) { {since: ENV['YT_TEST_PARTNER_PLAYLIST_DATE']} }
1428
-
1429
- specify 'with the :by option set to :country' do
1430
- playbacks = channel.playback_based_cpm range.merge by: :country
1431
- expect(playbacks.keys).to all(be_a String)
1432
- expect(playbacks.keys.map(&:length).uniq).to eq [2]
1433
- expect(playbacks.values).to all(be_a Float)
1434
- end
1435
- end
1436
-
1437
- describe 'annotation clicks can be retrieved for a single country' do
1438
- let(:country_code) { 'US' }
1439
- let(:annotation_clicks) { channel.annotation_clicks since: date, by: by, in: location }
1440
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
1441
-
1442
- context 'and grouped by day' do
1443
- let(:by) { :day }
1444
-
1445
- context 'with the :in option set to the country code' do
1446
- let(:location) { country_code }
1447
- it { expect(annotation_clicks.keys.min).to eq date.to_date }
1448
- end
1449
-
1450
- context 'with the :in option set to {country: country code}' do
1451
- let(:location) { {country: country_code} }
1452
- it { expect(annotation_clicks.keys.min).to eq date.to_date }
1453
- end
1454
- end
1455
-
1456
- context 'and grouped by country' do
1457
- let(:by) { :country }
1458
-
1459
- context 'with the :in option set to the country code' do
1460
- let(:location) { country_code }
1461
- it { expect(annotation_clicks.keys).to eq [country_code] }
1462
- end
1463
-
1464
- context 'with the :in option set to {country: country code}' do
1465
- let(:location) { {country: country_code} }
1466
- it { expect(annotation_clicks.keys).to eq [country_code] }
1467
- end
1468
- end
1469
- end
1470
-
1471
- describe 'annotation clicks can be retrieved for a single US state' do
1472
- let(:state_code) { 'NY' }
1473
- let(:result) { channel.annotation_clicks since: date, by: by, in: location }
1474
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
1475
-
1476
- context 'and grouped by day' do
1477
- let(:by) { :day }
1478
-
1479
- context 'with the :in option set to {state: state code}' do
1480
- let(:location) { {state: state_code} }
1481
- it { expect(result.keys.min).to eq date.to_date }
1482
- end
1483
-
1484
- context 'with the :in option set to {country: "US", state: state code}' do
1485
- let(:location) { {country: 'US', state: state_code} }
1486
- it { expect(result.keys.min).to eq date.to_date }
1487
- end
1488
- end
1489
-
1490
- context 'and grouped by US state' do
1491
- let(:by) { :state }
1492
-
1493
- context 'with the :in option set to {state: state code}' do
1494
- let(:location) { {state: state_code} }
1495
- it { expect(result.keys).to eq [state_code] }
1496
- end
1497
-
1498
- context 'with the :in option set to {country: "US", state: state code}' do
1499
- let(:location) { {country: 'US', state: state_code} }
1500
- it { expect(result.keys).to eq [state_code] }
1501
- end
1502
- end
1503
- end
1504
-
1505
- describe 'annotation clicks can be grouped by day' do
1506
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE'], until: Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 5} }
1507
-
1508
- specify 'with the :by option set to :day' do
1509
- annotation_clicks = channel.annotation_clicks range.merge by: :day
1510
- expect(annotation_clicks.values).to all(be_an Integer)
1511
- end
1512
- end
1513
-
1514
- describe 'annotation clicks can be grouped by country' do
1515
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
1516
-
1517
- specify 'with the :by option set to :country' do
1518
- clicks = channel.annotation_clicks range.merge by: :country
1519
- expect(clicks.keys).to all(be_a String)
1520
- expect(clicks.keys.map(&:length).uniq).to eq [2]
1521
- expect(clicks.values).to all(be_an Integer)
1522
- end
1523
- end
1524
-
1525
- describe 'annotation clicks can be grouped by state' do
1526
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
1527
-
1528
- specify 'with the :by option set to :state' do
1529
- clicks = channel.annotation_clicks range.merge by: :state
1530
- expect(clicks.keys).to all(be_a String)
1531
- expect(clicks.keys.map(&:length).uniq).to eq [2]
1532
- expect(clicks.values).to all(be_an Integer)
1533
- end
1534
- end
1535
-
1536
- describe 'annotation click-through rate can be retrieved for a single country' do
1537
- let(:country_code) { 'US' }
1538
- let(:annotation_click_through_rate) { channel.annotation_click_through_rate since: date, by: by, in: location }
1539
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
1540
-
1541
- context 'and grouped by day' do
1542
- let(:by) { :day }
1543
-
1544
- context 'with the :in option set to the country code' do
1545
- let(:location) { country_code }
1546
- it { expect(annotation_click_through_rate.keys.min).to eq date.to_date }
1547
- end
1548
-
1549
- context 'with the :in option set to {country: country code}' do
1550
- let(:location) { {country: country_code} }
1551
- it { expect(annotation_click_through_rate.keys.min).to eq date.to_date }
1552
- end
1553
- end
1554
-
1555
- context 'and grouped by country' do
1556
- let(:by) { :country }
1557
-
1558
- context 'with the :in option set to the country code' do
1559
- let(:location) { country_code }
1560
- it { expect(annotation_click_through_rate.keys).to eq [country_code] }
1561
- end
1562
-
1563
- context 'with the :in option set to {country: country code}' do
1564
- let(:location) { {country: country_code} }
1565
- it { expect(annotation_click_through_rate.keys).to eq [country_code] }
1566
- end
1567
- end
1568
- end
1569
-
1570
- describe 'annotation click-through rate can be retrieved for a single US state' do
1571
- let(:state_code) { 'NY' }
1572
- let(:result) { channel.annotation_click_through_rate since: date, by: by, in: location }
1573
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
1574
-
1575
- context 'and grouped by day' do
1576
- let(:by) { :day }
1577
-
1578
- context 'with the :in option set to {state: state code}' do
1579
- let(:location) { {state: state_code} }
1580
- it { expect(result.keys.min).to eq date.to_date }
1581
- end
1582
-
1583
- context 'with the :in option set to {country: "US", state: state code}' do
1584
- let(:location) { {country: 'US', state: state_code} }
1585
- it { expect(result.keys.min).to eq date.to_date }
1586
- end
1587
- end
1588
-
1589
- context 'and grouped by US state' do
1590
- let(:by) { :state }
1591
-
1592
- context 'with the :in option set to {state: state code}' do
1593
- let(:location) { {state: state_code} }
1594
- it { expect(result.keys).to eq [state_code] }
1595
- end
1596
-
1597
- context 'with the :in option set to {country: "US", state: state code}' do
1598
- let(:location) { {country: 'US', state: state_code} }
1599
- it { expect(result.keys).to eq [state_code] }
1600
- end
1601
- end
1602
- end
1603
-
1604
- describe 'annotation click-through rate can be grouped by day' do
1605
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE'], until: Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 5} }
1606
-
1607
- specify 'with the :by option set to :day' do
1608
- annotation_click_through_rate = channel.annotation_click_through_rate range.merge by: :day
1609
- expect(annotation_click_through_rate.values).to all(be_instance_of Float)
1610
- end
1611
- end
1612
-
1613
- describe 'annotation click-through rate can be grouped by country' do
1614
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
1615
-
1616
- specify 'with the :by option set to :country' do
1617
- rate = channel.annotation_click_through_rate range.merge by: :country
1618
- expect(rate.keys).to all(be_a String)
1619
- expect(rate.keys.map(&:length).uniq).to eq [2]
1620
- expect(rate.values).to all(be_a Float)
1621
- end
1622
- end
1623
-
1624
- describe 'annotation click-through rate can be grouped by state' do
1625
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE']} }
1626
-
1627
- specify 'with the :by option set to :state' do
1628
- rate = channel.annotation_click_through_rate range.merge by: :state
1629
- expect(rate.keys).to all(be_a String)
1630
- expect(rate.keys.map(&:length).uniq).to eq [2]
1631
- expect(rate.values).to all(be_a Float)
1632
- end
1633
- end
1634
-
1635
- describe 'annotation close rate can be retrieved for a single country' do
1636
- let(:country_code) { 'US' }
1637
- let(:annotation_close_rate) { channel.annotation_close_rate since: date, by: by, in: location }
1638
- let(:date) { 4.days.ago }
1639
-
1640
- context 'and grouped by day' do
1641
- let(:by) { :day }
1642
-
1643
- context 'with the :in option set to the country code' do
1644
- let(:location) { country_code }
1645
- it { expect(annotation_close_rate.keys.min).to eq date.to_date }
1646
- end
1647
-
1648
- context 'with the :in option set to {country: country code}' do
1649
- let(:location) { {country: country_code} }
1650
- it { expect(annotation_close_rate.keys.min).to eq date.to_date }
1651
- end
1652
- end
1653
-
1654
- context 'and grouped by country' do
1655
- let(:by) { :country }
1656
-
1657
- context 'with the :in option set to the country code' do
1658
- let(:location) { country_code }
1659
- it { expect(annotation_close_rate.keys).to eq [country_code] }
1660
- end
1661
-
1662
- context 'with the :in option set to {country: country code}' do
1663
- let(:location) { {country: country_code} }
1664
- it { expect(annotation_close_rate.keys).to eq [country_code] }
1665
- end
1666
- end
1667
- end
1668
-
1669
- describe 'annotation close rate can be retrieved for a single US state' do
1670
- let(:state_code) { 'NY' }
1671
- let(:result) { channel.annotation_close_rate since: date, by: by, in: location }
1672
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
1673
-
1674
- context 'and grouped by day' do
1675
- let(:by) { :day }
1676
-
1677
- context 'with the :in option set to {state: state code}' do
1678
- let(:location) { {state: state_code} }
1679
- it { expect(result.keys.min).to eq date.to_date }
1680
- end
1681
-
1682
- context 'with the :in option set to {country: "US", state: state code}' do
1683
- let(:location) { {country: 'US', state: state_code} }
1684
- it { expect(result.keys.min).to eq date.to_date }
1685
- end
1686
- end
1687
-
1688
- context 'and grouped by US state' do
1689
- let(:by) { :state }
1690
-
1691
- context 'with the :in option set to {state: state code}' do
1692
- let(:location) { {state: state_code} }
1693
- it { expect(result.keys).to eq [state_code] }
1694
- end
1695
-
1696
- context 'with the :in option set to {country: "US", state: state code}' do
1697
- let(:location) { {country: 'US', state: state_code} }
1698
- it { expect(result.keys).to eq [state_code] }
1699
- end
1700
- end
1701
- end
1702
-
1703
- describe 'annotation close rate can be grouped by day' do
1704
- let(:range) { {since: ENV['YT_TEST_PARTNER_VIDEO_DATE'], until: Date.parse(ENV['YT_TEST_PARTNER_VIDEO_DATE']) + 5} }
1705
-
1706
- specify 'with the :by option set to :day' do
1707
- annotation_close_rate = channel.annotation_close_rate range.merge by: :day
1708
- expect(annotation_close_rate.values).to all(be_instance_of Float)
1709
- end
1710
- end
1711
-
1712
- describe 'annotation close rate can be grouped by country' do
1713
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
1714
-
1715
- specify 'with the :by option set to :country' do
1716
- rate = channel.annotation_close_rate range.merge by: :country
1717
- expect(rate.keys).to all(be_a String)
1718
- expect(rate.keys.map(&:length).uniq).to eq [2]
1719
- expect(rate.values).to all(be_a Float)
1720
- end
1721
- end
1722
-
1723
- describe 'annotation close rate can be grouped by state' do
1724
- let(:range) { {since: 4.days.ago, until: 3.days.ago} }
1725
-
1726
- specify 'with the :by option set to :state' do
1727
- rate = channel.annotation_close_rate range.merge by: :state
1728
- expect(rate.keys).to all(be_a String)
1729
- expect(rate.keys.map(&:length).uniq).to eq [2]
1730
- expect(rate.values).to all(be_a Float)
1731
- end
1732
- end
1733
-
1734
- describe 'viewer percentage can be retrieved for a single country' do
1735
- let(:country_code) { 'US' }
1736
- let(:viewer_percentage) { channel.viewer_percentage in: location }
1737
-
1738
- context 'with the :in option set to the country code' do
1739
- let(:location) { country_code }
1740
- it { expect(viewer_percentage.keys).to match_array [:female, :male] }
1741
- end
1742
-
1743
- context 'with the :in option set to {country: country code}' do
1744
- let(:location) { {country: country_code} }
1745
- it { expect(viewer_percentage.keys).to match_array [:female, :male] }
1746
- end
1747
- end
1748
-
1749
- describe 'viewer percentage can be retrieved for a single US state' do
1750
- let(:state_code) { 'TX' }
1751
- let(:viewer_percentage) { channel.viewer_percentage since: date, in: location }
1752
- let(:date) { ENV['YT_TEST_PARTNER_VIDEO_DATE'] }
1753
-
1754
- context 'with the :in option set to {state: state code}' do
1755
- let(:location) { {state: state_code} }
1756
- it {expect(viewer_percentage.keys).to match_array [:female, :male] }
1757
- end
1758
-
1759
- context 'with the :in option set to {country: "US", state: state code}' do
1760
- let(:location) { {country: 'US', state: state_code} }
1761
- it { expect(viewer_percentage.keys).to match_array [:female, :male] }
1762
- end
1763
- end
1764
-
1765
- describe 'viewer percentage can be retrieved for a range of days' do
1766
- let(:viewer_percentage) { channel.viewer_percentage since: 1.year.ago, until: 10.days.ago}
1767
- it { expect(viewer_percentage).to be_a Hash }
1768
- end
1769
-
1770
- describe 'viewer_percentage can be grouped by gender and age group' do
1771
- let(:range) { {since: 1.year.ago.to_date, until: 1.week.ago.to_date} }
1772
- let(:keys) { range.values }
1773
-
1774
- specify 'without a :by option (default)' do
1775
- viewer_percentage = channel.viewer_percentage range
1776
- expect(viewer_percentage.keys).to match_array [:female, :male]
1777
- expect(viewer_percentage[:female].keys - %w(65- 35-44 45-54 13-17 25-34 55-64 18-24)).to be_empty
1778
- expect(viewer_percentage[:female].values).to all(be_instance_of Float)
1779
- expect(viewer_percentage[:male].keys - %w(65- 35-44 45-54 13-17 25-34 55-64 18-24)).to be_empty
1780
- expect(viewer_percentage[:male].values).to all(be_instance_of Float)
1781
- end
1782
-
1783
- specify 'with the :by option set to :gender_age_group' do
1784
- viewer_percentage = channel.viewer_percentage range.merge by: :gender_age_group
1785
- expect(viewer_percentage.keys).to match_array [:female, :male]
1786
- expect(viewer_percentage[:female].keys - %w(65- 35-44 45-54 13-17 25-34 55-64 18-24)).to be_empty
1787
- expect(viewer_percentage[:female].values).to all(be_instance_of Float)
1788
- expect(viewer_percentage[:male].keys - %w(65- 35-44 45-54 13-17 25-34 55-64 18-24)).to be_empty
1789
- expect(viewer_percentage[:male].values).to all(be_instance_of Float)
1790
- end
1791
- end
1792
-
1793
- describe 'viewer_percentage can be grouped by gender' do
1794
- let(:range) { {since: 1.year.ago.to_date, until: 1.week.ago.to_date} }
1795
- let(:keys) { range.values }
1796
-
1797
- specify 'with the :by option set to :gender' do
1798
- viewer_percentage = channel.viewer_percentage range.merge by: :gender
1799
- expect(viewer_percentage.keys).to match_array [:female, :male]
1800
- expect(viewer_percentage[:female]).to be_a Float
1801
- expect(viewer_percentage[:male]).to be_a Float
1802
- end
1803
- end
1804
-
1805
- describe 'viewer_percentage can be grouped by age group' do
1806
- let(:range) { {since: 1.year.ago.to_date, until: 1.week.ago.to_date} }
1807
- let(:keys) { range.values }
1808
-
1809
- specify 'with the :by option set to :age_group' do
1810
- viewer_percentage = channel.viewer_percentage range.merge by: :age_group
1811
- expect(viewer_percentage.keys - %w(65- 35-44 45-54 13-17 25-34 55-64 18-24)).to be_empty
1812
- expect(viewer_percentage.values).to all(be_instance_of Float)
1813
- end
1814
- end
1815
-
1816
- specify 'information about its content owner can be retrieved' do
1817
- expect(channel.content_owner).to be_a String
1818
- expect(channel.linked_at).to be_a Time
1819
- end
1820
- end
1821
-
1822
- context 'not managed by the authenticated Content Owner' do
1823
- let(:id) { 'UCBR8-60-B28hp2BmDPdntcQ' }
1824
-
1825
- specify 'estimated_revenue and ad_impressions cannot be retrieved' do
1826
- expect{channel.estimated_revenue}.to raise_error Yt::Errors::Forbidden
1827
- expect{channel.views}.to raise_error Yt::Errors::Forbidden
1828
- end
1829
-
1830
- specify 'information about its content owner cannot be retrieved' do
1831
- expect(channel.content_owner).to be_nil
1832
- expect(channel.linked_at).to be_nil
1833
- end
1834
- end
1835
- end
1836
- end