brainzz 0.0.18 → 0.0.20

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5668feb21fed30f063d10478004bb6ba7ecc6317
4
- data.tar.gz: ecaed5994b411412064964aeefa3d998aeaee60e
3
+ metadata.gz: 2cac458f1fe94ce4732b105c277a8021bd33368b
4
+ data.tar.gz: 58fbb8fd375834f8cb89638cd5a4108b785c81ca
5
5
  SHA512:
6
- metadata.gz: 1ab0494e395822611986b33fccc75cca750909c8880e3046f3fad28c376c51642855662f95dd6a4323b6cfde82d1a9386f0b380f016e9c1911f07f5ac5c3c2df
7
- data.tar.gz: bddf04cd072595c7e32a58def7c3b7282d8813fe70e2c6dbd6ec4c5c8a3ba4eb616189334f5e837041ac7d941dd2451537360944564a54a282500f990340ce46
6
+ metadata.gz: 89b72e52add42b683bae743b7287a42d7760a9c7796b55b9d259bb56a8a132a20257906733fd89b9236cc43dd0ca768935cc8f735905c872ca09827cf345d49a
7
+ data.tar.gz: 5816cc5435f57b9b910feb84649b895bfba50ad87a54f59e19ca802051d82c104dfb2de66f1a30fefd94295031b40608c966614cb3e7ba1e3b2d56eed50f723a
data/README.md CHANGED
@@ -117,6 +117,19 @@ and channel objects as the values.
117
117
 
118
118
  * channel ids (Array[String])
119
119
 
120
+ ### `channel_list`
121
+
122
+ Accepts a hash of options for the channels.list call. Allowing
123
+ for you to get managed channels by content owner id.
124
+
125
+ This endpoint returns a hash with a list of channels.
126
+
127
+ #### Parameters
128
+
129
+ * options (Hash)
130
+ * content_owner_id (String)
131
+
132
+
120
133
  ### `playlist_items_for`
121
134
 
122
135
  On first invocation, only a playlist id is required:
@@ -37,6 +37,7 @@ require_relative 'brainzz/models/playlist_item'
37
37
  require_relative 'brainzz/models/playlist_items_wrapper'
38
38
  require_relative 'brainzz/models/video_search_item'
39
39
  require_relative 'brainzz/models/video_search_wrapper'
40
+ require_relative 'brainzz/models/channel_list_wrapper'
40
41
 
41
42
  require_relative 'brainzz/services/access_token_service'
42
43
 
@@ -49,6 +50,7 @@ require_relative 'brainzz/params/channel_details_params'
49
50
  require_relative 'brainzz/params/video_stats_params'
50
51
  require_relative 'brainzz/params/channel_stats_params'
51
52
  require_relative 'brainzz/params/playlist_items_params'
53
+ require_relative 'brainzz/params/channel_list_params'
52
54
 
53
55
  require_relative 'brainzz/responses/playlist_items_response'
54
56
  require_relative 'brainzz/responses/details_response'
@@ -73,6 +75,7 @@ require_relative 'brainzz/responses/annotations_clickable_response'
73
75
  require_relative 'brainzz/responses/annotations_clicked_response'
74
76
  require_relative 'brainzz/responses/view_percentage_response'
75
77
  require_relative 'brainzz/responses/view_duration_response'
78
+ require_relative 'brainzz/responses/channel_list_response'
76
79
 
77
80
  require_relative 'brainzz/commands/base_command'
78
81
  require_relative 'brainzz/commands/data_command'
@@ -80,6 +83,7 @@ require_relative 'brainzz/commands/playlist_items_command'
80
83
  require_relative 'brainzz/commands/video_details_command'
81
84
  require_relative 'brainzz/commands/video_search_command'
82
85
  require_relative 'brainzz/commands/channel_details_command'
86
+ require_relative 'brainzz/commands/channel_list_command'
83
87
  require_relative 'brainzz/commands/analytics_command'
84
88
  require_relative 'brainzz/commands/stats_command'
85
89
  require_relative 'brainzz/commands/video_stats_command'
@@ -0,0 +1,69 @@
1
+ module Brainzz
2
+ class ChannelListCommand < DataCommand
3
+ class << self
4
+ private
5
+
6
+ def on_execute(options={}, content_owner_id=nil)
7
+ channel_list_params = ChannelListParams.new(options, content_owner_id)
8
+
9
+ if channel_list_params.valid?
10
+ response = get(channel_list_params)
11
+ ChannelListResponse.new response
12
+ else
13
+ ChannelListResponse.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
+ 'channels'
39
+ end
40
+
41
+ def params(channel_list_params)
42
+ params = super.merge({
43
+ 'maxResults' => 50,
44
+ 'part' => channel_list_params.parts.join(',')
45
+ })
46
+
47
+ params['managedByMe'] = true if channel_list_params.managed_by_me
48
+ params['mine'] = true if channel_list_params.mine
49
+
50
+ if channel_list_params.next_page_token
51
+ params['pageToken'] = channel_list_params.next_page_token
52
+ end
53
+
54
+ if channel_list_params.content_owner_id
55
+ # If we are checking on behalf of a content owner,
56
+ # we are using an access token and not a key
57
+ params.delete(:key) if channel_list_params.content_owner_id
58
+
59
+ if channel_list_params.content_owner_id
60
+ params['onBehalfOfContentOwner'] =
61
+ channel_list_params.content_owner_id
62
+ end
63
+ end
64
+
65
+ params
66
+ end
67
+ end
68
+ end
69
+ end
@@ -2,6 +2,10 @@ module Brainzz
2
2
  module Core
