Skip to content

Commit

Permalink
change addTracksToPlaylist to request body (#117)
Browse files Browse the repository at this point in the history
* change uris to body in addTracksToPlaylist
  • Loading branch information
dolcalmi authored and JMPerez committed Apr 24, 2017
1 parent 4d87722 commit 49fc626
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
10 changes: 2 additions & 8 deletions src/spotify-web-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -921,17 +921,11 @@ SpotifyWebApi.prototype = {
* it contains an error object. Not returned if a callback is given.
*/
addTracksToPlaylist: function(userId, playlistId, tracks, options, callback) {
var tracksString;
if (typeof tracks === 'object') {
tracksString = tracks.join();
} else {
tracksString = tracks;
}
var request = WebApiRequest.builder()
.withPath('/v1/users/' + encodeURIComponent(userId) + '/playlists/' + playlistId + '/tracks')
.withHeaders({ 'Content-Type' : 'application/json' })
.withQueryParameters({
uris: tracksString
.withBodyParameters({
uris: tracks
})
.build();

Expand Down
15 changes: 7 additions & 8 deletions test/spotify-web-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,8 @@ describe('Spotify Web API', function() {
sinon.stub(HttpManager, '_makeRequest', function(method, options, uri, callback) {
method.should.equal(superagent.post);
uri.should.equal('https://api.spotify.com/v1/users/thelinmichael/playlists/5ieJqeLJjjI8iJWaxeBLuK/tracks');
options.query.should.eql({uris: 'spotify:track:4iV5W9uYEdYUVa79Axb7Rh,spotify:track:1301WleyT98MSxVHPZCA6M'});
should.not.exist(options.query);
JSON.parse(options.data)["uris"].should.be.an.instanceOf(Array).and.have.lengthOf(2);
callback(null, { body: { snapshot_id: 'aSnapshotId'}, statusCode : 201 });
});

Expand All @@ -1151,8 +1152,8 @@ describe('Spotify Web API', function() {
it('should add tracks to playlist with specified index', function(done) {
sinon.stub(HttpManager, '_makeRequest', function(method, options, uri, callback) {
method.should.equal(superagent.post);
JSON.parse(options.data)["uris"].should.be.an.instanceOf(Array).and.have.lengthOf(2);
options.query.should.eql({
uris: 'spotify:track:4iV5W9uYEdYUVa79Axb7Rh,spotify:track:1301WleyT98MSxVHPZCA6M',
position: 10
});
callback(null, { body: { snapshot_id: 'aSnapshotId'}, statusCode : 201 });
Expand Down Expand Up @@ -2068,9 +2069,8 @@ describe('Spotify Web API', function() {
sinon.stub(HttpManager, '_makeRequest', function(method, options, uri, callback) {
method.should.equal(superagent.post);
uri.should.equal('https://api.spotify.com/v1/users/thelinmichael/playlists/5ieJqeLJjjI8iJWaxeBLuK/tracks');
var trackUris = options.query.uris.split(",");
trackUris.should.be.an.instanceOf(Array).and.have.lengthOf(2);
should.not.exist(options.data);
should.not.exist(options.query);
JSON.parse(options.data)["uris"].should.be.an.instanceOf(Array).and.have.lengthOf(2);
options.headers.Authorization.should.equal('Bearer long-access-token');
callback();
});
Expand All @@ -2092,9 +2092,8 @@ describe('Spotify Web API', function() {
sinon.stub(HttpManager, '_makeRequest', function(method, options, uri, callback) {
method.should.equal(superagent.post);
uri.should.equal('https://api.spotify.com/v1/users/thelinmichael/playlists/5ieJqeLJjjI8iJWaxeBLuK/tracks');
var trackUris = options.query.uris.split(",");
trackUris.should.be.an.instanceOf(Array).and.have.lengthOf(2);
should.not.exist(options.data);
should.not.exist(options.query);
JSON.parse(options.data)["uris"].should.be.an.instanceOf(Array).and.have.lengthOf(2);
options.headers.Authorization.should.equal('Bearer long-access-token');
callback();
});
Expand Down

0 comments on commit 49fc626

Please sign in to comment.