summaryrefslogtreecommitdiff
path: root/mpdlib.rb
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2009-07-21 14:57:09 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2009-07-21 14:57:09 -0700
commitca0ac60d048ed34cc39be0414b14a51bb0408b82 (patch)
treefed7823550adc9ab98e1f705a480db3f430633db /mpdlib.rb
parent89e03522718985ffd85837caf03f263055fbbd14 (diff)
downloadruby-libmpd-ca0ac60d048ed34cc39be0414b14a51bb0408b82.tar.gz
ruby-libmpd-ca0ac60d048ed34cc39be0414b14a51bb0408b82.tar.xz
Add ability to send requests and get responses.
Diffstat (limited to 'mpdlib.rb')
-rw-r--r--mpdlib.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/mpdlib.rb b/mpdlib.rb
index 33c0585..c8266be 100644
--- a/mpdlib.rb
+++ b/mpdlib.rb
@@ -17,4 +17,23 @@ class MPD
@socket = TCPSocket.new @host, @port
return @socket.gets.chomp
end
+
+ def send_request command
+ # Escape backslashes in command.
+ @socket.puts command.sub('\\', '\\\\\\')
+ return get_response
+ end
+
+ def get_response
+ response = String.new
+
+ while true
+ line = @socket.gets
+
+ return response if line == "OK\n"
+ return false if line =~ /^ACK/
+
+ response << line
+ end
+ end
end