squeezer-ruby 0.1.1 → 0.2.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.
@@ -16,11 +16,11 @@ describe Squeezer::Client do
16
16
  end
17
17
 
18
18
  it "should return a player's id" do
19
- @client.players["player_id"].id.should == "player_id"
19
+ @client.players.first.id.should == "player_id"
20
20
  end
21
21
 
22
22
  it "should return a player's name" do
23
- @client.players["player_id"].name.should == "Squeezebox"
23
+ @client.players.first.name.should == "Squeezebox"
24
24
  end
25
25
 
26
26
  end
@@ -0,0 +1,268 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe Squeezer::Models::Player do
4
+ before do
5
+ @player = Squeezer::Models::Player.new("player_id")
6
+ stub_connection.with("player name player_id ?").returns("player name player_id Squeezebox")
7
+ stub_connection.with("player ip player_id ?").returns("player ip player_id 127.0.0.1%3A12345")
8
+ stub_connection.with("player model player_id ?").returns("player model player_id squeezebox")
9
+ stub_connection.with("player displaytype player_id ?").returns("player displaytype player_id graphic-320x32")
10
+ stub_connection.with("player canpoweroff player_id ?").returns("player canpoweroff player_id 1")
11
+ end
12
+
13
+ describe "sorting" do
14
+ it "should sort by name" do
15
+ stub_connection.with("player name player_id1 ?").returns("player name player_id1 SqueezeboxA")
16
+ stub_connection.with("player name player_id2 ?").returns("player name player_id2 SqueezeboxB")
17
+ player1 = Squeezer::Models::Player.new("player_id1")
18
+ player2 = Squeezer::Models::Player.new("player_id2")
19
+
20
+ (player1 <=> player2).should == -1
21
+ (player2 <=> player1).should == 1
22
+ (player1 <=> player1).should == 0
23
+ (player2 <=> player2).should == 0
24
+ end
25
+ end
26
+
27
+ describe ".name" do
28
+ it "should return the player's name" do
29
+ @player.name.should == "Squeezebox"
30
+ end
31
+
32
+ it "should cache the player's name" do
33
+ @player.name.should == "Squeezebox"
34
+ stub_connection.with("player name player_id ?").never
35
+ @player.name.should == "Squeezebox"
36
+ end
37
+ end
38
+
39
+ describe ".ip" do
40
+ it "should return the player's ip" do
41
+ @player.ip.should == "127.0.0.1"
42
+ end
43
+
44
+ it "should cache the player's ip" do
45
+ @player.ip.should == "127.0.0.1"
46
+ stub_connection.with("player ip player_id ?").never
47
+ @player.ip.should == "127.0.0.1"
48
+ end
49
+ end
50
+
51
+ describe ".model" do
52
+ it "should return the player's model" do
53
+ @player.model.should == "squeezebox"
54
+ end
55
+
56
+ it "should cache the player's model" do
57
+ @player.model.should == "squeezebox"
58
+ stub_connection.with("player model player_id ?").never
59
+ @player.model.should == "squeezebox"
60
+ end
61
+ end
62
+
63
+ describe ".is_a?" do
64
+ it "should test the player's model" do
65
+ @player.is_a?("squeezebox").should be true
66
+ end
67
+ end
68
+
69
+ describe ".display_type" do
70
+ it "should return the player's display type" do
71
+ @player.display_type.should == "graphic-320x32"
72
+ end
73
+
74
+ it "should cache the player's display type" do
75
+ @player.display_type.should == "graphic-320x32"
76
+ stub_connection.with("player displaytype player_id ?").never
77
+ @player.display_type.should == "graphic-320x32"
78
+ end
79
+ end
80
+
81
+ describe ".can_power_off?" do
82
+ it "should return the player's capability to turn itself off" do
83
+ @player.can_power_off.should be true
84
+ end
85
+
86
+ it "should cache the player's capability to turn itself off" do
87
+ @player.can_power_off.should be true
88
+ stub_connection.with("player canpoweroff player_id ?").never
89
+ @player.can_power_off.should be true
90
+ end
91
+ end
92
+
93
+ describe ".signal_strength" do
94
+ it "should return the player's signal strength" do
95
+ stub_connection.with("player_id signalstrength ?").returns("player_id signalstrength 65")
96
+ @player.signal_strength.should be 65
97
+ end
98
+ end
99
+
100
+ describe ".wireless?" do
101
+ it "should return true if the player is connected through a wireless connection" do
102
+ stub_connection.with("player_id signalstrength ?").returns("player_id signalstrength 65")
103
+ @player.wireless?.should be true
104
+ end
105
+
106
+ it "should return false if the player is connected through a physical wire" do
107
+ stub_connection.with("player_id signalstrength ?").returns("player_id signalstrength 0")
108
+ @player.wireless?.should be false
109
+ end
110
+ end
111
+
112
+ describe ".connected?" do
113
+ it "should return true if the player is connected to the server" do
114
+ stub_connection.with("player_id connected ?").returns("player_id connected 1")
115
+ @player.connected?.should be true
116
+ stub_connection.with("player_id connected ?").returns("player_id connected 0")
117
+ @player.connected?.should be false
118
+ end
119
+ end
120
+
121
+ describe " mixers" do
122
+ it "should alter mixer levels" do
123
+
124
+ %w{volume bass treble pitch}.each do |mixer|
125
+ stub_connection.with("player_id mixer #{mixer} ?").returns("player_id mixer #{mixer} 65")
126
+ @player.send(mixer.to_sym).should be 65
127
+
128
+ stub_connection.with("player_id mixer #{mixer} +20").returns("player_id mixer #{mixer} +20")
129
+ @player.send("#{mixer}=", "+20").should be true
130
+ stub_connection.with("player_id mixer #{mixer} -20").returns("player_id mixer #{mixer} -20")
131
+ @player.send("#{mixer}=", "-20").should be true
132
+ stub_connection.with("player_id mixer #{mixer} 20").returns("player_id mixer #{mixer} 20")
133
+ @player.send("#{mixer}=", 20).should be true
134
+ stub_connection.with("player_id mixer #{mixer} -20").returns("player_id mixer #{mixer} -20")
135
+ @player.send("#{mixer}=", -20).should be true
136
+ end
137
+ end
138
+ end
139
+
140
+ describe ".power?" do
141
+ it "should show the current power state" do
142
+ stub_connection.with("player_id power ?").returns("player_id power 1")
143
+ @player.power?.should == :on
144
+
145
+ stub_connection.with("player_id power ?").returns("player_id power 0")
146
+ @player.power?.should == :off
147
+ end
148
+ end
149
+
150
+ describe ".on?" do
151
+ it "should be true when the player is turned on" do
152
+ stub_connection.with("player_id power ?").returns("player_id power 1")
153
+ @player.on?.should be true
154
+ end
155
+ end
156
+
157
+ describe ".off?" do
158
+ it "should be true when the player is turned off" do
159
+ stub_connection.with("player_id power ?").returns("player_id power 0")
160
+ @player.off?.should be true
161
+ end
162
+ end
163
+
164
+ describe ".on!" do
165
+ it "should turn the player on" do
166
+ stub_connection.with("player_id power 1").returns("player_id power 1")
167
+ @player.on!.should be true
168
+ end
169
+ end
170
+
171
+ describe ".off!" do
172
+ it "should turn the player off" do
173
+ stub_connection.with("player_id power 0").returns("player_id power 0")
174
+ @player.off!.should be true
175
+ end
176
+ end
177
+
178
+ describe ".find" do
179
+ it "should find a player by a combination of search arguments" do
180
+ stub_connection.with("player count ?").returns("1\n")
181
+ stub_connection.with("player id 0 ?").returns("player id 0 player_id\n")
182
+ Squeezer::Models::Player.find(:id => "player_id", :ip => "127.0.0.1", :name => "Squeezebox").nil?.should be false
183
+ end
184
+ end
185
+
186
+ context "player modes" do
187
+ describe ".play" do
188
+ it "should set a player to playing mode" do
189
+ stub_connection.with("player_id play 0").returns("player_id play 0")
190
+ @player.play.should be true
191
+ end
192
+
193
+ it "should set a player to playing mode with a fadeIn" do
194
+ stub_connection.with("player_id play 10").returns("player_id play 10")
195
+ @player.play(10).should be true
196
+ end
197
+ end
198
+
199
+ describe ".pause" do
200
+ it "should pause player" do
201
+ stub_connection.with("player_id pause").returns("player_id pause")
202
+ @player.pause.should be true
203
+ end
204
+ end
205
+
206
+ describe ".stop" do
207
+ it "should stop player" do
208
+ stub_connection.with("player_id stop").returns("player_id stop")
209
+ @player.stop.should be true
210
+ end
211
+ end
212
+
213
+ describe ".blink" do
214
+ it "should blink a message on the player's screen" do
215
+ stub_connection.at_least(3).with("player_id show font:huge line2:Hello%20World centered:true duration:0.1").returns("player_id show font:huge line2:Hello%20World centered:true duration:0.1")
216
+ @player.blink("Hello World", 3, 0.1)
217
+ end
218
+ end
219
+
220
+ describe ".alert" do
221
+ it "should alert a message on the player's screen" do
222
+ stub_connection.with("player_id show font:huge line2:Hello%20World centered:true duration:3").returns("player_id show font:huge line2:Hello%20World centered:true duration:3")
223
+ @player.alert("Hello World")
224
+ end
225
+ end
226
+
227
+ describe ".playlist" do
228
+ it "should return a playlist model for this player" do
229
+ playlist = @player.playlist
230
+ playlist.should be_a Squeezer::Models::Playlist
231
+ playlist.id.should == @player.id
232
+ end
233
+ end
234
+
235
+ describe ".mode" do
236
+ it "should return the player's state if playing" do
237
+ stub_connection.with("player_id mode ?").returns("player_id mode play")
238
+ @player.mode.should == :play
239
+ end
240
+
241
+ it "should return the player's state if playing" do
242
+ stub_connection.with("player_id mode ?").returns("player_id mode play")
243
+ @player.playing?.should be true
244
+ end
245
+
246
+ it "should return the player's state if paused" do
247
+ stub_connection.with("player_id mode ?").returns("player_id mode pause")
248
+ @player.mode.should == :pause
249
+ end
250
+
251
+ it "should return the player's state if paused" do
252
+ stub_connection.with("player_id mode ?").returns("player_id mode pause")
253
+ @player.paused?.should be true
254
+ end
255
+
256
+ it "should return the player's state if stopped" do
257
+ stub_connection.with("player_id mode ?").returns("player_id mode stop")
258
+ @player.mode.should == :stop
259
+ end
260
+
261
+ it "should return the player's state if stopped" do
262
+ stub_connection.with("player_id mode ?").returns("player_id mode stop")
263
+ @player.stopped?.should be true
264
+ end
265
+ end
266
+ end
267
+
268
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe Squeezer::Models::Playlist do
4
+ before do
5
+ @playlist = Squeezer::Models::Playlist.new("player_id")
6
+
7
+ # TODO test more entities
8
+ @artist = Squeezer::Models::Artist.new(:id => 1, :artist => "Awesome Artist")
9
+ end
10
+
11
+ describe ".add" do
12
+ it "should add an entity to the playlist" do
13
+ stub_connection.with("player_id playlistcontrol cmd:add artist_id:1").returns("player_id playlistcontrol cmd:add artist_id:1")
14
+
15
+ @playlist.add(@artist).should be true
16
+ end
17
+ end
18
+
19
+ describe ".load" do
20
+ it "should add an entity to the playlist and replace the original contents" do
21
+ stub_connection.with("player_id playlistcontrol cmd:load artist_id:1").returns("player_id playlistcontrol cmd:load artist_id:1")
22
+
23
+ @playlist.load(@artist).should be true
24
+ end
25
+ end
26
+
27
+ describe ".clear" do
28
+ it "should clear the current playlist" do
29
+ stub_connection.with("player_id playlist clear").returns("player_id playlist clear")
30
+
31
+ @playlist.clear.should be true
32
+ end
33
+ end
34
+ end
@@ -6,12 +6,20 @@ describe Squeezer do
6
6
  end
