Class: Hypem::Playlist

Inherits:
Object
  • Object
show all
Defined in:
lib/hypem/playlist.rb

Constant Summary collapse

[%s(3day),:lastweek,:noremix,:artists,:twitter]
GENERIC_METHODS =
[:blog, :search, :artist, :feed, :loved, :obsessed]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, arg, page = nil) ⇒ Playlist

Returns a new instance of Playlist.



7
8
9
10
11
12
13
# File 'lib/hypem/playlist.rb', line 7

def initialize(type,arg,page=nil)
  page = 1 if page.nil?
  @type = type
  @arg = arg
  @page = page
  @path = "/playlist/#{@type}/#{@arg}/json/#{@page}"
end

Instance Attribute Details

#extendedObject (readonly)

Returns the value of attribute extended.



5
6
7
# File 'lib/hypem/playlist.rb', line 5

def extended
  @extended
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/hypem/playlist.rb', line 4

def path
  @path
end

#tracksObject

Returns the value of attribute tracks.



4
5
6
# File 'lib/hypem/playlist.rb', line 4

def tracks
  @tracks
end

Class Method Details

.friends_favorites(user, page = nil) ⇒ Object



59
60
61
# File 'lib/hypem/playlist.rb', line 59

def self.friends_favorites(user,page=nil)
  Playlist.new(:people,user,page).tap(&:get)
end

.friends_history(user, page = nil) ⇒ Object



55
56
57
# File 'lib/hypem/playlist.rb', line 55

def self.friends_history(user,page=nil)
  Playlist.new(:people_history,user,page).tap(&:get)
end

.latest(filter = :all, page = nil) ⇒ Object

Raises:

  • (ArgumentError)


44
45
46
47
# File 'lib/hypem/playlist.rb', line 44

def self.latest(filter=:all,page=nil)
  raise ArgumentError unless [:all, :noremix, :remix, :fresh].include? filter
  Playlist.new(:latest,filter,page).tap(&:get)
end

.new_from_tracks(tracks) ⇒ Object



39
40
41
42
# File 'lib/hypem/playlist.rb', line 39

def self.new_from_tracks(tracks)
  track_params = tracks.map(&:id).join(',')
  Playlist.new('set',track_params)
end

Raises:

  • (ArgumentError)


49
50
51
52
53
# File 'lib/hypem/playlist.rb', line 49

def self.popular(arg=POPULAR_ARGS.first,page=nil)
  arg = arg.to_sym if arg.is_a? String
  raise ArgumentError unless POPULAR_ARGS.include?(arg)
  Playlist.new(:popular,arg,page).tap(&:get)
end

.tags(list, page) ⇒ Object



63
64
65
66
# File 'lib/hypem/playlist.rb', line 63

def self.tags(list,page)
  list = list.join(',') if list.is_a? Array
  Playlist.new(:tags,list,page)
end

Instance Method Details

#getObject



15
16
17
18
19
20
21
# File 'lib/hypem/playlist.rb', line 15

def get
  response = Request.new(@path).tap(&:get).response
  @tracks = []
  # getting rid of version cell
  response.body.shift
  response.body.each_value{|v| @tracks << Track.new(v)}
end

#next_pageObject



23
24
25
# File 'lib/hypem/playlist.rb', line 23

def next_page
  Playlist.new(@type,@arg,@page+1).tap(&:get)
end

#page(num) ⇒ Object



31
32
33
# File 'lib/hypem/playlist.rb', line 31

def page(num)
  Playlist.new(@type,@arg,num).tap(&:get)
end

#prev_pageObject



27
28
29
# File 'lib/hypem/playlist.rb', line 27

def prev_page
  Playlist.new(@type,@arg,@page-1).tap(&:get)
end

#urlObject



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

def url
  Hypem::ROOT_PATH + path
end