Class: YouTube::PlaylistItemsResource

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

Constant Summary collapse

PARTS =
"id,snippet,status"

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

#create(playlist_id:, video_id:, **attributes) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/you_tube/resources/playlist_items.rb', line 22

def create(playlist_id:, video_id:, **attributes)
  attrs = {}
  attrs[:snippet] = {}
  attrs[:status] = {}

  attrs[:snippet][:playlistId] = playlist_id
  attrs[:snippet][:resourceId] = {kind: "youtube#video", videoId: video_id}

  attrs[:snippet][:position] = attributes[:position]

  response = post_request("playlistItems?part=id,snippet,status", body: attrs)
  
  PlaylistItem.new(response.body) if response.success?
end

#delete(id:) ⇒ Object



57
58
59
# File 'lib/you_tube/resources/playlist_items.rb', line 57

def delete(id:)
  delete_request("playlistItems?id=#{id}")
end

#list(playlist_id:) ⇒ Object

Returns Playlist Items for a Playlist developers.google.com/youtube/v3/docs/playlistItems/list



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

def list(playlist_id:)
  response = get_request "playlistItems", params: {playlistId: playlist_id, part: PARTS}
  Collection.from_response(response, type: PlaylistItem)
end

#retrieve(id:) ⇒ Object

Returns a Playlist Item for a given ID developers.google.com/youtube/v3/docs/playlistItems/list



15
16
17
18
# File 'lib/you_tube/resources/playlist_items.rb', line 15

def retrieve(id:)
  response = get_request "playlistItems", params: {id: id, part: PARTS}
  PlaylistItem.new(response.body["items"][0])
end

#update(id:, playlist_id:, video_id:, **attributes) ⇒ Object

Updates a Playlist Item. ID, Playlist ID and Video ID are required. developers.google.com/youtube/v3/docs/playlistItems/update



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/you_tube/resources/playlist_items.rb', line 39

def update(id:, playlist_id:, video_id:, **attributes)
  attrs = {}
  attrs[:id] = id
  attrs[:snippet] = {}
  attrs[:status] = {}

  attrs[:snippet][:playlistId] = playlist_id
  attrs[:snippet][:resourceId] = {kind: "youtube#video", videoId: video_id}

  attrs[:snippet][:position] = attributes[:position]

  response = put_request("playlistItems?part=id,snippet,status", body: attrs)
  
  PlaylistItem.new(response.body) if response.success?
end