brainzz 0.0.17 → 0.0.18
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/lib/brainzz.rb +5 -0
- data/lib/brainzz/commands/video_details_command.rb +37 -3
- data/lib/brainzz/commands/video_search_command.rb +72 -0
- data/lib/brainzz/core.rb +6 -2
- data/lib/brainzz/models/video.rb +52 -6
- data/lib/brainzz/models/video_search_item.rb +12 -0
- data/lib/brainzz/models/video_search_wrapper.rb +19 -0
- data/lib/brainzz/params/video_details_params.rb +3 -2
- data/lib/brainzz/params/video_search_params.rb +17 -0
- data/lib/brainzz/responses/video_search_response.rb +7 -0
- metadata +7 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5668feb21fed30f063d10478004bb6ba7ecc6317
|
|
4
|
+
data.tar.gz: ecaed5994b411412064964aeefa3d998aeaee60e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1ab0494e395822611986b33fccc75cca750909c8880e3046f3fad28c376c51642855662f95dd6a4323b6cfde82d1a9386f0b380f016e9c1911f07f5ac5c3c2df
|
|
7
|
+
data.tar.gz: bddf04cd072595c7e32a58def7c3b7282d8813fe70e2c6dbd6ec4c5c8a3ba4eb616189334f5e837041ac7d941dd2451537360944564a54a282500f990340ce46
|
data/lib/brainzz.rb
CHANGED
|
@@ -35,6 +35,8 @@ require_relative 'brainzz/models/view_percentage'
|
|
|
35
35
|
require_relative 'brainzz/models/view_duration'
|
|
36
36
|
require_relative 'brainzz/models/playlist_item'
|
|
37
37
|
require_relative 'brainzz/models/playlist_items_wrapper'
|
|
38
|
+
require_relative 'brainzz/models/video_search_item'
|
|
39
|
+
require_relative 'brainzz/models/video_search_wrapper'
|
|
38
40
|
|
|
39
41
|
require_relative 'brainzz/services/access_token_service'
|
|
40
42
|
|
|
@@ -42,6 +44,7 @@ require_relative 'brainzz/params/base_params'
|
|
|
42
44
|
require_relative 'brainzz/params/analytics_params'
|
|
43
45
|
require_relative 'brainzz/params/stats_params'
|
|
44
46
|
require_relative 'brainzz/params/video_details_params'
|
|
47
|
+
require_relative 'brainzz/params/video_search_params'
|
|
45
48
|
require_relative 'brainzz/params/channel_details_params'
|
|
46
49
|
require_relative 'brainzz/params/video_stats_params'
|
|
47
50
|
require_relative 'brainzz/params/channel_stats_params'
|
|
@@ -50,6 +53,7 @@ require_relative 'brainzz/params/playlist_items_params'
|
|
|
50
53
|
require_relative 'brainzz/responses/playlist_items_response'
|
|
51
54
|
require_relative 'brainzz/responses/details_response'
|
|
52
55
|
require_relative 'brainzz/responses/video_details_response'
|
|
56
|
+
require_relative 'brainzz/responses/video_search_response'
|
|
53
57
|
require_relative 'brainzz/responses/channel_details_response'
|
|
54
58
|
require_relative 'brainzz/responses/video_stats_response'
|
|
55
59
|
require_relative 'brainzz/responses/view_count_response'
|
|
@@ -74,6 +78,7 @@ require_relative 'brainzz/commands/base_command'
|
|
|
74
78
|
require_relative 'brainzz/commands/data_command'
|
|
75
79
|
require_relative 'brainzz/commands/playlist_items_command'
|
|
76
80
|
require_relative 'brainzz/commands/video_details_command'
|
|
81
|
+
require_relative 'brainzz/commands/video_search_command'
|
|
77
82
|
require_relative 'brainzz/commands/channel_details_command'
|
|
78
83
|
require_relative 'brainzz/commands/analytics_command'
|
|
79
84
|
require_relative 'brainzz/commands/stats_command'
|
|
@@ -3,8 +3,9 @@ module Brainzz
|
|
|
3
3
|
class << self
|
|
4
4
|
private
|
|
5
5
|
|
|
6
|
-
def on_execute(video_ids, options={})
|
|
7
|
-
video_details_params = VideoDetailsParams
|
|
6
|
+
def on_execute(video_ids, options={}, content_owner_id=nil)
|
|
7
|
+
video_details_params = VideoDetailsParams
|
|
8
|
+
.new(video_ids, options, content_owner_id)
|
|
8
9
|
|
|
9
10
|
if video_details_params.valid?
|
|
10
11
|
response = get(video_details_params)
|
|
@@ -14,15 +15,48 @@ module Brainzz
|
|
|
14
15
|
end
|
|
15
16
|
end
|
|
16
17
|
|
|
18
|
+
def headers(parameters)
|
|
19
|
+
headers = super
|
|
20
|
+
|
|
21
|
+
if parameters.content_owner_id
|
|
22
|
+
if parameters.content_owner_id
|
|
23
|
+
access_token = access_token_for(parameters.content_owner_id)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
headers = headers.merge({
|
|
27
|
+
'Authorization' => "Bearer #{access_token}",
|
|
28
|
+
})
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
headers
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def access_token_for(content_owner_id)
|
|
35
|
+
AccessTokenService.retrieve_token_for content_owner_id
|
|
36
|
+
end
|
|
37
|
+
|
|
17
38
|
def endpoint
|
|
18
39
|
'videos'
|
|
19
40
|
end
|
|
20
41
|
|
|
21
42
|
def params(video_details_params)
|
|
22
|
-
super.merge({
|
|
43
|
+
params = super.merge({
|
|
23
44
|
'id' => video_details_params.video_ids.join(','),
|
|
24
45
|
'part' => video_details_params.parts.join(',')
|
|
25
46
|
})
|
|
47
|
+
|
|
48
|
+
if video_details_params.content_owner_id
|
|
49
|
+
# If we are checking on behalf of a content owner,
|
|
50
|
+
# we are using an access token and not a key
|
|
51
|
+
params.delete(:key) if video_details_params.content_owner_id
|
|
52
|
+
|
|
53
|
+
if video_details_params.content_owner_id
|
|
54
|
+
params['onBehalfOfContentOwner'] =
|
|
55
|
+
video_details_params.content_owner_id
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
params
|
|
26
60
|
end
|
|
27
61
|
end
|
|
28
62
|
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
module Brainzz
|
|
2
|
+
class VideoSearchCommand < DataCommand
|
|
3
|
+
class << self
|
|
4
|
+
private
|
|
5
|
+
|
|
6
|
+
def on_execute(options={}, content_owner_id=nil)
|
|
7
|
+
video_search_params = VideoSearchParams.new(options, content_owner_id)
|
|
8
|
+
|
|
9
|
+
if video_search_params.valid?
|
|
10
|
+
response = get(video_search_params)
|
|
11
|
+
VideoSearchResponse.new response
|
|
12
|
+
else
|
|
13
|
+
VideoSearchResponse.new
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def headers(parameters)
|
|
18
|
+
headers = super
|
|
19
|
+
|
|
20
|
+
if parameters.content_owner_id
|
|
21
|
+
if parameters.content_owner_id
|
|
22
|
+
access_token = access_token_for(parameters.content_owner_id)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
headers = headers.merge({
|
|
26
|
+
'Authorization' => "Bearer #{access_token}",
|
|
27
|
+
})
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
headers
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def access_token_for(content_owner_id)
|
|
34
|
+
AccessTokenService.retrieve_token_for content_owner_id
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def endpoint
|
|
38
|
+
'search'
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def params(video_search_params)
|
|
42
|
+
params = super.merge({
|
|
43
|
+
'part' => 'snippet',
|
|
44
|
+
'type' => 'video',
|
|
45
|
+
'maxResults' => 50
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
if video_search_params.next_page_token
|
|
49
|
+
params['pageToken'] = video_search_params.next_page_token
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
params['order'] = video_search_params.order if video_search_params.order
|
|
53
|
+
if video_search_params.for_content_owner
|
|
54
|
+
params['forContentOwner'] = video_search_params.for_content_owner
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
if video_search_params.content_owner_id
|
|
58
|
+
# If we are checking on behalf of a content owner,
|
|
59
|
+
# we are using an access token and not a key
|
|
60
|
+
params.delete(:key) if video_search_params.content_owner_id
|
|
61
|
+
|
|
62
|
+
if video_search_params.content_owner_id
|
|
63
|
+
params['onBehalfOfContentOwner'] =
|
|
64
|
+
video_search_params.content_owner_id
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
params
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
data/lib/brainzz/core.rb
CHANGED
|
@@ -10,8 +10,12 @@ module Brainzz
|
|
|
10
10
|
PlaylistItemsCommand.execute playlist_id, response
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def video_details_for(video_ids, options={})
|
|
14
|
-
VideoDetailsCommand.execute video_ids, options
|
|
13
|
+
def video_details_for(video_ids, options={}, content_owner_id = nil)
|
|
14
|
+
VideoDetailsCommand.execute video_ids, options, content_owner_id
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def video_search(options={}, content_owner_id = nil)
|
|
18
|
+
VideoSearchCommand.execute options, content_owner_id
|
|
15
19
|
end
|
|
16
20
|
|
|
17
21
|
def views_by_day_for(
|
data/lib/brainzz/models/video.rb
CHANGED
|
@@ -1,19 +1,41 @@
|
|
|
1
1
|
module Brainzz
|
|
2
2
|
class Video < BaseModel
|
|
3
|
-
attr_accessor :id
|
|
3
|
+
attr_accessor :id
|
|
4
|
+
attr_accessor :title
|
|
5
|
+
attr_accessor :description
|
|
6
|
+
attr_accessor :published_at
|
|
7
|
+
attr_accessor :duration
|
|
8
|
+
attr_accessor :tags
|
|
9
|
+
attr_accessor :view_count
|
|
10
|
+
attr_accessor :channel_id
|
|
11
|
+
attr_accessor :channel_title
|
|
12
|
+
attr_accessor :privacy_status
|
|
4
13
|
|
|
5
14
|
def initialize(hash = {})
|
|
6
15
|
@hash = hash || {}
|
|
7
16
|
|
|
8
|
-
@id
|
|
9
|
-
@title
|
|
10
|
-
@
|
|
11
|
-
@
|
|
12
|
-
@
|
|
17
|
+
@id = transform(hash_id)
|
|
18
|
+
@title = transform(hash_title)
|
|
19
|
+
@description = transform(hash_description)
|
|
20
|
+
@published_at = transform_date(hash_published_at)
|
|
21
|
+
@duration = transform_duration(hash_duration)
|
|
22
|
+
@tags = transform(hash_tags)
|
|
23
|
+
@view_count = transform(hash_view_count)
|
|
24
|
+
@channel_id = transform(hash_channel_id)
|
|
25
|
+
@channel_title = transform(hash_channel_title)
|
|
26
|
+
@privacy_status = transform(hash_privacy_status)
|
|
13
27
|
end
|
|
14
28
|
|
|
15
29
|
private
|
|
16
30
|
|
|
31
|
+
def status
|
|
32
|
+
@hash['status'] || {}
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def file_details
|
|
36
|
+
@hash['fileDetails'] || {}
|
|
37
|
+
end
|
|
38
|
+
|
|
17
39
|
def content_details
|
|
18
40
|
@hash['contentDetails'] || {}
|
|
19
41
|
end
|
|
@@ -26,6 +48,14 @@ module Brainzz
|
|
|
26
48
|
@hash['snippet'] || {}
|
|
27
49
|
end
|
|
28
50
|
|
|
51
|
+
def statistics
|
|
52
|
+
@hash['statistics'] || {}
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def hash_view_count
|
|
56
|
+
statistics['viewCount']
|
|
57
|
+
end
|
|
58
|
+
|
|
29
59
|
def hash_id
|
|
30
60
|
@hash['videoId'] || @hash['id']
|
|
31
61
|
end
|
|
@@ -34,6 +64,10 @@ module Brainzz
|
|
|
34
64
|
snippet['title']
|
|
35
65
|
end
|
|
36
66
|
|
|
67
|
+
def hash_description
|
|
68
|
+
snippet['description']
|
|
69
|
+
end
|
|
70
|
+
|
|
37
71
|
def hash_published_at
|
|
38
72
|
snippet['publishedAt']
|
|
39
73
|
end
|
|
@@ -41,5 +75,17 @@ module Brainzz
|
|
|
41
75
|
def hash_tags
|
|
42
76
|
snippet['tags']
|
|
43
77
|
end
|
|
78
|
+
|
|
79
|
+
def hash_channel_id
|
|
80
|
+
snippet['channelId']
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def hash_channel_title
|
|
84
|
+
snippet['channelTitle']
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def hash_privacy_status
|
|
88
|
+
status['privacyStatus']
|
|
89
|
+
end
|
|
44
90
|
end
|
|
45
91
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Brainzz
|
|
2
|
+
class VideoSearchWrapper
|
|
3
|
+
attr_accessor :next_page_token, :video_search_items
|
|
4
|
+
|
|
5
|
+
def initialize(video_search_data = {})
|
|
6
|
+
@video_search_items = []
|
|
7
|
+
items = video_search_data['items'] || []
|
|
8
|
+
items.each do |video_search_item|
|
|
9
|
+
@video_search_items << VideoSearchItem.new(video_search_item)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
@next_page_token = video_search_data['nextPageToken']
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def last_page?
|
|
16
|
+
!next_page_token
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
module Brainzz
|
|
2
2
|
class VideoDetailsParams
|
|
3
|
-
attr_reader :video_ids, :parts
|
|
3
|
+
attr_reader :video_ids, :parts, :content_owner_id
|
|
4
4
|
|
|
5
|
-
def initialize(video_ids, options={})
|
|
5
|
+
def initialize(video_ids, options={}, content_owner_id=nil)
|
|
6
6
|
@video_ids = video_ids
|
|
7
7
|
@parts = options.fetch(:parts, default_video_parts)
|
|
8
|
+
@content_owner_id = content_owner_id
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
def valid?
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Brainzz
|
|
2
|
+
class VideoSearchParams
|
|
3
|
+
attr_reader :content_owner_id, :next_page_token, :for_content_owner, :order
|
|
4
|
+
|
|
5
|
+
def initialize(options={}, content_owner_id=nil)
|
|
6
|
+
@for_content_owner = options.fetch(:for_content_owner, nil)
|
|
7
|
+
@order = options.fetch(:order, nil)
|
|
8
|
+
@content_owner_id = content_owner_id
|
|
9
|
+
@next_page_token = options.fetch(:next_page_token, nil)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def valid?
|
|
13
|
+
true
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
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.18
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Travis Herrick
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2016-
|
|
12
|
+
date: 2016-03-25 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: faraday
|
|
@@ -214,6 +214,7 @@ files:
|
|
|
214
214
|
- lib/brainzz/commands/subscribers_lost_by_day_command.rb
|
|
215
215
|
- lib/brainzz/commands/subscribers_lost_totals_command.rb
|
|
216
216
|
- lib/brainzz/commands/video_details_command.rb
|
|
217
|
+
- lib/brainzz/commands/video_search_command.rb
|
|
217
218
|
- lib/brainzz/commands/video_stats_command.rb
|
|
218
219
|
- lib/brainzz/commands/view_count_by_day_command.rb
|
|
219
220
|
- lib/brainzz/commands/view_duration_totals_command.rb
|
|
@@ -262,6 +263,8 @@ files:
|
|
|
262
263
|
- lib/brainzz/models/subscribers_lost_count.rb
|
|
263
264
|
- lib/brainzz/models/subscribers_lost_mixin.rb
|
|
264
265
|
- lib/brainzz/models/video.rb
|
|
266
|
+
- lib/brainzz/models/video_search_item.rb
|
|
267
|
+
- lib/brainzz/models/video_search_wrapper.rb
|
|
265
268
|
- lib/brainzz/models/video_stat.rb
|
|
266
269
|
- lib/brainzz/models/view_count.rb
|
|
267
270
|
- lib/brainzz/models/view_duration.rb
|
|
@@ -273,6 +276,7 @@ files:
|
|
|
273
276
|
- lib/brainzz/params/playlist_items_params.rb
|
|
274
277
|
- lib/brainzz/params/stats_params.rb
|
|
275
278
|
- lib/brainzz/params/video_details_params.rb
|
|
279
|
+
- lib/brainzz/params/video_search_params.rb
|
|
276
280
|
- lib/brainzz/params/video_stats_params.rb
|
|
277
281
|
- lib/brainzz/responses/annotations_clickable_response.rb
|
|
278
282
|
- lib/brainzz/responses/annotations_clicked_response.rb
|
|
@@ -292,6 +296,7 @@ files:
|
|
|
292
296
|
- lib/brainzz/responses/subscribers_gained_response.rb
|
|
293
297
|
- lib/brainzz/responses/subscribers_lost_response.rb
|
|
294
298
|
- lib/brainzz/responses/video_details_response.rb
|
|
299
|
+
- lib/brainzz/responses/video_search_response.rb
|
|
295
300
|
- lib/brainzz/responses/video_stats_response.rb
|
|
296
301
|
- lib/brainzz/responses/view_count_response.rb
|
|
297
302
|
- lib/brainzz/responses/view_duration_response.rb
|