brainzz 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4029a83f6655a6ed4e07fa351388d48a8e208e4
4
- data.tar.gz: 22f043f05acfb95f5a1f017943b935527af00c6b
3
+ metadata.gz: 1b5f82f5036c28151473f2fcebbffc4f602748de
4
+ data.tar.gz: 205663e5cbe802ead27977f180dc1ce55b940e77
5
5
  SHA512:
6
- metadata.gz: d7f6c8c8f6393af9000337b113769d5dd494896a69d3ed8223eb9d22620790e6b4ec0b3f96ca3bff6b457076e5a09b89e5a8f918945d124b8d9fbee934d68811
7
- data.tar.gz: a27e765087a0ecde171d15a31c884ec97689f667e0bedf7f63b73b1d86b118031199f3c517751868a4e927b0ecfcad39ef1207f15bb6a5a9f00afa0364436a9a
6
+ metadata.gz: 7b464322f717393ab637cf9fd3f8022a38d7d9c6ee824b161ab6edb751fc55ae36e51383a4fd96ed10737f9de69f809ddc959520260d70434871a9a8f117be02
7
+ data.tar.gz: f7dccc5ae1fb0ac178c6d6d7ddf07db73126d57a958c0578d2dfde0d0e3a2843ffceb6ce0019f655fa21d6ccab615bd4ead0936460f72e36bd31fb3f47f27e74
data/README.md CHANGED
@@ -25,6 +25,7 @@ Check `config/dotenv/test.env` for the required keys.
25
25
  The values in this file are required environment variables
26
26
  when consuming this gem.
27
27
 
28
+
28
29
  Environment Variables
29
30
  ---------------------
30
31
  Brainzz requires the use of multiple environment variables:
@@ -37,12 +38,15 @@ Brainzz requires the use of multiple environment variables:
37
38
 
38
39
  Place values in `config/dotenv/integration.env`.
39
40
 
41
+
40
42
  ### Attaining BRAINZZ_GOOGLE_API_KEY
41
43
 
42
44
  Follow the instructions [here][atv-wiki-google-api-key]
43
45
  to find the required values.
44
46
 
47
+
45
48
  ### Attaining BRAINZZ_REFRESH_TOKEN
49
+
46
50
  An OAUTH refresh token for the BRAINZZ_CONTENT_OWNER Google account
47
51
  uses BRAINZZ_CLIENT_SECRET and BRAINZZ_CLIENT_SECRET
48
52
 
@@ -58,8 +62,10 @@ uses BRAINZZ_CLIENT_SECRET and BRAINZZ_CLIENT_SECRET
58
62
  - Exchange code for tokens
59
63
  - Grab value for the Refresh Token and store
60
64
 
65
+
61
66
  Interface
62
67
  ---------
68
+
63
69
  All public endpoints are exposed in Brainzz::Core.
64
70
 
65
71
  Every response from the public API is wrapped in a `Response` object
@@ -104,9 +110,10 @@ and video objects as the values.
104
110
 
105
111
  #### Parameters
106
112
 
107
- * video id (String)
108
- * start date (DateTime)
109
- * end date (DateTime)
113
+ * video ids (Array[String])
114
+ * start date (DateTime)
115
+ * end date (DateTime)
116
+
110
117
 
111
118
  #### Result
112
119
 
@@ -130,236 +137,300 @@ corresponding to the following YouTube referrals:
130
137
 
131
138
  The constants are defined in `Brainzz::ViewCountEnum`.
132
139
 
140
+
133
141
  ### view_totals_for
134
142
 
135
143
  #### Parameters
144
+
136
145
  Same as views_by_day_for.
137
146
 
147
+
138
148
  #### Result
149
+
139
150
  Same as views_by_day_for except date values are nil.
140
151
 
141
152
  Views for date range are aggregated per source type.
142
153
 
154
+
143
155
  ### likes_by_day_for
144
156
 
145
157
  #### Parameters
