Class: Viddlereo::Playlist

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

Constant Summary

Constants inherited from Resource

Resource::BASE_URI

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

auth_required, auth_required?, client, default_options, get, inherited, #initialize, param, params, #params, post, resource_name, uri

Constructor Details

This class inherits a constructor from Viddlereo::Resource

Class Method Details

.find_by_id(playlist_id, options = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/viddlereo/playlist.rb', line 39

def self.find_by_id(playlist_id, options = {})
  begin
    response = get(:method => :getDetails, 
      :playlist_id => playlist_id,
      :per_page => options[:per_page] || 100, 
      :add_embed_code => options[:add_embed_code] || 1,
      :page => options[:page] || 1)
    playlist = parse(response).first
    playlist.videos = Viddlereo::Video.parse(response) if playlist
    playlist
  rescue RestClient::ResourceNotFound
    nil
  end
end

.find_by_user(user, options = {}) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/viddlereo/playlist.rb', line 54

def self.find_by_user(user, options = {})
  begin
    response = get(:method => :getByUser, 
      :user => user,
      :per_page => options[:per_page] || 100, 
      :page => options[:page] || 1)
    parse(response)
  rescue RestClient::ResourceNotFound
    []
  end
end

Instance Method Details

#destroyObject



34
35
36
37
# File 'lib/viddlereo/playlist.rb', line 34

def destroy
  self.class.post(:method => "delete", :playlist_id => self.id)   
  true
end

#saveObject



24
25
26
27
28
29
30
31
32
# File 'lib/viddlereo/playlist.rb', line 24

def save
  new_record = self.class.parse(self.class.post(:method => "create", 
    :name       => self.name, 
    :type       => self.type,
    :visibility => self.visibility
  ))
  self.id = new_record.first.id
  true
end