Skip to content

Commit

Permalink
Update createPlaylist to use the new endpoint route. Fixes JMPerez#124.…
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgrieger authored and JMPerez committed Feb 2, 2019
1 parent 120e85a commit 1f6fa39
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions __test__/spotify-web-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,11 @@ describe('Basic tests', function() {
var callback = sinon.spy();
var api = new SpotifyWebApi();
api.setAccessToken('<example_access_token>');
api.createPlaylist({ name: 'A name for the playlist' }, callback);
api.createPlaylist('a_user', { name: 'A name for the playlist' }, callback);
that.requests[0].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify(fixtures.user_new_playlist));
expect(callback.calledWith(null, fixtures.user_new_playlist)).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe('https://api.spotify.com/v1/me/playlists');
expect(that.requests[0].url).toBe('https://api.spotify.com/v1/users/a_user/playlists');
});

it("should update a playlist's details", function() {
Expand Down
6 changes: 4 additions & 2 deletions src/spotify-web-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,14 +732,16 @@ var SpotifyWebApi = (function() {
* See [Create a Playlist](https://developer.spotify.com/web-api/create-playlist/) on
* the Spotify Developer site for more information about the endpoint.
*
* @param {string} userId The id of the user. If you know the Spotify URI it is easy
* to find the id (e.g. spotify:user:<here_is_the_id>)
* @param {Object} options A JSON object with options that can be passed
* @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first
* one is the error object (null if no error), and the second is the value if the request succeeded.
* @return {Object} Null if a callback is provided, a `Promise` object otherwise
*/
Constr.prototype.createPlaylist = function(options, callback) {
Constr.prototype.createPlaylist = function(userId, options, callback) {
var requestData = {
url: _baseUri + '/me/playlists',
url: _baseUri + '/users/' + encodeURIComponent(userId) + '/playlists',
type: 'POST',
postData: options
};
Expand Down
4 changes: 3 additions & 1 deletion src/typings/spotify-web-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,14 @@ declare namespace SpotifyWebApi {
* See [Create a Playlist](https://developer.spotify.com/web-api/create-playlist/) on
* the Spotify Developer site for more information about the endpoint.
*
* @param {string} userId The id of the user. If you know the Spotify URI it is easy
* to find the id (e.g. spotify:user:<here_is_the_id>)
* @param {Object} options A JSON object with options that can be passed
* @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first
* one is the error object (null if no error), and the second is the value if the request succeeded.
* @return {Object} Null if a callback is provided, a `Promise` object otherwise
*/
createPlaylist(options?: Object, callback?: ResultsCallback<SpotifyApi.CreatePlaylistResponse>) : Promise<SpotifyApi.CreatePlaylistResponse>;
createPlaylist(userId: string, options?: Object, callback?: ResultsCallback<SpotifyApi.CreatePlaylistResponse>) : Promise<SpotifyApi.CreatePlaylistResponse>;

/**
* Change a playlist's name and public/private state
Expand Down

0 comments on commit 1f6fa39

Please sign in to comment.