Skip to content

Commit

Permalink
Send track URIs in body of request for addTracksToPlaylist (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
davejm authored and JMPerez committed Jan 4, 2017
1 parent 615905d commit f51a8e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 8 additions & 2 deletions __test__/spotify-web-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,10 @@ var Q = require('q');
);
expect(callback.calledWith(null, '')).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe('https://api.spotify.com/v1/users/jmperezperez/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks?uris=spotify%3Atrack%3A2Oehrcv4Kov0SuIgWyQY9e');
expect(that.requests[0].url).toBe('https://api.spotify.com/v1/users/jmperezperez/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks');
expect(that.requests[0].requestBody).toBe(JSON.stringify({
uris: ['spotify:track:2Oehrcv4Kov0SuIgWyQY9e']
}));
});

it('should add tracks to a playlist, specifying position', function() {
Expand All @@ -589,7 +592,10 @@ var Q = require('q');
);
expect(callback.calledWith(null, '')).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe('https://api.spotify.com/v1/users/jmperezperez/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks?uris=spotify%3Atrack%3A2Oehrcv4Kov0SuIgWyQY9e&position=0');
expect(that.requests[0].url).toBe('https://api.spotify.com/v1/users/jmperezperez/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks?position=0');
expect(that.requests[0].requestBody).toBe(JSON.stringify({
uris: ['spotify:track:2Oehrcv4Kov0SuIgWyQY9e']
}));
});

it('should remove tracks from a playlist', function() {
Expand Down
8 changes: 4 additions & 4 deletions src/spotify-web-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ var SpotifyWebApi = (function() {
}
};

var _checkParamsAndPerformRequest = function(requestData, options, callback) {
var _checkParamsAndPerformRequest = function(requestData, options, callback, optionsAlwaysExtendParams) {
var opt = {};
var cb = null;

Expand All @@ -142,7 +142,7 @@ var SpotifyWebApi = (function() {

// options extend postData, if any. Otherwise they extend parameters sent in the url
var type = requestData.type || 'GET';
if (type !== 'GET' && requestData.postData) {
if (type !== 'GET' && requestData.postData && !optionsAlwaysExtendParams) {
requestData.postData = _extend(requestData.postData, opt);
} else {
requestData.params = _extend(requestData.params, opt);
Expand Down Expand Up @@ -771,11 +771,11 @@ var SpotifyWebApi = (function() {
var requestData = {
url: _baseUri + '/users/' + encodeURIComponent(userId) + '/playlists/' + playlistId + '/tracks',
type: 'POST',
params: {
postData: {
uris: uris
}
};
return _checkParamsAndPerformRequest(requestData, options, callback);
return _checkParamsAndPerformRequest(requestData, options, callback, true);
};

/**
Expand Down

0 comments on commit f51a8e9

Please sign in to comment.