Skip to content
This repository has been archived by the owner on Aug 6, 2018. It is now read-only.

Commit

Permalink
Update to libspotify 0.0.6 (closes #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Burgestrand committed Nov 25, 2010
1 parent 6469fdb commit 2cee7ae
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ext/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
end

# check for libspotify
unless have_func 'sp_session_init' or have_library 'spotify', 'sp_session_init'
unless have_func 'sp_session_release' or have_library 'spotify', 'sp_session_release'
abort 'error: libspotify not installed'
end

Expand Down
33 changes: 25 additions & 8 deletions ext/hallon.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,21 @@ static sp_playlist_callbacks g_playlist_callbacks = {
*/
static VALUE ciSession_alloc(VALUE self)
{
sp_session **psession;
sp_session **psession = xmalloc(sizeof (void*));
return Data_Make_Struct(self, sp_session*, 0, -1, psession);
}

/**
* Internal method: release an allocated spotify session.
*/
static void ciSession_free(VALUE self)
{
sp_session **psession;
Data_Get_Struct(self, sp_session*, psession);
sp_session_release(DATA_PPTR(self, sp_session));
xfree(psession);
}

/**
* call-seq:
* login(username, password) -> Session
Expand Down Expand Up @@ -384,7 +395,7 @@ static VALUE cSession_initialize(int argc, VALUE *argv, VALUE self)

sp_session **psession;
Data_Get_Struct(self, sp_session*, psession);
sp_error error = sp_session_init(&config, &(*psession));
sp_error error = sp_session_create(&config, &(*psession));

if (error != SP_ERROR_OK)
{
Expand Down Expand Up @@ -950,9 +961,12 @@ static VALUE cTrack_loaded(VALUE self)
*
* True if the track is available for playback.
*/
static VALUE cTrack_available(VALUE self)
static VALUE cTrack_available(VALUE self, VALUE session)
{
return sp_track_is_available(DATA_PPTR(self, sp_track)) ? Qtrue : Qfalse;
return sp_track_is_available(
DATA_PPTR(session, sp_session),
DATA_PPTR(self, sp_track)
) ? Qtrue : Qfalse;
}

/**
Expand All @@ -972,9 +986,12 @@ static VALUE cTrack_to_link(VALUE self)
*
* True if the track is starred.
*/
static VALUE cTrack_starred(VALUE self)
static VALUE cTrack_starred(VALUE self, VALUE session)
{
return sp_track_is_starred(DATA_PPTR(self, sp_track)) ? Qtrue : Qfalse;
return sp_track_is_starred(
DATA_PPTR(session, sp_session),
DATA_PPTR(self, sp_track)
) ? Qtrue : Qfalse;
}

/**
Expand Down Expand Up @@ -1121,9 +1138,9 @@ void Init_hallon()
rb_define_method(cTrack, "initialize", cTrack_initialize, 0);
rb_define_method(cTrack, "name", cTrack_name, 0);
rb_define_method(cTrack, "loaded?", cTrack_loaded, 0);
rb_define_method(cTrack, "available?", cTrack_available, 0);
rb_define_method(cTrack, "available?", cTrack_available, 1);
rb_define_method(cTrack, "to_link", cTrack_to_link, 0);
rb_define_method(cTrack, "starred?", cTrack_starred, 0);
rb_define_method(cTrack, "starred?", cTrack_starred, 1);
rb_define_method(cTrack, "duration", cTrack_duration, 0);
rb_define_method(cTrack, "error", cTrack_error, 0);
rb_define_method(cTrack, "popularity", cTrack_popularity, 0);
Expand Down
2 changes: 1 addition & 1 deletion spec/hallon_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe Hallon do
describe "API version" do
specify { Hallon::API_VERSION.should equal 4 }
specify { Hallon::API_VERSION.should equal 6 }
end

describe "URI" do
Expand Down
7 changes: 5 additions & 2 deletions spec/track_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

describe Hallon::Track do
before :all do
@track = Hallon::Link.new(TRACK_URI).to_obj
Expand All @@ -19,7 +18,11 @@
end

it "should not be starred" do
@track.starred?.should equal false
@track.starred?(Hallon::Session.instance).should equal false
end

it "should be available" do
@track.available?(Hallon::Session.instance).should equal true
end

it "should have a duration" do
Expand Down

0 comments on commit 2cee7ae

Please sign in to comment.