Ejemplo n.º 1
0
static VALUE
rb_ds_playlist_new (VALUE self, VALUE sessionv, VALUE id)
{
	rb_ds_session *session;
	rb_ds_playlist *pls;
	ds_playlist_t *pl;
	char *playlist_id;

	VALUE2PLAYLIST(self, pls);
	VALUE2SESSION(sessionv, session);
	playlist_id = StringValuePtr(id);

	if (strlen(playlist_id) != 34)
		return Qnil;

	pl = despotify_get_playlist(session->real, playlist_id);
	if (!pl)
		return Qnil;

	pls->real = pl;
	pls->ischild = false;

	rb_iv_set(self, "session", sessionv);

	if (rb_block_given_p())
		rb_yield(self);

	return self;
}
Ejemplo n.º 2
0
void
rb_ds_session_error (VALUE session)
{
	rb_ds_session *sessionptr;
	VALUE2SESSION(session, sessionptr);

	rb_raise(eDespotifyError, sessionptr->real->last_error);
}
Ejemplo n.º 3
0
static VALUE
rb_ds_session_authenticate (VALUE self, VALUE username, VALUE password)
{
	rb_ds_session *session;
	VALUE2SESSION(self, session);

	if (!despotify_authenticate(session->real, StringValuePtr(username),
	                            StringValuePtr(password)))
		rb_ds_session_error(self);
	else
		session->connected = true;

	return self;
}
Ejemplo n.º 4
0
static VALUE
rb_ds_session_new (VALUE self)
{
	rb_ds_session *session;
	VALUE2SESSION(self, session);

	if (!(session->real = despotify_init_client(rb_ds_session_callback, (void *) self, 0, 0))) {
		rb_raise(rb_eNoMemError, "failed to allocate memory");
		return Qnil;
	}

	session->rootpl = NULL;
	session->connected = false;

	if (rb_block_given_p())
		rb_yield(self);

	return self;
}