Class: YouTube::VideosResource

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

Constant Summary collapse

PARTS =
"id,snippet,contentDetails,liveStreamingDetails,statistics,status"
AUTH_PARTS =
"id,snippet,contentDetails,fileDetails,processingDetails,statistics,status,suggestions"

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

#likedObject

Retrieves liked Videos for the currently authenticated user



28
29
30
31
# File 'lib/you_tube/resources/videos.rb', line 28

def liked
  response = get_request "videos", params: {myRating: "like", part: PARTS}
  Collection.from_response(response, type: Video)
end

#list(id: nil, ids: nil) ⇒ Object

Retrieves Videos by ID. Can be comma separated to retrieve multiple.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/you_tube/resources/videos.rb', line 8

def list(id: nil, ids: nil)
  raise "Either id or ids is required" unless !id.nil? || !ids.nil?

  if id
    response = get_request("videos", params: {id: id, part: PARTS})
  elsif ids
    response = get_request("videos", params: {id: ids.join(","), part: PARTS})
  end

  body = response.body["items"]
  if body.count == 1
    Video.new body[0]
  elsif body.count > 1
    Collection.from_response(response, type: Video)
  else
    return nil
  end
end

#retrieve(id:) ⇒ Object

Retrieves a Video by the ID. This retrieves extra information so will only work on videos for an authenticated user



35
36
37
38
39
# File 'lib/you_tube/resources/videos.rb', line 35

def retrieve(id:)
  response = get_request "videos", params: {id: id, part: AUTH_PARTS}
  return nil if response.body["pageInfo"]["totalResults"] == 0
  Video.new(response.body["items"][0])
end