You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Should all object be available through the session? #37
I'm wondering what peoples thoughts would be on interacting with all sub systems via single session object?
I think it makes the API a little cleaner.
Example chanegs to libspotify.js:
// **libspotify.jsvarSession=require('./Session');varb=require('bindings')('spotify.node');functionSpotify(config){this.config=config||{};}Spotify.prototype.login=function(user,pass,cb){varsess=newSession({applicationKey: this.config.applicationKey});// Use callback as main event handlersess.login(user,pass,cb);}exports=Spotify;
Example changes to session.js:
Session.prototype.login=functionlogin(login,password,cb){if('string'!=typeoflogin)thrownewTypeError('login should be a string');if('string'!=typeofpassword)thrownewTypeError('password should be a string');if('function'!=typeofcb)cb=function(){};varself=this;this.once('login',function(err){returncb(err,self);});b.session_login(this._sp_session,login,password);};+Session.prototype.search=function(query,options,cb){vars=newSearch(this._sp_session,query);s.once('ready',cb);for(variinoptions){s[i]=options[i];}// Run the searchs.execute();}
In your script:
// Create new Spotify instancevarSpotify=newsp.Spotify({applicationKey: __dirname+'/../conf/spotify_appkey.key'});// Login and find something to playSpotify.login(cred.login,cred.password,function(err,session){console.log(session);// should log Session object// session is now an object to work with.// all processing/searching/playing would be done via session.session.search('sometrack',{trackCount:20},function(err,search){console.log(search);// Should log the Search object});});
Activity