GreenStripes: Ruby bindings for libspotify

April 15, 2009

About a week ago, Spotify released libspotify, a C API for writing applications that utilize their service.

Now, while I’m certainly not averse to C, I think that a more human-friendly language is a better fit for many tasks. So I whipped up a set of Ruby bindings that lets you write programs like this one:

session = GreenStripes::Session.new(APPLICATION_KEY, 'GreenStripes', 'tmp', 'tmp')
session.login(USERNAME, PASSWORD)
session.process_events until session.connection_state == GreenStripes::ConnectionState::LOGGED_IN

search = GreenStripes::Search.new(session, 'yakety sax', 0, 100)
session.process_events until search.loaded?
puts "found #{search.num_tracks} tracks"
if search.num_tracks > 0
  track = search.track(0)
  session.process_events until track.loaded? and track.artist(0).loaded?
  puts "the first one is #{track.name} by #{track.artist(0).name}"
end

session.logout
session.process_events until session.connection_state == GreenStripes::ConnectionState::LOGGED_OUT

GreenStripes is very much in a beta stage, lacks features and has bugs, but it’s gotten to a point where you can actually play around with it and build stuff.

Interested? GreenStripes is available in source or gem form from GitHub, where you can also read installation instructions and sign up to be notified of updates: