brainzz 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +140 -105
- data/lib/brainzz/commands/analytics_command.rb +9 -14
- data/lib/brainzz/commands/base_command.rb +2 -2
- data/lib/brainzz/commands/channel_stats_command.rb +5 -6
- data/lib/brainzz/commands/stats_command.rb +9 -0
- data/lib/brainzz/commands/video_stats_command.rb +6 -7
- data/lib/brainzz/core.rb +123 -68
- data/lib/brainzz/params/analytics_params.rb +4 -2
- data/lib/brainzz/services/access_token_service.rb +23 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 436f5cc534dd86373de4739578b7f8558dda4557
|
4
|
+
data.tar.gz: 0ef21c5db8d8583d7310c1ef555dd23f45c6ea4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71fdb722ac1e459218af3a18cc085279698ab3b049df951aee6ae7a1af56fb9d97bc25245d1ed0c349fbebbdd8a740e1122f4d8269668c8b4cb057bc356fde66
|
7
|
+
data.tar.gz: 8eff3e9d78f0204c646108d48d980f4358882d9286897ba8dd174c30557702e8fe52ddf1af7d4fcdc154ba49d1100dd721debe393bfbee87a7e5d4aa260d372f
|
data/README.md
CHANGED
@@ -28,34 +28,53 @@ when consuming this gem.
|
|
28
28
|
|
29
29
|
Environment Variables
|
30
30
|
---------------------
|
31
|
+
|
32
|
+
### Single Content Owner
|
33
|
+
|
31
34
|
Brainzz requires the use of multiple environment variables:
|
32
|
-
- BRAINZZ_GOOGLE_API_KEY
|
33
|
-
- BRAINZZ_CLIENT_ID
|
34
|
-
- BRAINZZ_CLIENT_SECRET
|
35
|
-
- BRAINZZ_REFRESH_TOKEN
|
36
|
-
- BRAINZZ_CONTENT_OWNER
|
37
|
-
|
35
|
+
- `BRAINZZ_GOOGLE_API_KEY`
|
36
|
+
- `BRAINZZ_CLIENT_ID`
|
37
|
+
- `BRAINZZ_CLIENT_SECRET`
|
38
|
+
- `BRAINZZ_REFRESH_TOKEN`
|
39
|
+
- `BRAINZZ_CONTENT_OWNER`:
|
40
|
+
- the Google account for the CMS that owns the YouTube channel data.
|
38
41
|
|
39
42
|
Place values in `config/dotenv/integration.env`.
|
40
43
|
|
41
44
|
|
42
|
-
###
|
45
|
+
### Multiple Content Owners
|
46
|
+
|
47
|
+
The content owner must be passed in to the Brainzz method.
|
48
|
+
|
49
|
+
Use the environment variables above with the content owner
|
50
|
+
added to it in upper case.
|
51
|
+
Dashes also need to be remvoed.
|
52
|
+
|
53
|
+
For instance, if the content owner is `abc-1234-DEF`,
|
54
|
+
you would use the following variables:
|
55
|
+
|
56
|
+
- `BRAINZZ_CLIENT_ID_ABC1234DEF`
|
57
|
+
- `BRAINZZ_CLIENT_SECRET_ABC1234DEF`
|
58
|
+
- `BRAINZZ_REFRESH_TOKEN_ABC1234DEF`
|
59
|
+
|
60
|
+
|
61
|
+
### Attaining `BRAINZZ_GOOGLE_API_KEY`
|
43
62
|
|
44
63
|
Follow the instructions [here][atv-wiki-google-api-key]
|
45
64
|
to find the required values.
|
46
65
|
|
47
66
|
|
48
|
-
### Attaining BRAINZZ_REFRESH_TOKEN
|
67
|
+
### Attaining `BRAINZZ_REFRESH_TOKEN`
|
49
68
|
|
50
|
-
An OAUTH refresh token for the BRAINZZ_CONTENT_OWNER Google account
|
51
|
-
uses BRAINZZ_CLIENT_SECRET and BRAINZZ_CLIENT_SECRET
|
69
|
+
An OAUTH refresh token for the `BRAINZZ_CONTENT_OWNER` Google account
|
70
|
+
uses `BRAINZZ_CLIENT_SECRET` and `BRAINZZ_CLIENT_SECRET`
|
52
71
|
|
53
72
|
`BRAINZZ_CLIENT_ID` and `BRAINZZ_CLIENT_SECRET`.
|
54
73
|
- Go to the [Google OAuth Playground][google-oauth-playground]
|
55
|
-
- Log in with the Google account for BRAINZZ_CONTENT_OWNER
|
74
|
+
- Log in with the Google account for `BRAINZZ_CONTENT_OWNER`
|
56
75
|
- Click on the gear (upper-right)
|
57
76
|
- Click check box to "Use your own OAuth credentials"
|
58
|
-
- Fill in BRAINZZ_CLIENT_ID and BRAINZZ_CLIENT_SECRET
|
77
|
+
- Fill in `BRAINZZ_CLIENT_ID` and `BRAINZZ_CLIENT_SECRET`
|
59
78
|
- In Step 1 (Select & Authorize APIs) scroll down to YouTube Analytics API v1
|
60
79
|
- Click the last item "yt-analytics.readonly"
|
61
80
|
- Click blue 'Authorize APIs' button
|
@@ -72,7 +91,7 @@ Every response from the public API is wrapped in a `Response` object
|
|
72
91
|
that will always have the same interface regardless of request.
|
73
92
|
The `Response#data` attribute will be an object specific to the data requested.
|
74
93
|
|
75
|
-
### channel_details_for
|
94
|
+
### `channel_details_for`
|
76
95
|
|
77
96
|
Accepts an array of channel ids.
|
78
97
|
The maximum length of the array is determined by YouTube.
|
@@ -82,23 +101,23 @@ and channel objects as the values.
|
|
82
101
|
|
83
102
|
#### Channel Attributes Accessible
|
84
103
|
|
85
|
-
* id
|
86
|
-
* title
|
87
|
-
* published_at
|
88
|
-
* description
|
89
|
-
* uploads_playlist
|
90
|
-
* likes_playlist
|
91
|
-
* google_plus_id
|
92
|
-
* view_count
|
93
|
-
* comment_count
|
94
|
-
* subscriber_count
|
95
|
-
* video_count
|
104
|
+
* `id`
|
105
|
+
* `title`
|
106
|
+
* `published_at`
|
107
|
+
* `description`
|
108
|
+
* `uploads_playlist`
|
109
|
+
* `likes_playlist`
|
110
|
+
* `google_plus_id`
|
111
|
+
* `view_count`
|
112
|
+
* `comment_count`
|
113
|
+
* `subscriber_count`
|
114
|
+
* `video_count`
|
96
115
|
|
97
116
|
#### Parameters
|
98
117
|
|
99
118
|
* channel ids (Array[String])
|
100
119
|
|
101
|
-
### playlist_items_for
|
120
|
+
### `playlist_items_for`
|
102
121
|
|
103
122
|
On first invocation, only a playlist id is required:
|
104
123
|
|
@@ -121,7 +140,7 @@ end
|
|
121
140
|
```
|
122
141
|
|
123
142
|
|
124
|
-
### video_details_for
|
143
|
+
### `video_details_for`
|
125
144
|
|
126
145
|
Accepts an array of video ids.
|
127
146
|
The maximum length of the array is determined by YouTube.
|
@@ -131,7 +150,7 @@ This endpoint returns a hash with video ids as keys
|
|
131
150
|
and video objects as the values.
|
132
151
|
|
133
152
|
|
134
|
-
### views_by_day_for
|
153
|
+
### `views_by_day_for`
|
135
154
|
|
136
155
|
#### Parameters
|
137
156
|
|
@@ -163,27 +182,28 @@ corresponding to the following YouTube referrals:
|
|
163
182
|
The constants are defined in `Brainzz::ViewCountEnum`.
|
164
183
|
|
165
184
|
|
166
|
-
### view_totals_for
|
185
|
+
### `view_totals_for`
|
167
186
|
|
168
187
|
#### Parameters
|
169
188
|
|
170
|
-
Same as views_by_day_for
|
189
|
+
Same as `views_by_day_for`.
|
171
190
|
|
172
191
|
|
173
192
|
#### Result
|
174
193
|
|
175
|
-
Same as views_by_day_for except date values are nil.
|
194
|
+
Same as `views_by_day_for` except date values are nil.
|
176
195
|
|
177
196
|
Views for date range are aggregated per source type.
|
178
197
|
|
179
198
|
|
180
|
-
### likes_by_day_for
|
199
|
+
### `likes_by_day_for`
|
181
200
|
|
182
201
|
#### Parameters
|
183
202
|
|
184
|
-
* video ids
|
185
|
-
* start date
|
186
|
-
* end date
|
203
|
+
* video ids (Array[String])
|
204
|
+
* start date (DateTime)
|
205
|
+
* end date (DateTime)
|
206
|
+
* content owner id (String)
|
187
207
|
|
188
208
|
|
189
209
|
#### Result
|
@@ -191,27 +211,28 @@ Views for date range are aggregated per source type.
|
|
191
211
|
An array of `Brainzz::LikeCount` objects ordered by date in ascending order.
|
192
212
|
|
193
213
|
|
194
|
-
### like_totals_for
|
214
|
+
### `like_totals_for`
|
195
215
|
|
196
216
|
#### Parameters
|
197
217
|
|
198
|
-
Same as likes_by_day_for
|
218
|
+
Same as `likes_by_day_for`.
|
199
219
|
|
200
220
|
|
201
221
|
#### Result
|
202
222
|
|
203
|
-
Same as likes_by_day_for except date values are nil.
|
223
|
+
Same as `likes_by_day_for` except date values are nil.
|
204
224
|
|
205
225
|
Likes for date range are aggregated.
|
206
226
|
|
207
227
|
|
208
|
-
### shares_by_day_for
|
228
|
+
### `shares_by_day_for`
|
209
229
|
|
210
230
|
#### Parameters
|
211
231
|
|
212
|
-
* video ids
|
213
|
-
* start date
|
214
|
-
* end date
|
232
|
+
* video ids (Array[String])
|
233
|
+
* start date (DateTime)
|
234
|
+
* end date (DateTime)
|
235
|
+
* content owner id (String)
|
215
236
|
|
216
237
|
|
217
238
|
#### Result
|
@@ -219,26 +240,28 @@ Likes for date range are aggregated.
|
|
219
240
|
An array of `Brainzz::ShareCount` objects ordered by date in ascending order.
|
220
241
|
|
221
242
|
|
222
|
-
### share_totals_for
|
243
|
+
### `share_totals_for`
|
223
244
|
|
224
245
|
#### Parameters
|
225
246
|
|
226
|
-
Same as shares_by_day_for
|
247
|
+
Same as `shares_by_day_for`.
|
248
|
+
|
227
249
|
|
228
250
|
#### Result
|
229
251
|
|
230
|
-
Same as shares_by_day_for except date values are nil.
|
252
|
+
Same as `shares_by_day_for` except date values are nil.
|
231
253
|
|
232
254
|
Shares for date range are aggregated.
|
233
255
|
|
234
256
|
|
235
|
-
### dislikes_by_day_for
|
257
|
+
### `dislikes_by_day_for`
|
236
258
|
|
237
259
|
#### Parameters
|
238
260
|
|
239
|
-
* video ids
|
240
|
-
* start date
|
241
|
-
* end date
|
261
|
+
* video ids (Array[String])
|
262
|
+
* start date (DateTime)
|
263
|
+
* end date (DateTime)
|
264
|
+
* content owner id (String)
|
242
265
|
|
243
266
|
|
244
267
|
#### Result
|
@@ -246,27 +269,28 @@ Shares for date range are aggregated.
|
|
246
269
|
An array of `Brainzz::DislikeCount` objects ordered by date in ascending order.
|
247
270
|
|
248
271
|
|
249
|
-
### dislike_totals_for
|
272
|
+
### `dislike_totals_for`
|
250
273
|
|
251
274
|
#### Parameters
|
252
275
|
|
253
|
-
Same as dislikes_by_day_for
|
276
|
+
Same as `dislikes_by_day_for`.
|
254
277
|
|
255
278
|
|
256
279
|
#### Result
|
257
280
|
|
258
|
-
Same as dislikes_by_day_for except date values are nil.
|
281
|
+
Same as `dislikes_by_day_for` except date values are nil.
|
259
282
|
|
260
283
|
Dislikes for date range are aggregated.
|
261
284
|
|
262
285
|
|
263
|
-
### comments_by_day_for
|
286
|
+
### `comments_by_day_for`
|
264
287
|
|
265
288
|
#### Parameters
|
266
289
|
|
267
|
-
* video ids
|
268
|
-
* start date
|
269
|
-
* end date
|
290
|
+
* video ids (Array[String])
|
291
|
+
* start date (DateTime)
|
292
|
+
* end date (DateTime)
|
293
|
+
* content owner id (String)
|
270
294
|
|
271
295
|
|
272
296
|
#### Result
|
@@ -274,167 +298,178 @@ Dislikes for date range are aggregated.
|
|
274
298
|
An array of `Brainzz::CommentCount` objects ordered by date in ascending order.
|
275
299
|
|
276
300
|
|
277
|
-
### comment_totals_for
|
301
|
+
### `comment_totals_for`
|
278
302
|
|
279
303
|
#### Parameters
|
280
304
|
|
281
|
-
Same as comments_by_day_for
|
305
|
+
Same as `comments_by_day_for`.
|
282
306
|
|
283
307
|
|
284
308
|
#### Result
|
285
309
|
|
286
|
-
Same as comments_by_day_for except date values are nil.
|
310
|
+
Same as `comments_by_day_for` except date values are nil.
|
287
311
|
|
288
312
|
Comments for date range are aggregated.
|
289
313
|
|
290
314
|
|
291
|
-
### subscribers_gained_by_day_for
|
315
|
+
### `subscribers_gained_by_day_for`
|
292
316
|
|
293
317
|
#### Parameters
|
294
318
|
|
295
|
-
* video ids
|
296
|
-
* start date
|
297
|
-
* end date
|
319
|
+
* video ids (Array[String])
|
320
|
+
* start date (DateTime)
|
321
|
+
* end date (DateTime)
|
322
|
+
* content owner id (String)
|
298
323
|
|
299
324
|
|
300
325
|
#### Result
|
301
326
|
|
302
|
-
An array of `Brainzz::SubscribersGainedCount` objects
|
327
|
+
An array of `Brainzz::SubscribersGainedCount` objects
|
328
|
+
ordered by date in ascending order.
|
303
329
|
|
304
330
|
|
305
|
-
### subscribers_gained_totals_for
|
331
|
+
### `subscribers_gained_totals_for`
|
306
332
|
|
307
333
|
#### Parameters
|
308
334
|
|
309
|
-
Same as subscribers_gained_by_day_for
|
335
|
+
Same as `subscribers_gained_by_day_for`.
|
310
336
|
|
311
337
|
|
312
338
|
#### Result
|
313
339
|
|
314
|
-
Same as subscribers_gained_by_day_for except date values are nil.
|
340
|
+
Same as `subscribers_gained_by_day_for` except date values are nil.
|
315
341
|
|
316
342
|
SubscribersGained for date range are aggregated.
|
317
343
|
|
318
344
|
|
319
|
-
### subscribers_lost_by_day_for
|
345
|
+
### `subscribers_lost_by_day_for`
|
320
346
|
|
321
347
|
#### Parameters
|
322
348
|
|
323
|
-
* video ids
|
324
|
-
* start date
|
325
|
-
* end date
|
349
|
+
* video ids (Array[String])
|
350
|
+
* start date (DateTime)
|
351
|
+
* end date (DateTime)
|
352
|
+
* content owner id (String)
|
326
353
|
|
327
354
|
|
328
355
|
#### Result
|
329
356
|
|
330
|
-
An array of `Brainzz::SubscribersLostCount` objects
|
357
|
+
An array of `Brainzz::SubscribersLostCount` objects
|
358
|
+
ordered by date in ascending order.
|
331
359
|
|
332
360
|
|
333
|
-
### subscribers_lost_totals_for
|
361
|
+
### `subscribers_lost_totals_for`
|
334
362
|
|
335
363
|
#### Parameters
|
336
364
|
|
337
|
-
Same as subscribers_lost_by_day_for
|
365
|
+
Same as `subscribers_lost_by_day_for`.
|
338
366
|
|
339
367
|
|
340
368
|
#### Result
|
341
369
|
|
342
|
-
Same as subscribers_lost_by_day_for except date values are nil.
|
370
|
+
Same as `subscribers_lost_by_day_for` except date values are nil.
|
343
371
|
|
344
372
|
SubscribersLost for date range are aggregated.
|
345
373
|
|
346
374
|
|
347
|
-
### annotations_clickable_by_day_for
|
375
|
+
### `annotations_clickable_by_day_for`
|
348
376
|
|
349
377
|
#### Parameters
|
350
378
|
|
351
|
-
* video ids
|
352
|
-
* start date
|
353
|
-
* end date
|
379
|
+
* video ids (Array[String])
|
380
|
+
* start date (DateTime)
|
381
|
+
* end date (DateTime)
|
382
|
+
* content owner id (String)
|
354
383
|
|
355
384
|
|
356
385
|
#### Result
|
357
386
|
|
358
|
-
An array of `Brainzz::AnnotationsClickableCount` objects
|
387
|
+
An array of `Brainzz::AnnotationsClickableCount` objects
|
388
|
+
ordered by date in ascending order.
|
359
389
|
|
360
390
|
|
361
|
-
### annotations_clickable_totals_for
|
391
|
+
### `annotations_clickable_totals_for`
|
362
392
|
|
363
393
|
#### Parameters
|
364
394
|
|
365
|
-
Same as annotations_clickable_by_day_for
|
395
|
+
Same as `annotations_clickable_by_day_for`.
|
366
396
|
|
367
397
|
|
368
398
|
#### Result
|
369
399
|
|
370
|
-
Same as annotations_clickable_by_day_for except date values are nil.
|
400
|
+
Same as `annotations_clickable_by_day_for` except date values are nil.
|
371
401
|
|
372
402
|
AnnotationsClickable for date range are aggregated.
|
373
403
|
|
374
404
|
|
375
|
-
### annotations_clicked_by_day_for
|
405
|
+
### `annotations_clicked_by_day_for`
|
376
406
|
|
377
407
|
#### Parameters
|
378
408
|
|
379
|
-
* video ids
|
380
|
-
* start date
|
381
|
-
* end date
|
409
|
+
* video ids (Array[String])
|
410
|
+
* start date (DateTime)
|
411
|
+
* end date (DateTime)
|
412
|
+
* content owner id (String)
|
382
413
|
|
383
414
|
|
384
415
|
#### Result
|
385
416
|
|
386
|
-
An array of `Brainzz::AnnotationsClickedCount` objects
|
417
|
+
An array of `Brainzz::AnnotationsClickedCount` objects
|
418
|
+
ordered by date in ascending order.
|
387
419
|
|
388
420
|
|
389
|
-
### annotations_clicked_totals_for
|
421
|
+
### `annotations_clicked_totals_for`
|
390
422
|
|
391
423
|
#### Parameters
|
392
424
|
|
393
|
-
Same as annotations_clicked_by_day_for
|
425
|
+
Same as `annotations_clicked_by_day_for`.
|
394
426
|
|
395
427
|
|
396
428
|
#### Result
|
397
429
|
|
398
|
-
Same as annotations_clicked_by_day_for except date values are nil.
|
430
|
+
Same as `annotations_clicked_by_day_for` except date values are nil.
|
399
431
|
|
400
432
|
AnnotationsClicked for date range are aggregated.
|
401
433
|
|
402
434
|
|
403
|
-
### view_percentages_by_day_for
|
435
|
+
### `view_percentages_by_day_for`
|
404
436
|
|
405
437
|
#### Parameters
|
406
438
|
|
407
|
-
* video ids
|
408
|
-
* start date
|
409
|
-
* end date
|
439
|
+
* video ids (Array[String])
|
440
|
+
* start date (DateTime)
|
441
|
+
* end date (DateTime)
|
442
|
+
* content owner id (String)
|
410
443
|
|
411
444
|
|
412
445
|
#### Result
|
413
446
|
|
414
|
-
An array of `Brainzz::ViewPercentage` objects
|
447
|
+
An array of `Brainzz::ViewPercentage` objects
|
448
|
+
ordered by date in ascending order.
|
415
449
|
|
416
450
|
|
417
|
-
### view_percentage_totals_for
|
451
|
+
### `view_percentage_totals_for`
|
418
452
|
|
419
453
|
#### Parameters
|
420
454
|
|
421
|
-
Same as view_percentages_by_day_for
|
455
|
+
Same as `view_percentages_by_day_for`.
|
422
456
|
|
423
457
|
|
424
458
|
#### Result
|
425
459
|
|
426
|
-
Same as view_percentages_by_day_for except date values are nil.
|
460
|
+
Same as `view_percentages_by_day_for` except date values are nil.
|
427
461
|
|
428
462
|
ViewPercentages for date range are aggregated.
|
429
463
|
|
430
464
|
|
431
|
-
### view_durations_by_day_for
|
465
|
+
### `view_durations_by_day_for`
|
432
466
|
|
433
467
|
#### Parameters
|
434
468
|
|
435
|
-
* video ids
|
436
|
-
* start date
|
437
|
-
* end date
|
469
|
+
* video ids (Array[String])
|
470
|
+
* start date (DateTime)
|
471
|
+
* end date (DateTime)
|
472
|
+
* content owner id (String)
|
438
473
|
|
439
474
|
|
440
475
|
#### Result
|
@@ -442,16 +477,16 @@ ViewPercentages for date range are aggregated.
|
|
442
477
|
An array of `Brainzz::ViewDuration` objects ordered by date in ascending order.
|
443
478
|
|
444
479
|
|
445
|
-
### view_duration_totals_for
|
480
|
+
### `view_duration_totals_for`
|
446
481
|
|
447
482
|
#### Parameters
|
448
483
|
|
449
|
-
Same as view_durations_by_day_for
|
484
|
+
Same as `view_durations_by_day_for`.
|
450
485
|
|
451
486
|
|
452
487
|
#### Result
|
453
488
|
|
454
|
-
Same as view_durations_by_day_for except date values are nil.
|
489
|
+
Same as `view_durations_by_day_for` except date values are nil.
|
455
490
|
|
456
491
|
ViewDurations for date range are aggregated.
|
457
492
|
|
@@ -1,13 +1,6 @@
|
|
1
1
|
module Brainzz
|
2
2
|
class AnalyticsCommand < BaseCommand
|
3
3
|
class << self
|
4
|
-
def execute(*args)
|
5
|
-
local_token = access_token
|
6
|
-
response = super
|
7
|
-
response.scrub local_token, 'ACCESS_TOKEN'
|
8
|
-
response
|
9
|
-
end
|
10
|
-
|
11
4
|
private
|
12
5
|
|
13
6
|
def base_url
|
@@ -18,17 +11,21 @@ module Brainzz
|
|
18
11
|
'reports'
|
19
12
|
end
|
20
13
|
|
21
|
-
def headers
|
14
|
+
def headers(parameters)
|
15
|
+
access_token = access_token_for(parameters.content_owner)
|
16
|
+
|
22
17
|
super.merge({
|
23
18
|
'Authorization' => "Bearer #{access_token}",
|
24
19
|
})
|
25
20
|
end
|
26
21
|
|
27
|
-
def
|
28
|
-
AccessTokenService.
|
22
|
+
def access_token_for(content_owner)
|
23
|
+
AccessTokenService.retrieve_token_for content_owner
|
29
24
|
end
|
30
25
|
|
31
26
|
def params(analytics_params)
|
27
|
+
content_owner = content_owner_for(analytics_params.content_owner)
|
28
|
+
|
32
29
|
super.merge({
|
33
30
|
'ids' => "contentOwner==#{content_owner}",
|
34
31
|
'start-date' => analytics_params.start_date,
|
@@ -36,13 +33,11 @@ module Brainzz
|
|
36
33
|
})
|
37
34
|
end
|
38
35
|
|
39
|
-
def content_owner
|
40
|
-
ENV['BRAINZZ_CONTENT_OWNER']
|
36
|
+
def content_owner_for(content_owner)
|
37
|
+
content_owner || ENV['BRAINZZ_CONTENT_OWNER']
|
41
38
|
end
|
42
39
|
|
43
40
|
def scrub(response)
|
44
|
-
response.scrub access_token, 'ACCESS_TOKEN'
|
45
|
-
response.scrub content_owner, 'CONTENT_OWNER'
|
46
41
|
end
|
47
42
|
end
|
48
43
|
end
|
@@ -10,7 +10,7 @@ module Brainzz
|
|
10
10
|
private
|
11
11
|
|
12
12
|
def get(parameters)
|
13
|
-
connection.get endpoint, params(parameters), headers
|
13
|
+
connection.get endpoint, params(parameters), headers(parameters)
|
14
14
|
end
|
15
15
|
|
16
16
|
def connection
|
@@ -23,7 +23,7 @@ module Brainzz
|
|
23
23
|
params
|
24
24
|
end
|
25
25
|
|
26
|
-
def headers
|
26
|
+
def headers(parameters)
|
27
27
|
{
|
28
28
|
'Content-Type' => 'application/json',
|
29
29
|
}
|
@@ -3,12 +3,11 @@ module Brainzz
|
|
3
3
|
class << self
|
4
4
|
private
|
5
5
|
|
6
|
-
def on_execute(channel_ids, start_date, end_date)
|
7
|
-
channel_stats_params = ChannelStatsParams.new(
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
})
|
6
|
+
def on_execute(channel_ids, start_date, end_date, content_owner)
|
7
|
+
channel_stats_params = ChannelStatsParams.new(
|
8
|
+
params_hash_for(
|
9
|
+
:channel_ids, channel_ids, start_date, end_date, content_owner)
|
10
|
+
)
|
12
11
|
|
13
12
|
make_request_with_params(channel_stats_params)
|
14
13
|
end
|
@@ -3,6 +3,15 @@ module Brainzz
|
|
3
3
|
class << self
|
4
4
|
private
|
5
5
|
|
6
|
+
def params_hash_for(key, ids, start_date, end_date, content_owner_id)
|
7
|
+
{
|
8
|
+
key => ids,
|
9
|
+
:start_date => start_date,
|
10
|
+
:end_date => end_date,
|
11
|
+
:content_owner => content_owner_id,
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
6
15
|
def make_request_with_params(params)
|
7
16
|
if params.valid?
|
8
17
|
@response_class.new get(params)
|
@@ -3,14 +3,13 @@ module Brainzz
|
|
3
3
|
class << self
|
4
4
|
private
|
5
5
|
|
6
|
-
def on_execute(video_ids, start_date, end_date)
|
7
|
-
video_stats_params = VideoStatsParams.new(
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
})
|
6
|
+
def on_execute(video_ids, start_date, end_date, content_owner)
|
7
|
+
video_stats_params = VideoStatsParams.new(
|
8
|
+
params_hash_for(
|
9
|
+
:video_ids, video_ids, start_date, end_date, content_owner)
|
10
|
+
)
|
12
11
|
|
13
|
-
make_request_with_params
|
12
|
+
make_request_with_params video_stats_params
|
14
13
|
end
|
15
14
|
|
16
15
|
def dimensions
|
data/lib/brainzz/core.rb
CHANGED
@@ -14,152 +14,207 @@ module Brainzz
|
|
14
14
|
VideoDetailsCommand.execute video_ids, options
|
15
15
|
end
|
16
16
|
|
17
|
-
def views_by_day_for(
|
18
|
-
|
17
|
+
def views_by_day_for(
|
18
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
19
|
+
ViewCountByDayCommand
|
20
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
19
21
|
end
|
20
22
|
|
21
|
-
def view_totals_for(
|
22
|
-
|
23
|
+
def view_totals_for(
|
24
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
25
|
+
ViewTotalsCommand
|
26
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
23
27
|
end
|
24
28
|
|
25
|
-
def likes_by_day_for(
|
26
|
-
|
29
|
+
def likes_by_day_for(
|
30
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
31
|
+
LikeCountByDayCommand.execute video_ids,
|
32
|
+
start_date, end_date, content_owner_id
|
27
33
|
end
|
28
34
|
|
29
|
-
def like_totals_for(video_ids, start_date, end_date)
|
30
|
-
LikeTotalsCommand.execute video_ids,
|
35
|
+
def like_totals_for(video_ids, start_date, end_date, content_owner_id = nil)
|
36
|
+
LikeTotalsCommand.execute video_ids,
|
37
|
+
start_date, end_date, content_owner_id
|
31
38
|
end
|
32
39
|
|
33
|
-
def shares_by_day_for(
|
34
|
-
|
40
|
+
def shares_by_day_for(
|
41
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
42
|
+
ShareCountByDayCommand
|
43
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
35
44
|
end
|
36
45
|
|
37
|
-
def share_totals_for(
|
38
|
-
|
46
|
+
def share_totals_for(
|
47
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
48
|
+
ShareTotalsCommand
|
49
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
39
50
|
end
|
40
51
|
|
41
|
-
def dislikes_by_day_for(
|
42
|
-
|
52
|
+
def dislikes_by_day_for(
|
53
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
54
|
+
DislikeCountByDayCommand
|
55
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
43
56
|
end
|
44
57
|
|
45
|
-
def dislike_totals_for(
|
46
|
-
|
58
|
+
def dislike_totals_for(
|
59
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
60
|
+
DislikeTotalsCommand
|
61
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
47
62
|
end
|
48
63
|
|
49
|
-
def comments_by_day_for(
|
50
|
-
|
64
|
+
def comments_by_day_for(
|
65
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
66
|
+
CommentCountByDayCommand
|
67
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
51
68
|
end
|
52
69
|
|
53
|
-
def comment_totals_for(
|
54
|
-
|
70
|
+
def comment_totals_for(
|
71
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
72
|
+
CommentTotalsCommand
|
73
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
55
74
|
end
|
56
75
|
|
57
|
-
def subscribers_gained_by_day_for(
|
58
|
-
|
76
|
+
def subscribers_gained_by_day_for(
|
77
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
78
|
+
SubscribersGainedByDayCommand
|
79
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
59
80
|
end
|
60
81
|
|
61
|
-
def subscribers_gained_totals_for(
|
62
|
-
|
82
|
+
def subscribers_gained_totals_for(
|
83
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
84
|
+
SubscribersGainedTotalsCommand
|
85
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
63
86
|
end
|
64
87
|
|
65
|
-
def subscribers_lost_by_day_for(
|
66
|
-
|
88
|
+
def subscribers_lost_by_day_for(
|
89
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
90
|
+
SubscribersLostByDayCommand
|
91
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
67
92
|
end
|
68
93
|
|
69
|
-
def subscribers_lost_totals_for(
|
70
|
-
|
94
|
+
def subscribers_lost_totals_for(
|
95
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
96
|
+
SubscribersLostTotalsCommand
|
97
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
71
98
|
end
|
72
99
|
|
73
|
-
def annotations_clickable_by_day_for(
|
74
|
-
|
100
|
+
def annotations_clickable_by_day_for(
|
101
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
102
|
+
AnnotationsClickableByDayCommand
|
103
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
75
104
|
end
|
76
105
|
|
77
|
-
def annotations_clickable_totals_for(
|
78
|
-
|
106
|
+
def annotations_clickable_totals_for(
|
107
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
108
|
+
AnnotationsClickableTotalsCommand
|
109
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
79
110
|
end
|
80
111
|
|
81
|
-
def annotations_clicked_by_day_for(
|
82
|
-
|
112
|
+
def annotations_clicked_by_day_for(
|
113
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
114
|
+
AnnotationsClickedByDayCommand
|
115
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
83
116
|
end
|
84
117
|
|
85
|
-
def annotations_clicked_totals_for(
|
86
|
-
|
118
|
+
def annotations_clicked_totals_for(
|
119
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
120
|
+
AnnotationsClickedTotalsCommand
|
121
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
87
122
|
end
|
88
123
|
|
89
|
-
def view_percentages_by_day_for(
|
90
|
-
|
124
|
+
def view_percentages_by_day_for(
|
125
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
126
|
+
ViewPercentagesByDayCommand
|
127
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
91
128
|
end
|
92
129
|
|
93
|
-
def view_percentage_totals_for(
|
94
|
-
|
130
|
+
def view_percentage_totals_for(
|
131
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
132
|
+
ViewPercentageTotalsCommand
|
133
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
95
134
|
end
|
96
135
|
|
97
|
-
def view_durations_by_day_for(
|
98
|
-
|
136
|
+
def view_durations_by_day_for(
|
137
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
138
|
+
ViewDurationsByDayCommand
|
139
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
99
140
|
end
|
100
141
|
|
101
|
-
def view_duration_totals_for(
|
102
|
-
|
142
|
+
def view_duration_totals_for(
|
143
|
+
video_ids, start_date, end_date, content_owner_id = nil)
|
144
|
+
ViewDurationTotalsCommand
|
145
|
+
.execute video_ids, start_date, end_date, content_owner_id
|
103
146
|
end
|
104
147
|
|
105
|
-
def channel_subscribers_lost_by_day_for(
|
148
|
+
def channel_subscribers_lost_by_day_for(
|
149
|
+
channel_ids, start_date, end_date, content_owner_id = nil)
|
106
150
|
ChannelSubscribersLostByDayCommand
|
107
|
-
.execute channel_ids, start_date, end_date
|
151
|
+
.execute channel_ids, start_date, end_date, content_owner_id
|
108
152
|
end
|
109
153
|
|
110
|
-
def channel_subscribers_lost_totals_for(
|
154
|
+
def channel_subscribers_lost_totals_for(
|
155
|
+
channel_ids, start_date, end_date, content_owner_id = nil)
|
111
156
|
ChannelSubscribersLostTotalsCommand
|
112
|
-
.execute channel_ids, start_date, end_date
|
157
|
+
.execute channel_ids, start_date, end_date, content_owner_id
|
113
158
|
end
|
114
159
|
|
115
|
-
def channel_subscribers_gained_by_day_for(
|
160
|
+
def channel_subscribers_gained_by_day_for(
|
161
|
+
channel_ids, start_date, end_date, content_owner_id = nil)
|
116
162
|
ChannelSubscribersGainedByDayCommand
|
117
|
-
.execute channel_ids, start_date, end_date
|
163
|
+
.execute channel_ids, start_date, end_date, content_owner_id
|
118
164
|
end
|
119
165
|
|
120
|
-
def channel_subscribers_gained_totals_for(
|
166
|
+
def channel_subscribers_gained_totals_for(
|
167
|
+
channel_ids, start_date, end_date, content_owner_id = nil)
|
121
168
|
ChannelSubscribersGainedTotalsCommand
|
122
|
-
.execute channel_ids, start_date, end_date
|
169
|
+
.execute channel_ids, start_date, end_date, content_owner_id
|
123
170
|
end
|
124
171
|
|
125
|
-
def channel_view_by_day_for(
|
172
|
+
def channel_view_by_day_for(
|
173
|
+
channel_ids, start_date, end_date, content_owner_id = nil)
|
126
174
|
ChannelViewCountByDayCommand
|
127
|
-
.execute channel_ids, start_date, end_date
|
175
|
+
.execute channel_ids, start_date, end_date, content_owner_id
|
128
176
|
end
|
129
177
|
|
130
|
-
def channel_view_totals_for(
|
178
|
+
def channel_view_totals_for(
|
179
|
+
channel_ids, start_date, end_date, content_owner_id = nil)
|
131
180
|
ChannelViewCountTotalsCommand
|
132
|
-
.execute channel_ids, start_date, end_date
|
181
|
+
.execute channel_ids, start_date, end_date, content_owner_id
|
133
182
|
end
|
134
183
|
|
135
|
-
def channel_like_by_day_for(
|
184
|
+
def channel_like_by_day_for(
|
185
|
+
channel_ids, start_date, end_date, content_owner_id = nil)
|
136
186
|
ChannelLikeCountByDayCommand
|
137
|
-
.execute channel_ids, start_date, end_date
|
187
|
+
.execute channel_ids, start_date, end_date, content_owner_id
|
138
188
|
end
|
139
189
|
|
140
|
-
def channel_like_totals_for(
|
190
|
+
def channel_like_totals_for(
|
191
|
+
channel_ids, start_date, end_date, content_owner_id = nil)
|
141
192
|
ChannelLikeCountTotalsCommand
|
142
|
-
.execute channel_ids, start_date, end_date
|
193
|
+
.execute channel_ids, start_date, end_date, content_owner_id
|
143
194
|
end
|
144
195
|
|
145
|
-
def channel_dislike_by_day_for(
|
196
|
+
def channel_dislike_by_day_for(
|
197
|
+
channel_ids, start_date, end_date, content_owner_id = nil)
|
146
198
|
ChannelDislikeCountByDayCommand
|
147
|
-
.execute channel_ids, start_date, end_date
|
199
|
+
.execute channel_ids, start_date, end_date, content_owner_id
|
148
200
|
end
|
149
201
|
|
150
|
-
def channel_dislike_totals_for(
|
202
|
+
def channel_dislike_totals_for(
|
203
|
+
channel_ids, start_date, end_date, content_owner_id = nil)
|
151
204
|
ChannelDislikeCountTotalsCommand
|
152
|
-
.execute channel_ids, start_date, end_date
|
205
|
+
.execute channel_ids, start_date, end_date, content_owner_id
|
153
206
|
end
|
154
207
|
|
155
|
-
def channel_comment_by_day_for(
|
208
|
+
def channel_comment_by_day_for(
|
209
|
+
channel_ids, start_date, end_date, content_owner_id = nil)
|
156
210
|
ChannelCommentCountByDayCommand
|
157
|
-
.execute channel_ids, start_date, end_date
|
211
|
+
.execute channel_ids, start_date, end_date, content_owner_id
|
158
212
|
end
|
159
213
|
|
160
|
-
def channel_comment_totals_for(
|
214
|
+
def channel_comment_totals_for(
|
215
|
+
channel_ids, start_date, end_date, content_owner_id = nil)
|
161
216
|
ChannelCommentCountTotalsCommand
|
162
|
-
.execute channel_ids, start_date, end_date
|
217
|
+
.execute channel_ids, start_date, end_date, content_owner_id
|
163
218
|
end
|
164
219
|
end
|
165
220
|
end
|
@@ -2,10 +2,12 @@ module Brainzz
|
|
2
2
|
class AnalyticsParams < BaseParams
|
3
3
|
attr_reader :start_date
|
4
4
|
attr_reader :end_date
|
5
|
+
attr_reader :content_owner
|
5
6
|
|
6
7
|
def initialize(params)
|
7
|
-
@start_date
|
8
|
-
@end_date
|
8
|
+
@start_date = normalize_date(params[:start_date])
|
9
|
+
@end_date = normalize_date(params[:end_date])
|
10
|
+
@content_owner = params[:content_owner]
|
9
11
|
end
|
10
12
|
|
11
13
|
def valid?
|
@@ -4,24 +4,37 @@ module Brainzz
|
|
4
4
|
|
5
5
|
@@mutex = Mutex.new
|
6
6
|
|
7
|
-
def
|
7
|
+
def retrieve_token_for(content_owner)
|
8
8
|
@@mutex.synchronize do
|
9
|
-
|
10
|
-
response = Toke.retrieve_token(params)
|
11
|
-
@token = response.data if response.success?
|
12
|
-
end
|
9
|
+
@tokens ||= {}
|
13
10
|
|
14
|
-
|
11
|
+
params = params_for(content_owner)
|
12
|
+
|
13
|
+
key = params[:refresh_token]
|
14
|
+
|
15
|
+
get_token_for key, params
|
16
|
+
|
17
|
+
@tokens[key].token if @tokens[key]
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
18
21
|
private
|
19
22
|
|
20
|
-
def params
|
23
|
+
def get_token_for(key, params)
|
24
|
+
if @tokens[key].nil? or @tokens[key].expired?
|
25
|
+
response = Toke.retrieve_token(params)
|
26
|
+
@tokens[key] = response.data if response.success?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def params_for(content_owner)
|
31
|
+
suffix = ''
|
32
|
+
suffix = "_#{content_owner.upcase.gsub(/-/, '')}" if content_owner
|
33
|
+
|
21
34
|
{
|
22
|
-
:refresh_token => ENV[
|
23
|
-
:client_id => ENV[
|
24
|
-
:client_secret => ENV[
|
35
|
+
:refresh_token => ENV["BRAINZZ_REFRESH_TOKEN#{suffix}"],
|
36
|
+
:client_id => ENV["BRAINZZ_CLIENT_ID#{suffix}"],
|
37
|
+
:client_secret => ENV["BRAINZZ_CLIENT_SECRET#{suffix}"],
|
25
38
|
}
|
26
39
|
end
|
27
40
|
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.
|
4
|
+
version: 0.0.16
|
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-
|
13
|
+
date: 2015-11-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|