ruby-mpd-client 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mpd/client.rb +15 -6
- data/lib/mpd/client/connection.rb +2 -8
- data/lib/mpd/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b876a3e06965ebe7e8f061cc8430dd2f7ee1dbb
|
4
|
+
data.tar.gz: 8c8bc0f8cff555d558cbe02d350fa0b2c3f643b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 915464ea5f307fa7f4c7ad16530cdf3f41065953868f63d0f8ffb915433ad5f9ae65254743b4e5a89fb01d4d390b0d53f93c7f86551e46d7f8e1fc87866cdd14
|
7
|
+
data.tar.gz: 8860d06293f29478b684ce8a4465ae13d3e51e8950f43a049a1c07fbb3aadfe3ecedd08721f872981cbb3115acd7fa174eba317fd2534558c750fbdfbfa573ac
|
data/lib/mpd/client.rb
CHANGED
@@ -4,7 +4,9 @@ require 'mpd/client/commands'
|
|
4
4
|
|
5
5
|
module MPD
|
6
6
|
class Client
|
7
|
-
|
7
|
+
def self.connect(host: 'localhost', port: 6600)
|
8
|
+
new(host: host, port: port).tap(&:connect)
|
9
|
+
end
|
8
10
|
|
9
11
|
def initialize(host: 'localhost', port: 6600)
|
10
12
|
@connection = Connection.new(host: host, port: port)
|
@@ -20,19 +22,26 @@ module MPD
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def execute(command)
|
23
|
-
ensure_connection_established
|
24
25
|
connection.puts(command)
|
25
26
|
response = ServerResponse.from_connection(connection)
|
26
27
|
raise(MpdError, response.status) if response.error?
|
27
28
|
response
|
28
29
|
end
|
29
30
|
|
30
|
-
|
31
|
+
def connected?
|
32
|
+
execute('ping')
|
33
|
+
rescue => e
|
34
|
+
raise e if e.is_a?(MpdError)
|
35
|
+
false
|
36
|
+
end
|
31
37
|
|
32
|
-
def
|
33
|
-
return if connection.connected?
|
38
|
+
def connect
|
34
39
|
connection.connect
|
35
|
-
connection.gets
|
40
|
+
raise(ConnectionError) unless connection.gets =~ /^OK/
|
36
41
|
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
attr_reader :connection
|
37
46
|
end
|
38
47
|
end
|
@@ -16,21 +16,15 @@ module MPD
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def puts(text)
|
19
|
-
raise ConnectionError unless
|
19
|
+
raise ConnectionError unless socket
|
20
20
|
socket.puts(text)
|
21
21
|
end
|
22
22
|
|
23
23
|
def gets
|
24
|
-
raise ConnectionError unless
|
24
|
+
raise ConnectionError unless socket
|
25
25
|
socket.gets
|
26
26
|
end
|
27
27
|
|
28
|
-
def connected?
|
29
|
-
socket && !socket.closed?
|
30
|
-
rescue
|
31
|
-
false
|
32
|
-
end
|
33
|
-
|
34
28
|
private
|
35
29
|
|
36
30
|
attr_reader :socket, :host, :port
|
data/lib/mpd/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-mpd-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitriy Non
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|