03 July 2006
RubySlim - Ruby API for SlimServer
Just a small announcement for any other Squeezebox/Soundbridge owners out there who use the SlimServer music server. I've started work on a Ruby API for it and you can view the latest source on the Agile Evolved Open Source Trac.
You can also check out the latest source code from Subversion.
Here's a small code example:
slimserver = RubySlim::SlimServer.open('localhost')
slimserver.connect('myusername', 'mypassword')
puts slimserver.version
squeezebox = slimserver.players.first
squeezebox.turn_on
squeezebox.current_playlist.play
And in the future...a full RubyOnRails, AJAX-enabled front-end to the SlimServer for browsing your music collection, creating playlists, controlling your SqueezeBox and more. I've not checked anything in on this but I've already been experimenting with creating ActiveRecord models that interact with the SlimServer database. You could do something like this (this is actual code that I have got working):
squeezebox.turn_on
my_favorite_album = Album.find_by_title('The Number Of The Beast')
squeezebox.current_playlist.load :album => my_favorite_album.id
Finally, if you have access to the SlimServer CLI API (click on technical information on your SlimServer web interface menu) you can play with any parts of the CLI API that I'm yet to add to the Ruby API by using the raw connection and API object:
# make sure you are using the CLI port, not the web interface port
connection = RubySlim::SlimServer.raw_connection('localhost', 9090)
slimapi = RubySlim::SlimAPI.new(connection)
# invoke any api commands
slimapi.invoke("version")
slimapi.invoke("myplayerid player status")
For those interested in the concept of behaviour-driven development, the whole thing is specced using rSpec. Admittedly its not the greatest exercise in BDD because I'm simply wrapping an existing API in a Ruby API so there wasn't more than 1 context for most classes, but it was still great to use and the built-in mock objects API -- which seems very similar to FlexMock -- was very easy to get to grips with - great for mocking out those telnet connections to the SlimServer CLI.
Update: RubySlim is now hosted as a RubyForge project. The 0.1 release is available as a gem.
$ gem install rubyslim
Return to home page | Check out my tumblelog
7 Comments on this article
Return to home page | Check out my tumblelog
1. Comment by Andrew Turner on 12 Jul 2006 at 01:07
Really great idea. I would like to get this working – however the authentication fails and actually kills irb.
./slimserver.rb:25:in `connect': AuthenticationError (AuthenticationError) from (irb):3:in `irb_binding' from /usr/local/lib/ruby/1.8/irb/workspace.rb:52:in `irb_binding' from /usr/local/lib/ruby/1.8/irb/workspace.rb:52I don’t have Authentication turned on for my SlimServer – but even when I tried that (by setting it in the web control panel) it didn’t authenticate.
Ideas?
2. Comment by Jed Hurt on 15 Jul 2006 at 07:07
Hey Luke, It’s great to get a real world example of implementing rSpec with Rails. I remember in the RailsDay campfire you were talking about doing a write-up on rSpec. Are you still thinking about doing that?
3. Comment by Andrew Turner on 18 Jul 2006 at 00:07
Ok, this ended up working as “spec’d” after I downgraded from 6.5 beta to the stable 6.3. I don’t know what changed in 6.5, but not worth figuring out at this point.
What’s the progress on making a web-interface? Are you making this open-source?
4. Comment by Luke on 25 Jul 2006 at 10:07
Hi Andrew, the web interface is in the very early stages. As cliche as it is, I will probably release an early version soon to get some feedback. It will be open-source.
5. Comment by ed on 18 Dec 2006 at 06:12
Great idea. Been hacking away at some addons. How is the progress coming? Need some help? Let me know.
ed
6. Comment by Kevin on 24 Jan 2008 at 07:01
Just wanted to check and see if there were any updates before I tried to start hacking this to get it working with 7.0. Thanks!
7. Comment by Mat on 15 Jun 2008 at 16:06
I saw this post from Kevin and read this page and would be very interesting in any finished or semi-finished project for remote control of Slimserver
thanks