Skip to content

Commit

Permalink
Add support for Last Played At in the API response
Browse files Browse the repository at this point in the history
This patch records the last time that the song was played. This allows someone
to write client apps that follow along with what's currently playing
  • Loading branch information
anaisbetts committed Dec 13, 2011
1 parent 2916d1f commit 285b819
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions db/migrate/06_add_lastplayed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddLastPlayed < ActiveRecord::Migration
def self.up
add_column :songs, :last_played, :timestamp
end

def self.down
remove_column :songs, :last_played
end
end
1 change: 1 addition & 0 deletions lib/play/app/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def music_response(song)
'artist_name' => song.artist_name,
'song_title' => song.title,
'album_name' => song.album_name,
'last_played_at' => song.last_played
'song_download_path' => "/song/#{song.id}/download",
'album_download_path' => "/album/#{song.album_id}/download",
'alumb_art_url' => song.album.art_url
Expand Down
1 change: 1 addition & 0 deletions lib/play/song.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def dequeue!(user=nil)
def play!
Song.update_all(:now_playing => false)
self.now_playing = true
self.last_played = Time.now
votes.update_all(:active => false)
save
end
Expand Down

0 comments on commit 285b819

Please sign in to comment.