7
7
 
8
8
  context "when delegating to a client" do
9
-
10
9
  it "should return the same results as a client" do
11
10
  stub_connection.with("version ?").returns("version x.x.x\n")
12
11
  Squeezer.version.should == Squeezer::Client.new.version
13
12
  end
14
-
13
+ end
14
+
15
+ describe ".open" do
16
+ it "should run commands in a block" do
17
+ stub_connection.with("version ?").at_least_once.returns("version x.x.x\n")
18
+ stub_connection.with("exit").at_least_once
19
+ Squeezer.open do |client|
20
+ version.should == "x.x.x"
21
+ end
22
+ end
15
23
  end
16
24
 
17
25
  describe ".client" do
data/squeezer.gemspec CHANGED
@@ -9,6 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.add_development_dependency('simplecov', '~> 0.3')
10
10
  s.add_development_dependency('maruku', '~> 0.6')
11
11
  s.add_development_dependency('yard', '~> 0.6')
12
+ s.add_development_dependency('spork', '~> 0.8.4')
13
+ s.add_development_dependency('autotest-standalone', '~> 4.5.5')
12
14
 
13
15
  s.authors = ["Daniël van Hoesel"]
14
16
  s.description = %q{A Ruby wrapper for the Squeezebox Server CLI API}
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Dani\xC3\xABl van Hoesel"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-08 00:00:00 +01:00
17
+ date: 2011-02-20 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -116,6 +116,36 @@ dependencies:
116
116
  version: "0.6"