146
158
 
147
- * video id (String)
148
- * start date (DateTime)
149
- * end date (DateTime)
159
+ * video ids (Array[String])
160
+ * start date (DateTime)
161
+ * end date (DateTime)
162
+
150
163
 
151
164
  #### Result
152
165
 
153
166
  An array of `Brainzz::LikeCount` objects ordered by date in ascending order.
154
167
 
168
+
155
169
  ### like_totals_for
156
170
 
157
171
  #### Parameters
172
+
158
173
  Same as likes_by_day_for.
159
174
 
175
+
160
176
  #### Result
177
+
161
178
  Same as likes_by_day_for except date values are nil.
162
179
 
163
180
  Likes for date range are aggregated.
164
181
 
182
+
165
183
  ### shares_by_day_for
166
184
 
167
185
  #### Parameters
168
186
 
169
- * video id (String)
170
- * start date (DateTime)
171
- * end date (DateTime)
187
+ * video ids (Array[String])
188
+ * start date (DateTime)
189
+ * end date (DateTime)
190
+
172
191
 
173
192
  #### Result
174
193
 
175
194
  An array of `Brainzz::ShareCount` objects ordered by date in ascending order.
176
195
 
196
+
177
197
  ### share_totals_for
178
198
 
179
199
  #### Parameters
200
+
180
201
  Same as shares_by_day_for.
181
202
 
182
203
  #### Result
204
+
183
205
  Same as shares_by_day_for except date values are nil.
184
206
 
185
207
  Shares for date range are aggregated.
186
208
 
209
+
187
210
  ### dislikes_by_day_for
188
211
 
189
212
  #### Parameters
190
213
 
191
- * video id (String)
192
- * start date (DateTime)
193
- * end date (DateTime)
214
+ * video ids (Array[String])
215
+ * start date (DateTime)
216
+ * end date (DateTime)
217
+
194
218
 
195
219
  #### Result
196
220
 
197
221
  An array of `Brainzz::DislikeCount` objects ordered by date in ascending order.
198
222
 
223
+
199
224
  ### dislike_totals_for
200
225
 
201
226
  #### Parameters
227
+
202
228
  Same as dislikes_by_day_for.
203
229
 
230
+
204
231
  #### Result
232
+
205
233
  Same as dislikes_by_day_for except date values are nil.
206
234
 
207
235
  Dislikes for date range are aggregated.
208
236
 
237
+
209
238
  ### comments_by_day_for
210
239
 
211
240
  #### Parameters
212
241
 
213
- * video id (String)
214
- * start date (DateTime)
215
- * end date (DateTime)
242
+ * video ids (Array[String])
243
+ * start date (DateTime)
244
+ * end date (DateTime)
245
+
216
246
 
217
247
  #### Result
218
248
 
219
249
  An array of `Brainzz::CommentCount` objects ordered by date in ascending order.
220
250
 
251
+
221
252
  ### comment_totals_for
222
253
 
223
254
  #### Parameters
255
+
224
256
  Same as comments_by_day_for.
225
257
 
258
+
226
259
  #### Result
260
+
227
261
  Same as comments_by_day_for except date values are nil.
228
262
 
229
263
  Comments for date range are aggregated.
230
264
 
265
+
231
266
  ### subscribers_gained_by_day_for
232
267
 
233
268
  #### Parameters
234
269
 
235
- * video id (String)
236
- * start date (DateTime)
237
- * end date (DateTime)
270
+ * video ids (Array[String])
271
+ * start date (DateTime)
272
+ * end date (DateTime)
273
+
238
274
 
239
275
  #### Result
240
276
 
241
277
  An array of `Brainzz::SubscribersGainedCount` objects ordered by date in ascending order.
242
278
 
279
+
243
280
  ### subscribers_gained_totals_for
244
281
 
245
282
  #### Parameters
283
+
246
284
  Same as subscribers_gained_by_day_for.
247
285
 
286
+
248
287
  #### Result
