Skip to content

Commit 380987a

Browse files
committed
Add channel_sections under channel
1 parent 0713621 commit 380987a

File tree

5 files changed

+82
-2
lines changed

5 files changed

+82
-2
lines changed

lib/yt/collections/branding_settings.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class BrandingSettings < Base
99
private
1010

1111
def attributes_for_new_item(data)
12-
puts data
1312
{ data: data['brandingSettings'] }
1413
end
1514

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
require 'yt/collections/base'
2+
require 'yt/models/channel_section'
3+
4+
module Yt
5+
module Collections
6+
# Provides methods for a collection of YouTube channel sections.
7+
#
8+
# Resources with channel_sections is {Yt::Models::Channel channels}.
9+
class ChannelSections < Base
10+
11+
def attributes_for_new_item(data)
12+
{}.tap do |attributes|
13+
attributes[:id] = data['id']
14+
attributes[:snippet] = data['snippet']
15+
attributes[:content_details] = data['contentDetails']
16+
end
17+
end
18+
19+
# @return [Hash] the parameters to submit to YouTube to list channel sections.
20+
# @see https://developers.google.com/youtube/v3/docs/channelSections/list
21+
def list_params
22+
super.tap do |params|
23+
params[:params] = channel_sections_params
24+
params[:path] = '/youtube/v3/channelSections'
25+
end
26+
end
27+
28+
def channel_sections_params
29+
{}.tap do |params|
30+
params[:part] = 'snippet'
31+
params.merge! @parent.channel_sections_params if @parent
32+
# TODO: when to mine, when to on_behalf_of_content_owner
33+
# if @parent.auth
34+
# if @parent.auth.owner_name
35+
# params[:on_behalf_of_content_owner] = @parent.auth.owner_name
36+
# else
37+
# params[:mine] = true
38+
# end
39+
# end
40+
params
41+
end
42+
end
43+
end
44+
end
45+
end

lib/yt/models/channel.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ def unsubscribe!
126126
# explicitly select the option to keep all subscriptions private.
127127
has_many :subscribed_channels
128128

129+
# @!attribute [r] channel_sections
130+
# @return [Yt::Collections::ChannelSections] the channel’s channel sections.
131+
has_many :channel_sections
132+
129133
### ANALYTICS ###
130134

131135
# @macro reports
@@ -306,6 +310,13 @@ def initialize(options = {})
306310
end
307311
end
308312

313+
# @private
314+
# Used for `has_many :channel_sections` to return all youtube#channelSection items
315+
# of the channel.
316+
def channel_sections_params
317+
{channel_id: id}
318+
end
319+
309320
# @private
310321
# Tells `has_many :videos` that channel.videos should return all the
311322
# videos publicly available on the channel.

lib/yt/models/channel_section.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'yt/models/base'
2+
3+
module Yt
4+
module Models
5+
class ChannelSection < Base
6+
attr_reader :data
7+
8+
# @private
9+
def initialize(options = {})
10+
@id = options[:id]
11+
@data = options[:snippet]
12+
end
13+
14+
has_attribute :type
15+
has_attribute :channel_id
16+
has_attribute :position, type: Integer
17+
18+
### ID ###
19+
20+
# @!attribute [r] id
21+
# @return [String] the ID that YouTube uses to identify each resource.
22+
attr_reader :id
23+
end
24+
end
25+
end

lib/yt/models/group_info.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ def initialize(options = {})
1313
has_attribute :published_at, type: Time
1414
end
1515
end
16-
end
16+
end

0 commit comments

Comments
 (0)