Skip to content

Commit dba91a8

Browse files
authored
Sept 11 API updates (#243)
* Sept 11 API updates
1 parent 2fcd60c commit dba91a8

File tree

4 files changed

+59
-144
lines changed

4 files changed

+59
-144
lines changed

README.md

+18-16
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ This is a universal wrapper/client for the [Spotify Web API](https://developer.s
99
Project owners are [thelinmichael](https://github.com/thelinmichael) and [JMPerez](https://github.com/JMPerez), with help from [a lot of awesome contributors](https://github.com/thelinmichael/spotify-web-api-node/network/members).
1010

1111
## Table of contents
12-
- [Features](#features)
13-
- [Installation](#installation)
14-
- [Usage](#usage)
15-
- [Development](#development)
12+
13+
* [Features](#features)
14+
* [Installation](#installation)
15+
* [Usage](#usage)
16+
* [Development](#development)
1617

1718
## Features
19+
1820
The library includes helper functions to do the following:
1921

2022
#### Music metadata
@@ -383,7 +385,7 @@ spotifyApi.getMe()
383385
*/
384386

385387
// Get a playlist
386-
spotifyApi.getPlaylist('thelinmichael', '5ieJqeLJjjI8iJWaxeBLuK')
388+
spotifyApi.getPlaylist('5ieJqeLJjjI8iJWaxeBLuK')
387389
.then(function(data) {
388390
console.log('Some information about this playlist', data.body);
389391
}, function(err) {
@@ -399,23 +401,23 @@ spotifyApi.getUserPlaylists('thelinmichael')
399401
});
400402

401403
// Create a private playlist
402-
spotifyApi.createPlaylist('thelinmichael', 'My Cool Playlist', { 'public' : false })
404+
spotifyApi.createPlaylist('My Cool Playlist', { 'public' : false })
403405
.then(function(data) {
404406
console.log('Created playlist!');
405407
}, function(err) {
406408
console.log('Something went wrong!', err);
407409
});
408410

409411
// Add tracks to a playlist
410-
spotifyApi.addTracksToPlaylist('thelinmichael', '5ieJqeLJjjI8iJWaxeBLuK', ["spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "spotify:track:1301WleyT98MSxVHPZCA6M"])
412+
spotifyApi.addTracksToPlaylist('5ieJqeLJjjI8iJWaxeBLuK', ["spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "spotify:track:1301WleyT98MSxVHPZCA6M"])
411413
.then(function(data) {
412414
console.log('Added tracks to playlist!');
413415
}, function(err) {
414416
console.log('Something went wrong!', err);
415417
});
416418

417419
// Add tracks to a specific position in a playlist
418-
spotifyApi.addTracksToPlaylist('thelinmichael', '5ieJqeLJjjI8iJWaxeBLuK', ["spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "spotify:track:1301WleyT98MSxVHPZCA6M"],
420+
spotifyApi.addTracksToPlaylist('5ieJqeLJjjI8iJWaxeBLuK', ["spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "spotify:track:1301WleyT98MSxVHPZCA6M"],
419421
{
420422
position : 5
421423
})
@@ -426,7 +428,7 @@ spotifyApi.addTracksToPlaylist('thelinmichael', '5ieJqeLJjjI8iJWaxeBLuK', ["spot
426428
});
427429

428430
// Remove tracks from a playlist at a specific position
429-
spotifyApi.removeTracksFromPlaylistByPosition('thelinmichael', '5ieJqeLJjjI8iJWaxeBLuK', [0, 2, 130], "0wD+DKCUxiSR/WY8lF3fiCTb7Z8X4ifTUtqn8rO82O4Mvi5wsX8BsLj7IbIpLVM9")
431+
spotifyApi.removeTracksFromPlaylistByPosition('5ieJqeLJjjI8iJWaxeBLuK', [0, 2, 130], "0wD+DKCUxiSR/WY8lF3fiCTb7Z8X4ifTUtqn8rO82O4Mvi5wsX8BsLj7IbIpLVM9")
430432
.then(function(data) {
431433
console.log('Tracks removed from playlist!');
432434
}, function(err) {
@@ -436,7 +438,7 @@ spotifyApi.removeTracksFromPlaylistByPosition('thelinmichael', '5ieJqeLJjjI8iJWa
436438
// Remove all occurrence of a track
437439
var tracks = [{ uri : "spotify:track:4iV5W9uYEdYUVa79Axb7Rh" }];
438440
var options = { snapshot_id : "0wD+DKCUxiSR/WY8lF3fiCTb7Z8X4ifTUtqn8rO82O4Mvi5wsX8BsLj7IbIpLVM9" };
439-
spotifyApi.removeTracksFromPlaylist('thelinmichael', '5ieJqeLJjjI8iJWaxeBLuK', tracks, options)
441+
spotifyApi.removeTracksFromPlaylist('5ieJqeLJjjI8iJWaxeBLuK', tracks, options)
440442
.then(function(data) {
441443
console.log('Tracks removed from playlist!');
442444
}, function(err) {
@@ -445,15 +447,15 @@ spotifyApi.removeTracksFromPlaylist('thelinmichael', '5ieJqeLJjjI8iJWaxeBLuK', t
445447

446448
// Reorder the first two tracks in a playlist to the place before the track at the 10th position
447449
var options = { "range_length" : 2 };
448-
spotifyApi.reorderTracksInPlaylist('thelinmichael', '5ieJqeLJjjI8iJWaxeBLuK', 0, 10, options)
450+
spotifyApi.reorderTracksInPlaylist('5ieJqeLJjjI8iJWaxeBLuK', 0, 10, options)
449451
.then(function(data) {
450452
console.log('Tracks reordered in playlist!');
451453
}, function(err) {
452454
console.log('Something went wrong!', err);
453455
});
454456

455457
// Change playlist details
456-
spotifyApi.changePlaylistDetails('thelinmichael', '5ieJqeLJjjI8iJWaxeBLuK',
458+
spotifyApi.changePlaylistDetails('5ieJqeLJjjI8iJWaxeBLuK',
457459
{
458460
name: 'This is a new name for my Cool Playlist, and will become private',
459461
'public' : false
@@ -464,15 +466,15 @@ spotifyApi.changePlaylistDetails('thelinmichael', '5ieJqeLJjjI8iJWaxeBLuK',
464466
});
465467

466468
// Upload a custom playlist cover image
467-
spotifyApi.uploadCustomPlaylistCoverImage('thelinmichael', '5ieJqeLJjjI8iJWaxeBLuK','longbase64uri')
469+
spotifyApi.uploadCustomPlaylistCoverImage('5ieJqeLJjjI8iJWaxeBLuK','longbase64uri')
468470
.then(function(data) {
469471
console.log('Playlsit cover image uploaded!');
470472
}, function(err) {
471473
console.log('Something went wrong!', err);
472474
});
473475

474476
// Follow a playlist (privately)
475-
spotifyApi.followPlaylist('thelinmichael', '5ieJqeLJjjI8iJWaxeBLuK',
477+
spotifyApi.followPlaylist('5ieJqeLJjjI8iJWaxeBLuK',
476478
{
477479
'public' : false
478480
}).then(function(data) {
@@ -482,15 +484,15 @@ spotifyApi.followPlaylist('thelinmichael', '5ieJqeLJjjI8iJWaxeBLuK',
482484
});
483485

484486
// Unfollow a playlist
485-
spotifyApi.unfollowPlaylist('thelinmichael', '5ieJqeLJjjI8iJWaxeBLuK')
487+
spotifyApi.unfollowPlaylist('5ieJqeLJjjI8iJWaxeBLuK')
486488
.then(function(data) {
487489
console.log('Playlist successfully unfollowed!');
488490
}, function(err) {
489491
console.log('Something went wrong!', err);
490492
});
491493

492494
// Check if Users are following a Playlist
493-
spotifyApi.areFollowingPlaylist('thelinmichael', '5ieJqeLJjjI8iJWaxeBLuK', ['thelinmichael', 'ella'])
495+
spotifyApi.areFollowingPlaylist('5ieJqeLJjjI8iJWaxeBLuK', ['thelinmichael', 'ella'])
494496
.then(function(data) {
495497
data.body.forEach(function(isFollowing) {
496498
console.log("User is following: " + isFollowing);

__tests__/spotify-web-api.js

+17-26
Original file line numberDiff line numberDiff line change
@@ -1456,12 +1456,12 @@ describe('Spotify Web API', () => {
14561456
) {
14571457
expect(method).toBe(superagent.get);
14581458
expect(uri).toBe(
1459-
'https://api.spotify.com/v1/users/thelinmichael/playlists/5ieJqeLJjjI8iJWaxeBLuK'
1459+
'https://api.spotify.com/v1/playlists/5ieJqeLJjjI8iJWaxeBLuK'
14601460
);
14611461
expect(options.query).toBeFalsy();
14621462
callback(null, {
14631463
body: {
1464-
uri: 'spotify:user:thelinmichael:playlist:5ieJqeLJjjI8iJWaxeBLuK'
1464+
uri: 'spotify:playlist:5ieJqeLJjjI8iJWaxeBLuK'
14651465
},
14661466
statusCode: 200
14671467
});
@@ -1470,13 +1470,8 @@ describe('Spotify Web API', () => {
14701470
var api = new SpotifyWebApi();
14711471
api.setAccessToken('myVeryVeryLongAccessToken');
14721472

1473-
api.getPlaylist('thelinmichael', '5ieJqeLJjjI8iJWaxeBLuK', {}, function(
1474-
err,
1475-
data
1476-
) {
1477-
expect(data.body.uri).toBe(
1478-
'spotify:user:thelinmichael:playlist:5ieJqeLJjjI8iJWaxeBLuK'
1479-
);
1473+
api.getPlaylist('5ieJqeLJjjI8iJWaxeBLuK', {}, function(err, data) {
1474+
expect(data.body.uri).toBe('spotify:playlist:5ieJqeLJjjI8iJWaxeBLuK');
14801475
expect(data.statusCode).toBe(200);
14811476
done();
14821477
});
@@ -1570,7 +1565,7 @@ describe('Spotify Web API', () => {
15701565
) {
15711566
expect(method).toBe(superagent.put);
15721567
expect(uri).toBe(
1573-
'https://api.spotify.com/v1/users/thelinmichael/playlists/5ieJqeLJjjI8iJWaxeBLuK'
1568+
'https://api.spotify.com/v1/playlists/5ieJqeLJjjI8iJWaxeBLuK'
15741569
);
15751570
expect(JSON.parse(options.data)).toEqual({
15761571
name:
@@ -1585,7 +1580,7 @@ describe('Spotify Web API', () => {
15851580
api.setAccessToken('long-access-token');
15861581

15871582
api
1588-
.changePlaylistDetails('thelinmichael', '5ieJqeLJjjI8iJWaxeBLuK', {
1583+
.changePlaylistDetails('5ieJqeLJjjI8iJWaxeBLuK', {
15891584
name:
15901585
'This is a new name for my Cool Playlist, and will become private',
15911586
public: false
@@ -1605,7 +1600,7 @@ describe('Spotify Web API', () => {
16051600
) {
16061601
expect(method).toBe(superagent.post);
16071602
expect(uri).toBe(
1608-
'https://api.spotify.com/v1/users/thelinmichael/playlists/5ieJqeLJjjI8iJWaxeBLuK/tracks'
1603+
'https://api.spotify.com/v1/playlists/5ieJqeLJjjI8iJWaxeBLuK/tracks'
16091604
);
16101605
expect(options.query).toBeFalsy();
16111606
expect(JSON.parse(options.data)['uris']).toBeInstanceOf(Array);
@@ -1617,7 +1612,7 @@ describe('Spotify Web API', () => {
16171612
api.setAccessToken('long-access-token');
16181613

16191614
api
1620-
.addTracksToPlaylist('thelinmichael', '5ieJqeLJjjI8iJWaxeBLuK', [
1615+
.addTracksToPlaylist('5ieJqeLJjjI8iJWaxeBLuK', [
16211616
'spotify:track:4iV5W9uYEdYUVa79Axb7Rh',
16221617
'spotify:track:1301WleyT98MSxVHPZCA6M'
16231618
])
@@ -1648,7 +1643,6 @@ describe('Spotify Web API', () => {
16481643

16491644
api
16501645
.addTracksToPlaylist(
1651-
'thelinmichael',
16521646
'5ieJqeLJjjI8iJWaxeBLuK',
16531647
[
16541648
'spotify:track:4iV5W9uYEdYUVa79Axb7Rh',
@@ -2666,7 +2660,7 @@ describe('Spotify Web API', () => {
26662660
expect(JSON.parse(options.data)).toEqual({ public: false });
26672661
expect(options.query).toBeFalsy();
26682662
expect(uri).toBe(
2669-
'https://api.spotify.com/v1/users/jmperezperez/playlists/7p9EIC2KW0NNkTEOnTUZJl/followers'
2663+
'https://api.spotify.com/v1/playlists/7p9EIC2KW0NNkTEOnTUZJl/followers'
26702664
);
26712665
callback();
26722666
});
@@ -2678,7 +2672,7 @@ describe('Spotify Web API', () => {
26782672
});
26792673

26802674
api
2681-
.followPlaylist('jmperezperez', '7p9EIC2KW0NNkTEOnTUZJl', {
2675+
.followPlaylist('7p9EIC2KW0NNkTEOnTUZJl', {
26822676
public: false
26832677
})
26842678
.then(
@@ -2703,7 +2697,7 @@ describe('Spotify Web API', () => {
27032697
expect(options.data).toBeFalsy();
27042698
expect(options.query).toBeFalsy();
27052699
expect(uri).toBe(
2706-
'https://api.spotify.com/v1/users/jmperezperez/playlists/7p9EIC2KW0NNkTEOnTUZJl/followers'
2700+
'https://api.spotify.com/v1/playlists/7p9EIC2KW0NNkTEOnTUZJl/followers'
27072701
);
27082702
callback();
27092703
});
@@ -2714,7 +2708,7 @@ describe('Spotify Web API', () => {
27142708
accessToken: accessToken
27152709
});
27162710

2717-
api.unfollowPlaylist('jmperezperez', '7p9EIC2KW0NNkTEOnTUZJl').then(
2711+
api.unfollowPlaylist('7p9EIC2KW0NNkTEOnTUZJl').then(
27182712
function(data) {
27192713
done();
27202714
},
@@ -3224,7 +3218,7 @@ describe('Spotify Web API', () => {
32243218
) {
32253219
expect(method).toBe(superagent.post);
32263220
expect(uri).toBe(
3227-
'https://api.spotify.com/v1/users/thelinmichael/playlists/5ieJqeLJjjI8iJWaxeBLuK/tracks'
3221+
'https://api.spotify.com/v1/playlists/5ieJqeLJjjI8iJWaxeBLuK/tracks'
32283222
);
32293223
expect(options.query).toBeFalsy();
32303224
expect(JSON.parse(options.data)['uris']).toBeInstanceOf(Array);
@@ -3237,7 +3231,7 @@ describe('Spotify Web API', () => {
32373231
api.setAccessToken('long-access-token');
32383232

32393233
api
3240-
.addTracksToPlaylist('thelinmichael', '5ieJqeLJjjI8iJWaxeBLuK', [
3234+
.addTracksToPlaylist('5ieJqeLJjjI8iJWaxeBLuK', [
32413235
'spotify:track:4iV5W9uYEdYUVa79Axb7Rh',
32423236
'spotify:track:1301WleyT98MSxVHPZCA6M'
32433237
])
@@ -3261,7 +3255,7 @@ describe('Spotify Web API', () => {
32613255
) {
32623256
expect(method).toBe(superagent.post);
32633257
expect(uri).toBe(
3264-
'https://api.spotify.com/v1/users/thelinmichael/playlists/5ieJqeLJjjI8iJWaxeBLuK/tracks'
3258+
'https://api.spotify.com/v1/playlists/5ieJqeLJjjI8iJWaxeBLuK/tracks'
32653259
);
32663260
expect(options.query).toBeFalsy();
32673261
expect(JSON.parse(options.data)['uris']).toBeInstanceOf(Array);
@@ -3274,7 +3268,6 @@ describe('Spotify Web API', () => {
32743268
api.setAccessToken('long-access-token');
32753269

32763270
api.addTracksToPlaylist(
3277-
'thelinmichael',
32783271
'5ieJqeLJjjI8iJWaxeBLuK',
32793272
[
32803273
'spotify:track:4iV5W9uYEdYUVa79Axb7Rh',
@@ -3290,7 +3283,7 @@ describe('Spotify Web API', () => {
32903283
test('should remove tracks from a playlist by position', done => {
32913284
sinon.stub(HttpManager, 'del', function(request, callback) {
32923285
expect(request.getURI()).toBe(
3293-
'https://api.spotify.com/v1/users/thelinmichael/playlists/5ieJqeLJjjI8iJWaxeBLuK/tracks'
3286+
'https://api.spotify.com/v1/playlists/5ieJqeLJjjI8iJWaxeBLuK/tracks'
32943287
);
32953288
expect(request.getQueryParameters()).toBeFalsy();
32963289
var data = request.getBodyParameters();
@@ -3309,7 +3302,6 @@ describe('Spotify Web API', () => {
33093302
api.setAccessToken('long-access-token');
33103303

33113304
api.removeTracksFromPlaylistByPosition(
3312-
'thelinmichael',
33133305
'5ieJqeLJjjI8iJWaxeBLuK',
33143306
[0, 2],
33153307
'0wD+DKCUxiSR/WY8lF3fiCTb7Z8X4ifTUtqn8rO82O4Mvi5wsX8BsLj7IbIpLVM9',
@@ -3332,7 +3324,7 @@ describe('Spotify Web API', () => {
33323324
) {
33333325
expect(method).toBe(superagent.put);
33343326
expect(uri).toBe(
3335-
'https://api.spotify.com/v1/users/thelinmichael/playlists/5ieJqeLJjjI8iJWaxeBLuK/tracks'
3327+
'https://api.spotify.com/v1/playlists/5ieJqeLJjjI8iJWaxeBLuK/tracks'
33363328
);
33373329
expect(options.query).toBeFalsy();
33383330
expect(JSON.parse(options.data)['range_start']).toBe(5);
@@ -3356,7 +3348,6 @@ describe('Spotify Web API', () => {
33563348
};
33573349

33583350
api.reorderTracksInPlaylist(
3359-
'thelinmichael',
33603351
'5ieJqeLJjjI8iJWaxeBLuK',
33613352
5,
33623353
1512,

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
"npm test -- --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
2020
"precommit": "lint-staged"
2121
},
22+
"jest": {
23+
"verbose": true,
24+
"testURL": "http://localhost/"
25+
},
2226
"lint-staged": {
2327
"*.{js,json,css,md}": ["prettier --single-quote --write", "git add"]
2428
},

0 commit comments

Comments
 (0)