288
+
249
289
  Same as subscribers_gained_by_day_for except date values are nil.
250
290
 
251
291
  SubscribersGained for date range are aggregated.
252
292
 
293
+
253
294
  ### subscribers_lost_by_day_for
254
295
 
255
296
  #### Parameters
256
297
 
257
- * video id (String)
258
- * start date (DateTime)
259
- * end date (DateTime)
298
+ * video ids (Array[String])
299
+ * start date (DateTime)
300
+ * end date (DateTime)
301
+
260
302
 
261
303
  #### Result
262
304
 
263
305
  An array of `Brainzz::SubscribersLostCount` objects ordered by date in ascending order.
264
306
 
307
+
265
308
  ### subscribers_lost_totals_for
266
309
 
267
310
  #### Parameters
311
+
268
312
  Same as subscribers_lost_by_day_for.
269
313
 
314
+
270
315
  #### Result
316
+
271
317
  Same as subscribers_lost_by_day_for except date values are nil.
272
318
 
273
319
  SubscribersLost for date range are aggregated.
274
320
 
321
+
275
322
  ### annotations_clickable_by_day_for
276
323
 
277
324
  #### Parameters
278
325
 
279
- * video id (String)
280
- * start date (DateTime)
281
- * end date (DateTime)
326
+ * video ids (Array[String])
327
+ * start date (DateTime)
328
+ * end date (DateTime)
329
+
282
330
 
283
331
  #### Result
284
332
 
285
333
  An array of `Brainzz::AnnotationsClickableCount` objects ordered by date in ascending order.
286
334
 
335
+
287
336
  ### annotations_clickable_totals_for
288
337
 
289
338
  #### Parameters
339
+
290
340
  Same as annotations_clickable_by_day_for.
291
341
 
342
+
292
343
  #### Result
344
+
293
345
  Same as annotations_clickable_by_day_for except date values are nil.
294
346
 
295
347
  AnnotationsClickable for date range are aggregated.
296
348
 
349
+
297
350
  ### annotations_clicked_by_day_for
298
351
 
299
352
  #### Parameters
300
353
 
301
- * video id (String)
302
- * start date (DateTime)
303
- * end date (DateTime)
354
+ * video ids (Array[String])
355
+ * start date (DateTime)
356
+ * end date (DateTime)
357
+
304
358
 
305
359
  #### Result
306
360
 
307
361
  An array of `Brainzz::AnnotationsClickedCount` objects ordered by date in ascending order.
308
362
 
363
+
309
364
  ### annotations_clicked_totals_for
310
365
 
311
366
  #### Parameters
367
+
312
368
  Same as annotations_clicked_by_day_for.
313
369
 
370
+
314
371
  #### Result
372
+
315
373
  Same as annotations_clicked_by_day_for except date values are nil.
316
374
 
317
375
  AnnotationsClicked for date range are aggregated.
318
376
 
377
+
319
378
  ### view_percentages_by_day_for
320
379
 
321
380
  #### Parameters
322
381
 
323
- * video id (String)
324
- * start date (DateTime)
325
- * end date (DateTime)
382
+ * video ids (Array[String])
383
+ * start date (DateTime)
384
+ * end date (DateTime)
385
+
326
386
 
327
387
  #### Result
328
388
 
329
389
  An array of `Brainzz::ViewPercentage` objects ordered by date in ascending order.
330
390
 
391
+
331
392
  ### view_percentage_totals_for
332
393
 
333
394
  #### Parameters
395
+
334
396
  Same as view_percentages_by_day_for.
335
397
 
398
+
336
399
  #### Result
400
+
337
401
  Same as view_percentages_by_day_for except date values are nil.
338
402
 
339
403
  ViewPercentages for date range are aggregated.
340
404
 
405
+
341
406
  ### view_durations_by_day_for
342
407
 
343
408
  #### Parameters
344
409
 
