Class: YouTube::ChannelsResource
- Defined in:
- lib/you_tube/resources/channels.rb
Constant Summary collapse
- PARTS =
"id,snippet,status,statistics,contentDetails"
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
-
#mine ⇒ Object
Retrieve the channel of the currently authenticated user.
-
#retrieve(id: nil, username: nil, handle: nil) ⇒ Object
Retrieve a Channel by its ID, Username or Handle (@username).
- #videos(id:, **options) ⇒ Object
Methods inherited from Resource
Constructor Details
This class inherits a constructor from YouTube::Resource
Instance Method Details
#mine ⇒ Object
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)
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:, **) response = get_request "search", params: {channelId: id, part: "id,snippet"}.merge() Collection.from_response(response, type: SearchResult) end |