Class: Yt::Playlist

Inherits:
Resource show all
Defined in:
lib/yt/models/playlist.rb

Instance Attribute Summary

Attributes inherited from Resource

#auth, #id

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Methods included from Associations

#has_many

Methods included from Actions::Update

#do_update

Constructor Details

This class inherits a constructor from Yt::Resource

Instance Method Details

#deleteObject



7
8
9
10
# File 'lib/yt/models/playlist.rb', line 7

def delete
  do_delete {@id = nil}
  !exists?
end

#exists?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/yt/models/playlist.rb', line 35

def exists?
  !@id.nil?
end

#update(options = {}) ⇒ Object

Valid body (no defaults) are: title (string), description (string), privacy_status (string), tags (array of strings) - since title is required, we set it again if it’s not passed



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/yt/models/playlist.rb', line 14

def update(options = {})
  parts, body = [], {id: @id}

  options[:title] ||= title
  parts << :snippet
  body[:snippet] = options.slice :title, :description, :tags

  if status = options[:privacy_status]
    parts << :status
    body[:status] = {privacyStatus: status}
  end

  params = {params: {part: parts.join(',')}, body: body}
  do_update(params, expect: Net::HTTPOK) do |data|
    @id = data['id']
    @snippet = Snippet.new data: data['snippet'] if data['snippet']
    @status = Status.new data: data['status'] if data['status']
    true
  end
end