345
- * video id (String)
346
- * start date (DateTime)
347
- * end date (DateTime)
410
+ * video ids (Array[String])
411
+ * start date (DateTime)
412
+ * end date (DateTime)
413
+
348
414
 
349
415
  #### Result
350
416
 
351
417
  An array of `Brainzz::ViewDuration` objects ordered by date in ascending order.
352
418
 
419
+
353
420
  ### view_duration_totals_for
354
421
 
355
422
  #### Parameters
423
+
356
424
  Same as view_durations_by_day_for.
357
425
 
426
+
358
427
  #### Result
428
+
359
429
  Same as view_durations_by_day_for except date values are nil.
360
430
 
361
431
  ViewDurations for date range are aggregated.
362
432
 
433
+
363
434
  Factories
364
435
  ---------
365
436
 
@@ -36,6 +36,10 @@ module Brainzz
36
36
  })
37
37
  end
38
38
 
39
+ def dimensions
40
+ super << 'video'
41
+ end
42
+
39
43
  def content_owner
40
44
  ENV['BRAINZZ_CONTENT_OWNER']
41
45
  end
@@ -18,7 +18,9 @@ module Brainzz
18
18
  end
19
19
 
20
20
  def params(parameters = nil)
21
- {}
21
+ params = {}
22
+ params['dimensions'] = dimensions.join(',') unless dimensions.empty?
23
+ params
22
24
  end
23
25
 
24
26
  def headers
@@ -27,6 +29,10 @@ module Brainzz
27
29
  }
28
30
  end
29
31
 
32
+ def dimensions
33
+ []
34
+ end
35
+
30
36
  def url(parameters)
31
37
  connection.build_url endpoint, params(parameters)
32
38
  end
@@ -2,10 +2,13 @@ module Brainzz
2
2
  module VideoStatsByDayCommand
3
3
  private
4
4
 
5
+ def dimensions
6
+ super << 'day'
7
+ end
8
+
5
9
  def params(video_stats_params)
6
10
  super.merge({
7
- 'dimensions' => 'day',
8
- 'sort' => 'day',
11
+ 'sort' => 'day',
9
12
  })
10
13
  end
11
14
  end
@@ -3,9 +3,9 @@ module Brainzz
3
3
  class << self
4
4
  private
5
5
 