117
117
  type: :development
118
118
  version_requirements: *id007
119
+ - !ruby/object:Gem::Dependency
120
+ name: spork
121
+ prerelease: false
122
+ requirement: &id008 !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ~>
126
+ - !ruby/object:Gem::Version
127
+ segments:
128
+ - 0
129
+ - 8
130
+ - 4
131
+ version: 0.8.4
132
+ type: :development
133
+ version_requirements: *id008
134
+ - !ruby/object:Gem::Dependency
135
+ name: autotest-standalone
136
+ prerelease: false
137
+ requirement: &id009 !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ~>
141
+ - !ruby/object:Gem::Version
142
+ segments:
143
+ - 4
144
+ - 5
145
+ - 5
146
+ version: 4.5.5
147
+ type: :development
148
+ version_requirements: *id009
119
149
  description: A Ruby wrapper for the Squeezebox Server CLI API
120
150
  email:
121
151
  - daniel@danielvanhoesel.nl
@@ -126,7 +156,9 @@ extensions: []
126
156
  extra_rdoc_files: []
127
157
 
128
158
  files:
159
+ - .autotest
129
160
  - .gitignore
161
+ - .rspec
130
162
  - Gemfile
131
163
  - LICENSE.mkd
132
164
  - README.mkd
@@ -143,13 +175,20 @@ files:
143
175
  - lib/squeezer/connection.rb
