Skip to content

Commit ff89d46

Browse files
committed
Merge pull request #23 from danmactough/add-user-albums-endpoints
Add methods to manage user's saved albums
2 parents 6ac9936 + bd2749b commit ff89d46

File tree

3 files changed

+13199
-0
lines changed

3 files changed

+13199
-0
lines changed

src/spotify-web-api.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,81 @@ var SpotifyWebApi = (function() {
259259
return _checkParamsAndPerformRequest(requestData, options, callback);
260260
};
261261

262+
/**
263+
* Get a list of the albums saved in the current Spotify user's "Your Music" library.
264+
* See [Get Current User's Saved Albums](https://developer.spotify.com/web-api/get-users-saved-albums/) on
265+
* the Spotify Developer site for more information about the endpoint.
266+
* @param {Object} options A JSON object with options that can be passed
267+
* @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first
268+
* one is the error object (null if no error), and the second is the value if the request succeeded.
269+
* @return {Object} Null if a callback is provided, a `Promise` object otherwise
270+
*/
271+
Constr.prototype.getMySavedAlbums = function(options, callback) {
272+
var requestData = {
273+
url: _baseUri + '/me/albums'
274+
};
275+
return _checkParamsAndPerformRequest(requestData, options, callback);
276+
};
277+
278+
/**
279+
* Save one or more albums to the current user's "Your Music" library.
280+
* See [Save Albums for Current User](https://developer.spotify.com/web-api/save-albums-user/) on
281+
* the Spotify Developer site for more information about the endpoint.
282+
* @param {Array<string>} albumIds The ids of the albums. If you know their Spotify URI, it is easy
283+
* to find their album id (e.g. spotify:album:<here_is_the_album_id>)
284+
* @param {Object} options A JSON object with options that can be passed
285+
* @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first
286+
* one is the error object (null if no error), and the second is the value if the request succeeded.
287+
* @return {Object} Null if a callback is provided, a `Promise` object otherwise
288+
*/
289+
Constr.prototype.addToMySavedAlbums = function(albumIds, options, callback) {
290+
var requestData = {
291+
url: _baseUri + '/me/albums',
292+
type: 'PUT',
293+
postData: albumIds
294+
};
295+
return _checkParamsAndPerformRequest(requestData, options, callback);
296+
};
297+
298+
/**
299+
* Remove one or more albums from the current user's "Your Music" library.
300+
* See [Remove Albums for Current User](https://developer.spotify.com/web-api/remove-albums-user/) on
301+
* the Spotify Developer site for more information about the endpoint.
302+
* @param {Array<string>} albumIds The ids of the albums. If you know their Spotify URI, it is easy
303+
* to find their album id (e.g. spotify:album:<here_is_the_album_id>)
304+
* @param {Object} options A JSON object with options that can be passed
305+
* @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first
306+
* one is the error object (null if no error), and the second is the value if the request succeeded.
307+
* @return {Object} Null if a callback is provided, a `Promise` object otherwise
308+
*/
309+
Constr.prototype.removeFromMySavedAlbums = function(albumIds, options, callback) {
310+
var requestData = {
311+
url: _baseUri + '/me/albums',
312+
type: 'DELETE',
313+
postData: albumIds
314+
};
315+
return _checkParamsAndPerformRequest(requestData, options, callback);
316+
};
317+
318+
/**
319+
* Check if one or more albums is already saved in the current Spotify user's "Your Music" library.
320+
* See [Check User's Saved Albums](https://developer.spotify.com/web-api/check-users-saved-albums/) on
321+
* the Spotify Developer site for more information about the endpoint.
322+
* @param {Array<string>} albumIds The ids of the albums. If you know their Spotify URI, it is easy
323+
* to find their album id (e.g. spotify:album:<here_is_the_album_id>)
324+
* @param {Object} options A JSON object with options that can be passed
325+
* @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first
326+
* one is the error object (null if no error), and the second is the value if the request succeeded.
327+
* @return {Object} Null if a callback is provided, a `Promise` object otherwise
328+
*/
329+
Constr.prototype.containsMySavedAlbums = function(albumIds, options, callback) {
330+
var requestData = {
331+
url: _baseUri + '/me/albums/contains',
332+
params: { ids: albumIds.join(',') }
333+
};
334+
return _checkParamsAndPerformRequest(requestData, options, callback);
335+
};
336+
262337
/**
263338
* Adds the current user as a follower of one or more other Spotify users.
264339
* See [Follow Artists or Users](https://developer.spotify.com/web-api/follow-artists-users/) on

0 commit comments

Comments
 (0)