Skip to content

Commit

Permalink
Add options for pause() (#191)
Browse files Browse the repository at this point in the history
* Avoid passing device_id in body parameters
* Add device_id to pause
  • Loading branch information
JMPerez authored Mar 8, 2018
1 parent 10d44d8 commit 73010ca
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/spotify-web-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ SpotifyWebApi.prototype = {

/**
* Starts o Resumes the Current User's Playback
* @param {Object} [options] Options, being context_uri, offset, uris.
* @param {Object} [options] Options, being device_id, context_uri, offset, uris.
* @param {requestCallback} [callback] Optional callback method to be called instead of the promise.
* @example playbackResume({context_uri: 'spotify:album:5ht7ItJgpBH7W6vJ5BqpPr'}).then(...)
* @returns {Promise|undefined} A promise that if successful, resolves into a paging object of tracks,
Expand All @@ -1103,14 +1103,17 @@ SpotifyWebApi.prototype = {

/**
* Pauses the Current User's Playback
* @param {Object} [options] Options, for now device_id,
* @param {requestCallback} [callback] Optional callback method to be called instead of the promise.
* @example playbackPause().then(...)
* @returns {Promise|undefined} A promise that if successful, resolves into a paging object of tracks,
* otherwise an error. Not returned if a callback is given.
*/
pause: function(callback) {
pause: function(options, callback) {
return WebApiRequest.builder(this.getAccessToken())
.withPath('/v1/me/player/pause')
/*jshint camelcase: false */
.withQueryParameters(options && options.device_id ? {device_id: options.device_id} : null)
.withHeaders({ 'Content-Type' : 'application/json' })
.build()
.execute(HttpManager.put, callback);
Expand Down
25 changes: 25 additions & 0 deletions test/spotify-web-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,31 @@ describe('Spotify Web API', function() {

});

it('should pause the user\'s playback with options', function(done) {

sinon.stub(HttpManager, '_makeRequest', function(method, options, uri, callback) {
method.should.equal(superagent.put);
uri.should.equal('https://api.spotify.com/v1/me/player/pause');
options.query.should.eql({device_id: 'my_device_id'});
callback();
});

var accessToken = 'myAccessToken';

var api = new SpotifyWebApi({
accessToken : accessToken
});

api.pause({device_id: 'my_device_id'})
.then(function(data) {
done();
}, function(err) {
console.log(err);
done(err);
});

});

it('should skip the user\'s playback to next track', function(done) {

sinon.stub(HttpManager, '_makeRequest', function(method, options, uri, callback) {
Expand Down

0 comments on commit 73010ca

Please sign in to comment.