Class: YouTube::ChannelsResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/you_tube/resources/channels.rb

Constant Summary collapse

PARTS =
"id,snippet,status,statistics,contentDetails"

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from YouTube::Resource

Instance Method Details

#mineObject

Retrieve the channel of the currently authenticated user



7
8
9
10
11
# File 'lib/you_tube/resources/channels.rb', line 7

def mine
  response = get_request "channels", params: {mine: true, part: PARTS}
  return nil if response.body["pageInfo"]["totalResults"] == 0
  Channel.new(response.body["items"][0])
end

#retrieve(id: nil, username: nil, handle: nil) ⇒ Object

Retrieve a Channel by its ID, Username or Handle (@username)

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/you_tube/resources/channels.rb', line 14

def retrieve(id: nil, username: nil, handle: nil)
  attrs = {}
  attrs[:id] = id if id
  attrs[:forUsername] = username if username
  attrs[:forHandle] = handle if handle
  raise ArgumentError, "Must provide either an ID, Username or Handle" if attrs.empty?

  response = get_request "channels", params: attrs.merge({part: PARTS})
  return nil if response.body["pageInfo"]["totalResults"] == 0
  Channel.new(response.body["items"][0])
end

#videos(id:, **options) ⇒ Object



26
27
28
29
# File 'lib/you_tube/resources/channels.rb', line 26

def videos(id:, **options)
  response = get_request "search", params: {channelId: id, part: "id,snippet"}.merge(options)
  Collection.from_response(response, type: SearchResult)
end