144
176
  - lib/squeezer/core_extentions.rb
145
177
  - lib/squeezer/models.rb
178
+ - lib/squeezer/models/album.rb
146
179
  - lib/squeezer/models/artist.rb
180
+ - lib/squeezer/models/genre.rb
147
181
  - lib/squeezer/models/player.rb
182
+ - lib/squeezer/models/playlist.rb
183
+ - lib/squeezer/models/track.rb
148
184
  - lib/squeezer/version.rb
185
+ - script/console
149
186
  - spec/spec_helper.rb
150
187
  - spec/squeezer/client/database_spec.rb
151
188
  - spec/squeezer/client/general_spec.rb
152
189
  - spec/squeezer/client/players_spec.rb
190
+ - spec/squeezer/models/player_spec.rb
191
+ - spec/squeezer/models/playlist_spec.rb
153
192
  - spec/squeezer_spec.rb
154
193
  - squeezer.gemspec
155
194
  has_rdoc: true
@@ -186,5 +225,11 @@ rubygems_version: 1.3.7
186
225
  signing_key:
187
226
  specification_version: 3
188
227
  summary: Ruby wrapper for the Squeezebox Server CLI API
189
- test_files: []
190
-
228
+ test_files:
229
+ - spec/spec_helper.rb
230
+ - spec/squeezer/client/database_spec.rb
231
+ - spec/squeezer/client/general_spec.rb
232
+ - spec/squeezer/client/players_spec.rb
233
+ - spec/squeezer/models/player_spec.rb
234
+ - spec/squeezer/models/playlist_spec.rb
235
+ - spec/squeezer_spec.rb