class Soundcloud9000::Models::TrackCollection

This model deals with the different types of tracklists that populate the tracklist section

Constants

DEFAULT_LIMIT

Attributes

collection_to_load[RW]
help[RW]
limit[R]
playlist[RW]
shuffle[RW]
user[RW]

Public Class Methods

new(client) click to toggle source
Calls superclass method Soundcloud9000::Models::Collection::new
# File lib/soundcloud9000/models/track_collection.rb, line 15
def initialize(client)
  super
  @limit = DEFAULT_LIMIT
  @collection_to_load = :recent
  @shuffle = false
  @help = false
end

Public Instance Methods

clear_and_replace() click to toggle source
# File lib/soundcloud9000/models/track_collection.rb, line 27
def clear_and_replace
  clear
  load_more
  events.trigger(:replace)
end
favorites_tracks() click to toggle source
# File lib/soundcloud9000/models/track_collection.rb, line 47
def favorites_tracks
  return [] if @client.current_user.nil?

  @client.get(@client.current_user.uri + '/favorites', offset: @limit * @page, limit: @limit)
end
load() click to toggle source
# File lib/soundcloud9000/models/track_collection.rb, line 33
def load
  clear
  load_more
end
load_more() click to toggle source
# File lib/soundcloud9000/models/track_collection.rb, line 38
def load_more
  unless @loaded
    tracks = send(@collection_to_load.to_s + '_tracks')
    @loaded = true if tracks.empty?
    append tracks.map { |hash| Track.new hash }
    @page += 1
  end
end
playlist_tracks() click to toggle source
# File lib/soundcloud9000/models/track_collection.rb, line 69
def playlist_tracks
  return [] if @playlist.nil?

  @client.get(@playlist.uri + '/tracks', offset: @limit * @page, limit: @limit)
end
recent_tracks() click to toggle source
# File lib/soundcloud9000/models/track_collection.rb, line 53
def recent_tracks
  @client.get('/tracks', offset: @page * limit, limit: @limit)
end
size() click to toggle source
# File lib/soundcloud9000/models/track_collection.rb, line 23
def size
  @rows.size
end
user_tracks() click to toggle source
# File lib/soundcloud9000/models/track_collection.rb, line 57
def user_tracks
  return [] if @client.current_user.nil?

  user_tracks = @client.get(@client.current_user.uri + '/tracks', offset: @limit * @page, limit: @limit)
  if user_tracks.empty?
    UI::Input.error("'#{@client.current_user.username}' has not authored any tracks. Use f to switch to their favorites, or s to switch to their playlists.")
    return []
  else
    return user_tracks
  end
end