Class: MPD::Client
- Inherits:
-
Object
show all
- Defined in:
- lib/mpd/client.rb,
lib/mpd/client/commands.rb,
lib/mpd/client/connection.rb,
lib/mpd/client/server_response.rb,
lib/mpd/client/commands/playback_control.rb,
lib/mpd/client/commands/playback_options.rb
Defined Under Namespace
Modules: Commands
Classes: Connection, ServerResponse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(host: 'localhost', port: 6600) ⇒ Client
Returns a new instance of Client.
11
12
13
|
# File 'lib/mpd/client.rb', line 11
def initialize(host: 'localhost', port: 6600)
@connection = Connection.new(host: host, port: port)
end
|
Class Method Details
.connect(host: 'localhost', port: 6600) ⇒ Object
7
8
9
|
# File 'lib/mpd/client.rb', line 7
def self.connect(host: 'localhost', port: 6600)
new(host: host, port: port).tap(&:connect)
end
|
Instance Method Details
#connect ⇒ Object
38
39
40
41
|
# File 'lib/mpd/client.rb', line 38
def connect
connection.connect
raise(ConnectionError) unless connection.gets =~ /^OK/
end
|
#connected? ⇒ Boolean
31
32
33
34
35
36
|
# File 'lib/mpd/client.rb', line 31
def connected?
execute('ping')
rescue => e
raise e if e.is_a?(MpdError)
false
end
|
#current_song ⇒ Object
15
16
17
|
# File 'lib/mpd/client.rb', line 15
def current_song
execute('currentsong').to_h
end
|
#execute(command) ⇒ Object
24
25
26
27
28
29
|
# File 'lib/mpd/client.rb', line 24
def execute(command)
connection.puts(command)
response = ServerResponse.from_connection(connection)
raise(MpdError, response.status) if response.error?
response
end
|
#status ⇒ Object
19
20
21
22
|
# File 'lib/mpd/client.rb', line 19
def status
response = execute('status')
response.to_h
end
|