Class: Hypem::Playlist
- Inherits:
-
Object
- Object
- Hypem::Playlist
- Defined in:
- lib/hypem/playlist.rb
Constant Summary collapse
- POPULAR_ARGS =
[%s(3day),:lastweek,:noremix,:artists,:twitter]
- GENERIC_METHODS =
[:blog, :search, :artist, :feed, :loved, :obsessed]
Instance Attribute Summary collapse
-
#extended ⇒ Object
readonly
Returns the value of attribute extended.
-
#path ⇒ Object
Returns the value of attribute path.
-
#tracks ⇒ Object
Returns the value of attribute tracks.
Class Method Summary collapse
- .create_url(tracks) ⇒ Object
- .friends_favorites(user, page = nil) ⇒ Object
- .friends_history(user, page = nil) ⇒ Object
- .latest(filter = :all, page = nil) ⇒ Object
- .popular(arg = POPULAR_ARGS.first, page = nil) ⇒ Object
- .tags(list, page) ⇒ Object
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(type, arg, page = nil) ⇒ Playlist
constructor
A new instance of Playlist.
- #next_page ⇒ Object
- #page(num) ⇒ Object
- #prev_page ⇒ Object
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
#extended ⇒ Object (readonly)
Returns the value of attribute extended.
5 6 7 |
# File 'lib/hypem/playlist.rb', line 5 def extended @extended end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/hypem/playlist.rb', line 4 def path @path end |
#tracks ⇒ Object
Returns the value of attribute tracks.
4 5 6 |
# File 'lib/hypem/playlist.rb', line 4 def tracks @tracks end |
Class Method Details
.create_url(tracks) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/hypem/playlist.rb', line 35 def self.create_url(tracks) raise ArgumentError if (!tracks.is_a? Array) || (!tracks.first.is_a? Hypem::Track) track_params = tracks.map(&:id).join(',') playlist = Playlist.new('set',track_params) return Hypem::ROOT_PATH + playlist.path end |
.friends_favorites(user, page = nil) ⇒ Object
57 58 59 |
# File 'lib/hypem/playlist.rb', line 57 def self.friends_favorites(user,page=nil) Playlist.new(:people,user,page).tap(&:get) end |
.friends_history(user, page = nil) ⇒ Object
53 54 55 |
# File 'lib/hypem/playlist.rb', line 53 def self.friends_history(user,page=nil) Playlist.new(:people_history,user,page).tap(&:get) end |
.latest(filter = :all, page = nil) ⇒ Object
42 43 44 45 |
# File 'lib/hypem/playlist.rb', line 42 def self.latest(filter=:all,page=nil) raise ArgumentError unless [:all, :noremix, :remix, :fresh].include? filter Playlist.new(:latest,filter,page).tap(&:get) end |
.popular(arg = POPULAR_ARGS.first, page = nil) ⇒ Object
47 48 49 50 51 |
# File 'lib/hypem/playlist.rb', line 47 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 |
Instance Method Details
#get ⇒ Object
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_page ⇒ Object
23 24 25 |
# File 'lib/hypem/playlist.rb', line 23 def next_page Playlist.new(@type,@arg,@page+1).tap(&:get) end |