rmpd 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,7 @@ require File.join(File.dirname(__FILE__), "rmpd/response")
7
7
  module Rmpd
8
8
  ACK_RE = /^ACK \[(\d+)@(\d+)\] \{([^}]*)\} (.*)$/
9
9
  OK_RE = /^OK.*$/
10
+ LIST_OK_RE = /^list_OK.*$/
10
11
 
11
12
  class MpdError < StandardError ; end
12
13
 
@@ -15,11 +15,14 @@ module Rmpd
15
15
  end
16
16
 
17
17
  def receive_server_response
18
+ @last_response = nil
18
19
  lines = []
19
20
  while lines << @socket.readline do
20
21
  puts "recv: #{lines.last.strip} (#{OK_RE === lines.last})" if $DEBUG
21
22
  case lines.last
22
- when ACK_RE, OK_RE; break
23
+ when ACK_RE, OK_RE, LIST_OK_RE
24
+ @last_response = lines.last
25
+ break
23
26
  end
24
27
  end
25
28
  return lines.join
@@ -25,14 +25,46 @@ module Rmpd
25
25
  @in_command_list = true
26
26
  yield self
27
27
  send_command("command_list_end")
28
+ handle_command_list_response
29
+ ensure
30
+ @in_command_list = false
31
+ @in_command_list_response_regexp = nil
32
+ end
33
+
34
+ def command_list_ok
35
+ send_command("command_list_ok_begin")
36
+ @in_command_list = true
37
+ yield self
38
+ send_command("command_list_end")
39
+ read_command_list_ok_responses do |responses|
40
+ handle_command_list_response.tap do |res|
41
+ responses << res unless res.empty?
42
+ end
43
+ end
44
+ ensure
45
+ @in_command_list = false
46
+ @in_command_list_response_regexp = nil
47
+ end
48
+
49
+
50
+ private
51
+
52
+ def handle_command_list_response
28
53
  if @in_command_list_response_regexp
29
54
  read_responses(@in_command_list_response_regexp)
30
55
  else
31
56
  read_response
32
57
  end
33
- ensure
34
- @in_command_list = false
35
- @in_command_list_response_regexp = nil
58
+ end
59
+
60
+ def read_command_list_ok_responses
61
+ responses = []
62
+
63
+ begin
64
+ yield responses
65
+ end while LIST_OK_RE === @last_response
66
+
67
+ responses
36
68
  end
37
69
  end
38
70
  end
@@ -16,7 +16,7 @@ module Rmpd
16
16
  case config_file
17
17
  when String, Pathname
18
18
  config = YAML::load_file(config_file)
19
- when File
19
+ when File, StringIO
20
20
  config = YAML::load(config_file)
21
21
  else
22
22
  config = {}
@@ -4,7 +4,7 @@ module Rmpd
4
4
 
5
5
  KEY_VALUE_RE = /^([^:]+):\s*(.*)$/
6
6
  KNOWN_INT_FIELDS = [:pos, :id, :track, :playlistlength, :playlist,
7
- :xfade, :repeat, :random, :queued, :volume, :song]
7
+ :xfade, :repeat, :random, :queued, :volume, :song, :songid]
8
8
  KNOWN_COMPLEX_FIELDS = [:time,]
9
9
 
10
10
  class Response < DelegateClass(Hash)
@@ -39,7 +39,7 @@ module Rmpd
39
39
  data.split("\n").each do |line|
40
40
  case line
41
41
  when KEY_VALUE_RE; register_key_val_pair($~)
42
- when OK_RE; @error = nil
42
+ when LIST_OK_RE, OK_RE; @error = nil
43
43
  when ACK_RE; @error = MpdAckError.new($~.values_at(0..-1))
44
44
  end
45
45
  end
@@ -1,3 +1,3 @@
1
1
  module Rmpd
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -143,4 +143,20 @@ describe Rmpd::Commands do
143
143
  end
144
144
  end
145
145
  end
146
+
147
+ describe "command_list_ok" do
148
+ it "should return a list of multi responses" do
149
+ @responses = connect_response + command_list_ok_responses + ok
150
+ @socket.stub!(:readline).and_return(*@responses)
151
+ @socket.stub!(:puts).and_return(@socket.puts)
152
+ @socket.stub!(:eof?).and_return(false)
153
+
154
+ results = @conn.command_list_ok do |c|
155
+ c.list("album")
156
+ c.list("artist")
157
+ end
158
+
159
+ results.should have(2).items, results.pretty_inspect
160
+ end
161
+ end
146
162
  end
@@ -17,7 +17,7 @@ EOF
17
17
  end
18
18
 
19
19
  it "should have a size of 2" do
20
- @response.should have(2).items
20
+ @response.should have(2).items, @response.inspect
21
21
  end
22
22
 
23
23
  it "should be OK" do
@@ -46,3 +46,7 @@ end
46
46
  def ack(x=1, y=2, cmd="foo_command", msg="No one's home dopey!")
47
47
  ["ACK [#{x}@#{y}] {#{cmd}} #{msg}"]
48
48
  end
49
+
50
+ def command_list_ok_responses
51
+ ["Album: Foo\n", "list_OK\n", "Artist: Bar\n", "list_OK\n"]
52
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmpd
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 4
10
- version: 1.0.4
9
+ - 5
10
+ version: 1.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Eric Wollesen
@@ -15,13 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-07 00:00:00 -06:00
19
- default_executable:
18
+ date: 2012-08-17 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: rspec
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
23
  none: false
26
24
  requirements:
27
25
  - - ~>
@@ -33,11 +31,11 @@ dependencies:
33
31
  - 0
34
32
  version: 2.6.0
35
33
  type: :development
36
- version_requirements: *id001
34
+ requirement: *id001
35
+ prerelease: false
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: ruby-debug
39
- prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
39
  none: false
42
40
  requirements:
43
41
  - - ">="
@@ -47,11 +45,11 @@ dependencies:
47
45
  - 0
48
46
  version: "0"
49
47
  type: :development
50
- version_requirements: *id002
48
+ requirement: *id002
49
+ prerelease: false
51
50
  - !ruby/object:Gem::Dependency
52
51
  name: rake
53
- prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
53
  none: false
56
54
  requirements:
57
55
  - - ">="
@@ -61,7 +59,8 @@ dependencies:
61
59
  - 0
62
60
  version: "0"
63
61
  type: :development
64
- version_requirements: *id003
62
+ requirement: *id003
63
+ prerelease: false
65
64
  description: Music Player Daemon client in Ruby
66
65
  email:
67
66
  - ericw@xmtp.net
@@ -106,7 +105,6 @@ files:
106
105
  - spec/spec.opts
107
106
  - spec/spec_helper.rb
108
107
  - spec/spec_rcov.opts
109
- has_rdoc: true
110
108
  homepage: http://github.com/ewollesen/rmpd
111
109
  licenses: []
112
110
 
@@ -136,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
134
  requirements: []
137
135
 
138
136
  rubyforge_project:
139
- rubygems_version: 1.6.2
137
+ rubygems_version: 1.8.24
140
138
  signing_key:
141
139
  specification_version: 3
142
140
  summary: Music Player Daemon client in Ruby