3
3
  extend self
4
4
 
5
+ def channel_list(options={}, content_owner_id = nil)
6
+ ChannelListCommand.execute options, content_owner_id
7
+ end
8
+
5
9
  def channel_details_for(channel_ids)
6
10
  ChannelDetailsCommand.execute channel_ids
7
11
  end
@@ -0,0 +1,19 @@
1
+ module Brainzz
2
+ class ChannelListWrapper
3
+ attr_accessor :next_page_token, :channel_list_items
4
+
5
+ def initialize(channel_list_data = {})
6
+ @channel_list_items = []
7
+ items = channel_list_data['items'] || []
8
+ items.each do |channel_list_item|
9
+ @channel_list_items << Channel.new(channel_list_item)
10
+ end
11
+
12
+ @next_page_token = channel_list_data['nextPageToken']
13
+ end
14
+
15
+ def last_page?
16
+ !next_page_token
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ module Brainzz
2
+ class ChannelListParams
3
+ attr_reader :parts
4
+ attr_reader :content_owner_id
5
+ attr_reader :managed_by_me
6
+ attr_reader :mine
7
+ attr_reader :next_page_token
8
+
9
+ def initialize(options={}, content_owner_id=nil)
10
+ @parts = options.fetch(:parts, default_channel_parts)
11
+ @content_owner_id = content_owner_id
12
+ @managed_by_me = options.fetch(:managed_by_me, false)
13
+ @mine = options.fetch(:mine, false)
14
+ @next_page_token = options.fetch(:next_page_token, nil)
15
+ end
16
+
17
+ def valid?
18
+ !!(@parts && !@parts.empty?)
19
+ end
20
+
21
+ private
22
+
23
+ def default_channel_parts
24
+ %w(snippet contentDetails statistics)
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ module Brainzz
2
+ class ChannelListResponse < ::Reverb::Response
3
+ def on_success
4
+ self.data = ChannelListWrapper.new(body)
5
+ end
6
+ end
7
+ 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.18
4
+ version: 0.0.20
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-03-25 00:00:00.000000000 Z
12
+ date: 2016-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -190,6 +190,7 @@ files:
190
190
  - lib/brainzz/commands/channel_dislike_totals_command.rb
191
191
  - lib/brainzz/commands/channel_like_count_by_day_command.rb
192
192
  - lib/brainzz/commands/channel_like_totals_command.rb
193
+ - lib/brainzz/commands/channel_list_command.rb
193
194
  - lib/brainzz/commands/channel_stats_command.rb
194
195
  - lib/brainzz/commands/channel_subscribers_gained_by_day_command.rb
195
196
  - lib/brainzz/commands/channel_subscribers_gained_totals_command.rb
@@ -247,6 +248,7 @@ files:
247
248
  - lib/brainzz/models/channel_comment_count.rb
248
249
  - lib/brainzz/models/channel_dislike_count.rb
249
250
  - lib/brainzz/models/channel_like_count.rb
251
+ - lib/brainzz/models/channel_list_wrapper.rb
250
252
  - lib/brainzz/models/channel_stat.rb
251
253
  - lib/brainzz/models/channel_subscribers_gained_count.rb
252
254
  - lib/brainzz/models/channel_subscribers_lost_count.rb
@@ -272,6 +274,7 @@ files:
272
274
  - lib/brainzz/params/analytics_params.rb
273
275
  - lib/brainzz/params/base_params.rb
274
276
  - lib/brainzz/params/channel_details_params.rb
277
+ - lib/brainzz/params/channel_list_params.rb
275
278
  - lib/brainzz/params/channel_stats_params.rb
276
279
  - lib/brainzz/params/playlist_items_params.rb
277
280
  - lib/brainzz/params/stats_params.rb
@@ -284,6 +287,7 @@ files:
284
287
  - lib/brainzz/responses/channel_details_response.rb
285
288
  - lib/brainzz/responses/channel_dislike_count_response.rb
286
289
  - lib/brainzz/responses/channel_like_count_response.rb
290
+ - lib/brainzz/responses/channel_list_response.rb
287
291
  - lib/brainzz/responses/channel_subscribers_gained_response.rb
288
292
  - lib/brainzz/responses/channel_subscribers_lost_response.rb
289
293
  - lib/brainzz/responses/channel_view_count_response.rb