6
- def on_execute(video_id, start_date, end_date)
7
- video_stats_params = VideoStatsParams.new ({
8
- :video_id => video_id,
6
+ def on_execute(video_ids, start_date, end_date)
7
+ video_stats_params = VideoStatsParams.new({
8
+ :video_ids => video_ids,
9
9
  :start_date => start_date,
10
10
  :end_date => end_date,
11
11
  })
@@ -23,7 +23,7 @@ module Brainzz
23
23
 
24
24
  def params(video_stats_params)
25
25
  super.merge({
26
- 'filters' => "video==#{video_stats_params.video_id}",
26
+ 'filters' => "video==#{video_stats_params.video_ids.join(',')}",
27
27
  })
28
28
  end
29
29
  end
@@ -1,17 +1,6 @@
1
1
  module Brainzz
2
2
  class ViewCountByDayCommand < ViewTotalsCommand
3
3
  extend VideoStatsByDayCommand
4
-
5
4
  make_with_response ViewCountResponse
6
-
7
- class << self
8
- private
9
-
10
- def params(video_stats_params)
11
- super.merge({
12
- 'dimensions' => 'day,insightTrafficSourceType',
13
- })
14
- end
15
- end
16
5
  end
17
6
  end
@@ -5,10 +5,13 @@ module Brainzz
5
5
  class << self
6
6
  private
7
7
 
8
+ def dimensions
9
+ super << 'insightTrafficSourceType'
10
+ end
11
+
8
12
  def params(video_stats_params)
9
13
  super.merge({
10
- 'metrics' => 'views',
11
- 'dimensions' => 'insightTrafficSourceType',
14
+ 'metrics' => 'views',
12
15
  })
13
16
  end
14
17
  end
@@ -10,92 +10,92 @@ module Brainzz
10
10
  VideoDetailsCommand.execute video_ids, options
11
11
  end
12
12
 
13
- def views_by_day_for(video_id, start_date, end_date)
14
- ViewCountByDayCommand.execute video_id, start_date, end_date
13
+ def views_by_day_for(video_ids, start_date, end_date)
14
+ ViewCountByDayCommand.execute video_ids, start_date, end_date
15
15
  end
16
16
 
17
- def view_totals_for(video_id, start_date, end_date)
18
- ViewTotalsCommand.execute video_id, start_date, end_date
17
+ def view_totals_for(video_ids, start_date, end_date)
18
+ ViewTotalsCommand.execute video_ids, start_date, end_date
19
19
  end
20
20
 
21
- def likes_by_day_for(video_id, start_date, end_date)
22
- LikeCountByDayCommand.execute video_id, start_date, end_date
21
+ def likes_by_day_for(video_ids, start_date, end_date)
22
+ LikeCountByDayCommand.execute video_ids, start_date, end_date
23
23
  end
24
24
 
25
- def like_totals_for(video_id, start_date, end_date)
26
- LikeTotalsCommand.execute video_id, start_date, end_date
25
+ def like_totals_for(video_ids, start_date, end_date)
26
+ LikeTotalsCommand.execute video_ids, start_date, end_date
27
27
  end
28
28
 
29
- def shares_by_day_for(video_id, start_date, end_date)
30
- ShareCountByDayCommand.execute video_id, start_date, end_date
29
+ def shares_by_day_for(video_ids, start_date, end_date)
30
+ ShareCountByDayCommand.execute video_ids, start_date, end_date
31
31
  end
32
32
 
33
- def share_totals_for(video_id, start_date, end_date)
34
- ShareTotalsCommand.execute video_id, start_date, end_date
33
+ def share_totals_for(video_ids, start_date, end_date)
34
+ ShareTotalsCommand.execute video_ids, start_date, end_date
35
35
  end
36
36
 
37
- def dislikes_by_day_for(video_id, start_date, end_date)
38
- DislikeCountByDayCommand.execute video_id, start_date, end_date
37
+ def dislikes_by_day_for(video_ids, start_date, end_date)
38
+ DislikeCountByDayCommand.execute video_ids, start_date, end_date
39
39
  end
40
40
 
41
- def dislike_totals_for(video_id, start_date, end_date)
42
- DislikeTotalsCommand.execute video_id, start_date, end_date
41
+ def dislike_totals_for(video_ids, start_date, end_date)
42
+ DislikeTotalsCommand.execute video_ids, start_date, end_date
43
43
  end
44
44
 
45
- def comments_by_day_for(video_id, start_date, end_date)
46
- CommentCountByDayCommand.execute video_id, start_date, end_date
45
+ def comments_by_day_for(video_ids, start_date, end_date)
46
+ CommentCountByDayCommand.execute video_ids, start_date, end_date
47
47
  end
48
48
 
49
- def comment_totals_for(video_id, start_date, end_date)
50
- CommentTotalsCommand.execute video_id, start_date, end_date
49
+ def comment_totals_for(video_ids, start_date, end_date)
50
+ CommentTotalsCommand.execute video_ids, start_date, end_date
51
51
  end
52
52
 
53
- def subscribers_gained_by_day_for(video_id, start_date, end_date)
54
- SubscribersGainedByDayCommand.execute video_id, start_date, end_date
53
+ def subscribers_gained_by_day_for(video_ids, start_date, end_date)
54
+ SubscribersGainedByDayCommand.execute video_ids, start_date, end_date
55
55
  end
56
56
 
57
- def subscribers_gained_totals_for(video_id, start_date, end_date)
58
- SubscribersGainedTotalsCommand.execute video_id, start_date, end_date
57
+ def subscribers_gained_totals_for(video_ids, start_date, end_date)
58
+ SubscribersGainedTotalsCommand.execute video_ids, start_date, end_date
59
59
  end
60
60
 
61
- def subscribers_lost_by_day_for(video_id, start_date, end_date)
62
- SubscribersLostByDayCommand.execute video_id, start_date, end_date
61
+ def subscribers_lost_by_day_for(video_ids, start_date, end_date)
62
+ SubscribersLostByDayCommand.execute video_ids, start_date, end_date
63
63
  end
64
64
 
65
- def subscribers_lost_totals_for(video_id, start_date, end_date)
66
- SubscribersLostTotalsCommand.execute video_id, start_date, end_date
65
+ def subscribers_lost_totals_for(video_ids, start_date, end_date)
66
+ SubscribersLostTotalsCommand.execute video_ids, start_date, end_date
67
67
  end
68
68
 
69
- def annotations_clickable_by_day_for(video_id, start_date, end_date)
70
- AnnotationsClickableByDayCommand.execute video_id, start_date, end_date
69
+ def annotations_clickable_by_day_for(video_ids, start_date, end_date)
70
+ AnnotationsClickableByDayCommand.execute video_ids, start_date, end_date
71
71
  end
72
72
 
73
- def annotations_clickable_totals_for(video_id, start_date, end_date)
74
- AnnotationsClickableTotalsCommand.execute video_id, start_date, end_date
73
+ def annotations_clickable_totals_for(video_ids, start_date, end_date)
74
+ AnnotationsClickableTotalsCommand.execute video_ids, start_date, end_date
75
75
  end
76
76
 
77
- def annotations_clicked_by_day_for(video_id, start_date, end_date)
78
- AnnotationsClickedByDayCommand.execute video_id, start_date, end_date
77
+ def annotations_clicked_by_day_for(video_ids, start_date, end_date)
78
+ AnnotationsClickedByDayCommand.execute video_ids, start_date, end_date
79
79
  end
80
80
 
81
- def annotations_clicked_totals_for(video_id, start_date, end_date)
82
- AnnotationsClickedTotalsCommand.execute video_id, start_date, end_date
81
+ def annotations_clicked_totals_for(video_ids, start_date, end_date)
82
+ AnnotationsClickedTotalsCommand.execute video_ids, start_date, end_date
83
83
  end
84
84
 
85
- def view_percentages_by_day_for(video_id, start_date, end_date)
86
- ViewPercentagesByDayCommand.execute video_id, start_date, end_date
85
+ def view_percentages_by_day_for(video_ids, start_date, end_date)
86
+ ViewPercentagesByDayCommand.execute video_ids, start_date, end_date
87
87
  end
88
88
 
89
- def view_percentage_totals_for(video_id, start_date, end_date)
90
- ViewPercentageTotalsCommand.execute video_id, start_date, end_date
89
+ def view_percentage_totals_for(video_ids, start_date, end_date)
90
+ ViewPercentageTotalsCommand.execute video_ids, start_date, end_date
91
91
  end
92
92
 
93
- def view_durations_by_day_for(video_id, start_date, end_date)
94
- ViewDurationsByDayCommand.execute video_id, start_date, end_date
93
+ def view_durations_by_day_for(video_ids, start_date, end_date)
94
+ ViewDurationsByDayCommand.execute video_ids, start_date, end_date
95
95
  end
96
96
 
97
- def view_duration_totals_for(video_id, start_date, end_date)
98
- ViewDurationTotalsCommand.execute video_id, start_date, end_date
97
+ def view_duration_totals_for(video_ids, start_date, end_date)
98
+ ViewDurationTotalsCommand.execute video_ids, start_date, end_date
99
99
  end
100
100
  end
101
101
  end
@@ -1,7 +1,10 @@
1
1
  FactoryGirl.define do
2
2
  factory :brainzz_annotations_clickable_count,
3
- :class => Brainzz::AnnotationsClickableCount do
3
+ :class => Brainzz::AnnotationsClickableCount do
4
+
5
+ video_id { generate :brainzz_video_id }
4
6
  annotations_clickable { rand(1_000_000) + 1 }
7
+
5
8
  day { Time.parse (DateTime.now - rand(100)).strftime('%F') }
6
9
 
7
10
  factory :brainzz_aggregate_annotations_clickable_count do
@@ -1,8 +1,10 @@
1
1
  FactoryGirl.define do
2
2
  factory :brainzz_annotations_clicked_count,
3
- :class => Brainzz::AnnotationsClickedCount do
3
+ :class => Brainzz::AnnotationsClickedCount do
4
+
5
+ video_id { generate :brainzz_video_id }
4
6
  annotations_clicked { rand(1_000_000) + 1 }
5
- day { Time.parse (DateTime.now - rand(100)).strftime('%F') }
7
+ day { Time.parse (DateTime.now - rand(100)).strftime('%F') }
6
8
 
7
9
  factory :brainzz_aggregate_annotations_clicked_count do
8
10
  day nil
@@ -1,7 +1,8 @@
1
1
  FactoryGirl.define do
2
2
  factory :brainzz_comment_count, :class => Brainzz::CommentCount do
3
+ video_id { generate :brainzz_video_id }
3
4
  comments { rand(1_000_000) + 1 }
4
- day { Time.parse (DateTime.now - rand(100)).strftime('%F') }
5
+ day { Time.parse (DateTime.now - rand(100)).strftime('%F') }
5
6
 
6
7
  factory :brainzz_aggregate_comment_count do
7
8
  day nil
@@ -1,5 +1,6 @@
1
1
  FactoryGirl.define do
2
2
  factory :brainzz_dislike_count, :class => Brainzz::DislikeCount do
3
+ video_id { generate :brainzz_video_id }
3
4
  dislikes { rand(1_000_000) + 1 }
4
5
  day { Time.parse (DateTime.now - rand(100)).strftime('%F') }
5
6
 
@@ -1,7 +1,8 @@
1
1
  FactoryGirl.define do
2
2
  factory :brainzz_like_count, :class => Brainzz::LikeCount do
3
- likes { rand(1_000_000) + 1 }
4
- day { Time.parse (DateTime.now - rand(100)).strftime('%F') }
3
+ video_id { generate :brainzz_video_id }
4
+ likes { rand(1_000_000) + 1 }
5
+ day { Time.parse (DateTime.now - rand(100)).strftime('%F') }
5
6
 
6
7
  factory :brainzz_aggregate_like_count do
7
8
  day nil
@@ -1,7 +1,8 @@
1
1
  FactoryGirl.define do
2
2
  factory :brainzz_share_count, :class => Brainzz::ShareCount do
3
- shares { rand(1_000_000) + 1 }
4
- day { Time.parse (DateTime.now - rand(100)).strftime('%F') }
3
+ video_id { generate :brainzz_video_id }
4
+ shares { rand(1_000_000) + 1 }
5
+ day { Time.parse (DateTime.now - rand(100)).strftime('%F') }
5
6
 
6
7
  factory :brainzz_aggregate_share_count do
7
8
  day nil
@@ -1,6 +1,8 @@
1
1
  FactoryGirl.define do
2
2
  factory :brainzz_subscribers_gained_count,
3
- :class => Brainzz::SubscribersGainedCount do
3
+ :class => Brainzz::SubscribersGainedCount do
4
+
5
+ video_id { generate :brainzz_video_id }
4
6
  subscribers_gained { rand(1_000_000) + 1 }
5
7
  day { Time.parse (DateTime.now - rand(100)).strftime('%F') }
6
8
 
@@ -1,6 +1,8 @@
1
1
  FactoryGirl.define do
2
2
  factory :brainzz_subscribers_lost_count,
3
- :class => Brainzz::SubscribersLostCount do
3
+ :class => Brainzz::SubscribersLostCount do
4
+
5
+ video_id { generate :brainzz_video_id }
4
6
  subscribers_lost { rand(1_000_000) + 1 }
5
7
  day { Time.parse (DateTime.now - rand(100)).strftime('%F') }
6
8
 
@@ -1,8 +1,9 @@
1
1
  FactoryGirl.define do
2
2
  factory :brainzz_view_count, :class => Brainzz::ViewCount do
3
- views { rand(1_000_000) + 1 }
4
- day { Time.parse (DateTime.now - rand(100)).strftime('%F') }
5
- source { generate :brainzz_view_count_source }
3
+ video_id { generate :brainzz_video_id }
4
+ views { rand(1_000_000) + 1 }
5
+ day { Time.parse (DateTime.now - rand(100)).strftime('%F') }
6
+ source { generate :brainzz_view_count_source }
6
7
 
7
8
  factory :brainzz_aggregate_view_count do
8
9
  day nil
@@ -1,7 +1,8 @@
1
1
  FactoryGirl.define do
2
2
  factory :brainzz_view_duration, :class => Brainzz::ViewDuration do
3
+ video_id { generate :brainzz_video_id }
3
4
  duration { rand(1_000_000) + 1 }
4
- day { Time.parse (DateTime.now - rand(100)).strftime('%F') }
5
+ day { Time.parse (DateTime.now - rand(100)).strftime('%F') }
5
6
 
6
7
  factory :brainzz_aggregate_view_duration do
7
8
  day nil
@@ -1,7 +1,8 @@
1
1
  FactoryGirl.define do
2
2
  factory :brainzz_view_percentage, :class => Brainzz::ViewPercentage do
3
+ video_id { generate :brainzz_video_id }
3
4
  percentage { rand(1_000_000) / 10000.0 }
4
- day { Time.parse (DateTime.now - rand(100)).strftime('%F') }
5
+ day { Time.parse (DateTime.now - rand(100)).strftime('%F') }
5
6
 
6
7
  factory :brainzz_aggregate_view_percentage do
7
8
  day nil
@@ -1,11 +1,12 @@
1
1
  module Brainzz
2
2
  class VideoStat < BaseModel
3
- attr_accessor :day
3
+ attr_accessor :day, :video_id
4
4
 
5
5
  def initialize(hash)
6
6
  @hash = hash
7
7
 
8
- @day = transform_date(day_data)
8
+ @day = transform_date(day_data)
9
+ @video_id = transform(video_id_data)
9
10
  end
10
11
 
11
12
  private
@@ -22,6 +23,10 @@ module Brainzz
22
23
  data && keys['day'] && data[keys['day']]
23
24
  end
24
25
 
26
+ def video_id_data
27
+ data && keys['video'] && data[keys['video']]
28
+ end
29
+
25
30
  def normalize_stat(stat)
26
31
  stat.to_i if stat
27
32
  end
@@ -1,14 +1,31 @@
1
1
  module Brainzz
2
2
  class VideoStatsParams < AnalyticsParams
3
- attr_reader :video_id
3
+ attr_reader :video_ids
4
4
 
5
5
  def initialize(params)
6
6
  super
7
- @video_id = normalize(params[:video_id])
7
+ @video_ids = normalize(params[:video_ids])
8
8
  end
9
9
 
10
10
  def valid?
11
- !!(super && video_id)
11
+ !!(super && !video_ids.empty?)
12
+ end
13
+
14
+ private
15
+
16
+ def normalize(video_ids)
17
+ video_ids = [video_ids] if video_ids.is_a?(String)
18
+
19
+ return [] unless video_ids
20
+
21
+ ids = []
22
+
23
+ video_ids.each do |video_id|
24
+ id = super(video_id)
25
+ ids << id if id
26
+ end
27
+
28
+ ids
12
29
  end
13
30
  end
14
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brainzz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Herrick
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-06-24 00:00:00.000000000 Z
13
+ date: 2015-06-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday