Skip to content

Commit 73010ca

Browse files
authored
Add options for pause() (#191)
* Avoid passing device_id in body parameters * Add device_id to pause
1 parent 10d44d8 commit 73010ca

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/spotify-web-api.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ SpotifyWebApi.prototype = {
10761076

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

11041104
/**
11051105
* Pauses the Current User's Playback
1106+
* @param {Object} [options] Options, for now device_id,
11061107
* @param {requestCallback} [callback] Optional callback method to be called instead of the promise.
11071108
* @example playbackPause().then(...)
11081109
* @returns {Promise|undefined} A promise that if successful, resolves into a paging object of tracks,
11091110
* otherwise an error. Not returned if a callback is given.
11101111
*/
1111-
pause: function(callback) {
1112+
pause: function(options, callback) {
11121113
return WebApiRequest.builder(this.getAccessToken())
11131114
.withPath('/v1/me/player/pause')
1115+
/*jshint camelcase: false */
1116+
.withQueryParameters(options && options.device_id ? {device_id: options.device_id} : null)
11141117
.withHeaders({ 'Content-Type' : 'application/json' })
11151118
.build()
11161119
.execute(HttpManager.put, callback);

test/spotify-web-api.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,31 @@ describe('Spotify Web API', function() {
14121412

14131413
});
14141414

1415+
it('should pause the user\'s playback with options', function(done) {
1416+
1417+
sinon.stub(HttpManager, '_makeRequest', function(method, options, uri, callback) {
1418+
method.should.equal(superagent.put);
1419+
uri.should.equal('https://api.spotify.com/v1/me/player/pause');
1420+
options.query.should.eql({device_id: 'my_device_id'});
1421+
callback();
1422+
});
1423+
1424+
var accessToken = 'myAccessToken';
1425+
1426+
var api = new SpotifyWebApi({
1427+
accessToken : accessToken
1428+
});
1429+
1430+
api.pause({device_id: 'my_device_id'})
1431+
.then(function(data) {
1432+
done();
1433+
}, function(err) {
1434+
console.log(err);
1435+
done(err);
1436+
});
1437+
1438+
});
1439+
14151440
it('should skip the user\'s playback to next track', function(done) {
14161441

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

0 commit comments

Comments
 (0)