Skip to content

Commit 49fc626

Browse files
dolcalmiJMPerez
authored andcommitted
change addTracksToPlaylist to request body (#117)
* change uris to body in addTracksToPlaylist
1 parent 4d87722 commit 49fc626

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

src/spotify-web-api.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -921,17 +921,11 @@ SpotifyWebApi.prototype = {
921921
* it contains an error object. Not returned if a callback is given.
922922
*/
923923
addTracksToPlaylist: function(userId, playlistId, tracks, options, callback) {
924-
var tracksString;
925-
if (typeof tracks === 'object') {
926-
tracksString = tracks.join();
927-
} else {
928-
tracksString = tracks;
929-
}
930924
var request = WebApiRequest.builder()
931925
.withPath('/v1/users/' + encodeURIComponent(userId) + '/playlists/' + playlistId + '/tracks')
932926
.withHeaders({ 'Content-Type' : 'application/json' })
933-
.withQueryParameters({
934-
uris: tracksString
927+
.withBodyParameters({
928+
uris: tracks
935929
})
936930
.build();
937931

test/spotify-web-api.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,8 @@ describe('Spotify Web API', function() {
11341134
sinon.stub(HttpManager, '_makeRequest', function(method, options, uri, callback) {
11351135
method.should.equal(superagent.post);
11361136
uri.should.equal('https://api.spotify.com/v1/users/thelinmichael/playlists/5ieJqeLJjjI8iJWaxeBLuK/tracks');
1137-
options.query.should.eql({uris: 'spotify:track:4iV5W9uYEdYUVa79Axb7Rh,spotify:track:1301WleyT98MSxVHPZCA6M'});
1137+
should.not.exist(options.query);
1138+
JSON.parse(options.data)["uris"].should.be.an.instanceOf(Array).and.have.lengthOf(2);
11381139
callback(null, { body: { snapshot_id: 'aSnapshotId'}, statusCode : 201 });
11391140
});
11401141

@@ -1151,8 +1152,8 @@ describe('Spotify Web API', function() {
11511152
it('should add tracks to playlist with specified index', function(done) {
11521153
sinon.stub(HttpManager, '_makeRequest', function(method, options, uri, callback) {
11531154
method.should.equal(superagent.post);
1155+
JSON.parse(options.data)["uris"].should.be.an.instanceOf(Array).and.have.lengthOf(2);
11541156
options.query.should.eql({
1155-
uris: 'spotify:track:4iV5W9uYEdYUVa79Axb7Rh,spotify:track:1301WleyT98MSxVHPZCA6M',
11561157
position: 10
11571158
});
11581159
callback(null, { body: { snapshot_id: 'aSnapshotId'}, statusCode : 201 });
@@ -2068,9 +2069,8 @@ describe('Spotify Web API', function() {
20682069
sinon.stub(HttpManager, '_makeRequest', function(method, options, uri, callback) {
20692070
method.should.equal(superagent.post);
20702071
uri.should.equal('https://api.spotify.com/v1/users/thelinmichael/playlists/5ieJqeLJjjI8iJWaxeBLuK/tracks');
2071-
var trackUris = options.query.uris.split(",");
2072-
trackUris.should.be.an.instanceOf(Array).and.have.lengthOf(2);
2073-
should.not.exist(options.data);
2072+
should.not.exist(options.query);
2073+
JSON.parse(options.data)["uris"].should.be.an.instanceOf(Array).and.have.lengthOf(2);
20742074
options.headers.Authorization.should.equal('Bearer long-access-token');
20752075
callback();
20762076
});
@@ -2092,9 +2092,8 @@ describe('Spotify Web API', function() {
20922092
sinon.stub(HttpManager, '_makeRequest', function(method, options, uri, callback) {
20932093
method.should.equal(superagent.post);
20942094
uri.should.equal('https://api.spotify.com/v1/users/thelinmichael/playlists/5ieJqeLJjjI8iJWaxeBLuK/tracks');
2095-
var trackUris = options.query.uris.split(",");
2096-
trackUris.should.be.an.instanceOf(Array).and.have.lengthOf(2);
2097-
should.not.exist(options.data);
2095+
should.not.exist(options.query);
2096+
JSON.parse(options.data)["uris"].should.be.an.instanceOf(Array).and.have.lengthOf(2);
20982097
options.headers.Authorization.should.equal('Bearer long-access-token');
20992098
callback();
21002099
});

0 commit comments

Comments
 (0)