From 55769e4e611568bdffc58632855b9e1495d8f98c Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Thu, 17 Oct 2013 12:28:35 +0100 Subject: [PATCH] Add list of controls and volume control. --- models/control.rb | 10 +++++++++- mpd_client.rb | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/models/control.rb b/models/control.rb index 948abbb..486770f 100644 --- a/models/control.rb +++ b/models/control.rb @@ -2,6 +2,10 @@ require './models/mpd_connection' class Control class << self + def controls + [:play, :stop, :next, :previous, :pause] + end + def play MPDConnection.mpd.play end @@ -19,7 +23,11 @@ class Control end def pause - MPDConnection.mpd.pause(!MPDConnection.mpd.paused?) + MPDConnection.mpd.pause = !MPDConnection.mpd.paused? + end + + def volume(value) + MPDConnection.mpd.volume = value end end end diff --git a/mpd_client.rb b/mpd_client.rb index 5e7f963..0cec098 100644 --- a/mpd_client.rb +++ b/mpd_client.rb @@ -39,6 +39,18 @@ class MPDClient < Sinatra::Base JSON Song.queue.map(&:to_h) end + put '/control/:action' do + if Control.controls.include?(params[:action].to_sym) + Control.send(params[:action]) + else + not_found + end + end + + put '/control/volume/:value' do + Control.volume(params[:value]) + end + end end