diff --git a/src/spotify-web-api.js b/src/spotify-web-api.js index 2a756da8..fc4c84c0 100644 --- a/src/spotify-web-api.js +++ b/src/spotify-web-api.js @@ -9,7 +9,7 @@ function SpotifyWebApi(credentials) { } SpotifyWebApi.prototype = { - setCredentials: function(credentials) { + setCredentials: function (credentials) { for (var key in credentials) { if (credentials.hasOwnProperty(key)) { this._credentials[key] = credentials[key]; @@ -17,80 +17,80 @@ SpotifyWebApi.prototype = { } }, - getCredentials: function() { + getCredentials: function () { return this._credentials; }, - resetCredentials: function() { + resetCredentials: function () { this._credentials = null; }, - setClientId: function(clientId) { + setClientId: function (clientId) { this._setCredential('clientId', clientId); }, - setClientSecret: function(clientSecret) { + setClientSecret: function (clientSecret) { this._setCredential('clientSecret', clientSecret); }, - setAccessToken: function(accessToken) { + setAccessToken: function (accessToken) { this._setCredential('accessToken', accessToken); }, - setRefreshToken: function(refreshToken) { + setRefreshToken: function (refreshToken) { this._setCredential('refreshToken', refreshToken); }, - setRedirectURI: function(redirectUri) { + setRedirectURI: function (redirectUri) { this._setCredential('redirectUri', redirectUri); }, - getRedirectURI: function() { + getRedirectURI: function () { return this._getCredential('redirectUri'); }, - getClientId: function() { + getClientId: function () { return this._getCredential('clientId'); }, - getClientSecret: function() { + getClientSecret: function () { return this._getCredential('clientSecret'); }, - getAccessToken: function() { + getAccessToken: function () { return this._getCredential('accessToken'); }, - getRefreshToken: function() { + getRefreshToken: function () { return this._getCredential('refreshToken'); }, - resetClientId: function() { + resetClientId: function () { this._resetCredential('clientId'); }, - resetClientSecret: function() { + resetClientSecret: function () { this._resetCredential('clientSecret'); }, - resetAccessToken: function() { + resetAccessToken: function () { this._resetCredential('accessToken'); }, - resetRefreshToken: function() { + resetRefreshToken: function () { this._resetCredential('refreshToken'); }, - resetRedirectURI: function() { + resetRedirectURI: function () { this._resetCredential('redirectUri'); }, - _setCredential: function(credentialKey, value) { + _setCredential: function (credentialKey, value) { this._credentials = this._credentials || {}; this._credentials[credentialKey] = value; }, - _getCredential: function(credentialKey) { + _getCredential: function (credentialKey) { if (!this._credentials) { return; } else { @@ -98,7 +98,7 @@ SpotifyWebApi.prototype = { } }, - _resetCredential: function(credentialKey) { + _resetCredential: function (credentialKey) { if (!this._credentials) { return; } else { @@ -115,7 +115,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, returns an object containing information * about the track. Not returned if a callback is given. */ - getTrack: function(trackId, options, callback) { + getTrack: function (trackId, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/tracks/' + trackId) .withQueryParameters(options) @@ -132,7 +132,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, returns an object containing information * about the artists. Not returned if a callback is given. */ - getTracks: function(trackIds, options, callback) { + getTracks: function (trackIds, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/tracks') .withQueryParameters( @@ -154,7 +154,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, returns an object containing information * about the album. Not returned if a callback is given. */ - getAlbum: function(albumId, options, callback) { + getAlbum: function (albumId, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/albums/' + albumId) .withQueryParameters(options) @@ -171,7 +171,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, returns an object containing information * about the albums. Not returned if a callback is given. */ - getAlbums: function(albumIds, options, callback) { + getAlbums: function (albumIds, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/albums') .withQueryParameters( @@ -184,6 +184,44 @@ SpotifyWebApi.prototype = { .execute(HttpManager.get, callback); }, + /** +* Get current Queue +*/ + + getQueue: function (callback) { + return WebApiRequest.builder(this.getAccessToken()) + .withPath('/v1/me/player/queue') + .build() + .execute(HttpManager.get, callback) + }, + + getPlaylistCoverImage: function (playlistId, callback) { + return WebApiRequest.builder(this.getAccessToken()) + .withPath("/v1/playlists/" + playlistId + "/images") + .withHeaders({ "Content-Type": 'application/json' }) + .build() + .execute(HttpManager.get, callback); + }, + + addToPlaybackQueue: function (uri, callback) { + var baseUrl = "/v1/me" + var path = "/player/queue" + return WebApiRequest.builder(this.getAccessToken()) + .withPath(baseUrl + path) + .withQueryParameters({ uri: uri }) + .build() + .execute(HttpManager.post, callback); + }, + + getAvailableMarkets: function (callback) { + var path = "/v1/markets" + return WebApiRequest.builder(this.getAccessToken()) + .withPath(path) + .withHeaders({ 'Content-Type': 'application/json' }) + .build() + .execute(HttpManager.get, callback); + }, + /** * Look up an artist. * @param {string} artistId The artist's ID. @@ -192,7 +230,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, returns an object containing information * about the artist. Not returned if a callback is given. */ - getArtist: function(artistId, callback) { + getArtist: function (artistId, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/artists/' + artistId) .build() @@ -207,7 +245,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, returns an object containing information * about the artists. Not returned if a callback is given. */ - getArtists: function(artistIds, callback) { + getArtists: function (artistIds, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/artists') .withQueryParameters({ @@ -229,7 +267,7 @@ SpotifyWebApi.prototype = { * search results. The result is paginated. If the promise is rejected, * it contains an error object. Not returned if a callback is given. */ - search: function(query, types, options, callback) { + search: function (query, types, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/search/') .withQueryParameters( @@ -253,7 +291,7 @@ SpotifyWebApi.prototype = { * search results. The result is paginated. If the promise is rejected, * it contains an error object. Not returned if a callback is given. */ - searchAlbums: function(query, options, callback) { + searchAlbums: function (query, options, callback) { return this.search(query, ['album'], options, callback); }, @@ -267,7 +305,7 @@ SpotifyWebApi.prototype = { * search results. The result is paginated. If the promise is rejected, * it contains an error object. Not returned if a callback is given. */ - searchArtists: function(query, options, callback) { + searchArtists: function (query, options, callback) { return this.search(query, ['artist'], options, callback); }, @@ -281,7 +319,7 @@ SpotifyWebApi.prototype = { * search results. The result is paginated. If the promise is rejected, * it contains an error object. Not returned if a callback is given. */ - searchTracks: function(query, options, callback) { + searchTracks: function (query, options, callback) { return this.search(query, ['track'], options, callback); }, @@ -295,7 +333,7 @@ SpotifyWebApi.prototype = { * search results. The result is paginated. If the promise is rejected, * it contains an error object. Not returned if a callback is given. */ - searchPlaylists: function(query, options, callback) { + searchPlaylists: function (query, options, callback) { return this.search(query, ['playlist'], options, callback); }, @@ -309,7 +347,7 @@ SpotifyWebApi.prototype = { * for the given artist. The result is paginated. If the promise is rejected, * it contains an error object. Not returned if a callback is given. */ - getArtistAlbums: function(artistId, options, callback) { + getArtistAlbums: function (artistId, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/artists/' + artistId + '/albums') .withQueryParameters(options) @@ -327,7 +365,7 @@ SpotifyWebApi.prototype = { * tracks in the album. The result is paginated. If the promise is rejected. * it contains an error object. Not returned if a callback is given. */ - getAlbumTracks: function(albumId, options, callback) { + getAlbumTracks: function (albumId, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/albums/' + albumId + '/tracks') .withQueryParameters(options) @@ -345,7 +383,7 @@ SpotifyWebApi.prototype = { * artist's top tracks in the given country. If the promise is rejected, * it contains an error object. Not returned if a callback is given. */ - getArtistTopTracks: function(artistId, country, callback) { + getArtistTopTracks: function (artistId, country, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/artists/' + artistId + '/top-tracks') .withQueryParameters({ @@ -363,7 +401,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, returns an object containing the * related artists. If the promise is rejected, it contains an error object. Not returned if a callback is given. */ - getArtistRelatedArtists: function(artistId, callback) { + getArtistRelatedArtists: function (artistId, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/artists/' + artistId + '/related-artists') .build() @@ -379,7 +417,7 @@ SpotifyWebApi.prototype = { * containing information about the user. If the promise is * rejected, it contains an error object. Not returned if a callback is given. */ - getUser: function(userId, callback) { + getUser: function (userId, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/users/' + encodeURIComponent(userId)) .build() @@ -395,7 +433,7 @@ SpotifyWebApi.prototype = { * depends on the permissions given by the user. If the promise is * rejected, it contains an error object. Not returned if a callback is given. */ - getMe: function(callback) { + getMe: function (callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me') .build() @@ -413,7 +451,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves to an object containing * a list of playlists. If rejected, it contains an error object. Not returned if a callback is given. */ - getUserPlaylists: function(userId, options, callback) { + getUserPlaylists: function (userId, options, callback) { var path; if (typeof userId === 'string') { path = '/v1/users/' + encodeURIComponent(userId) + '/playlists'; @@ -441,7 +479,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves to an object containing * the playlist. If rejected, it contains an error object. Not returned if a callback is given. */ - getPlaylist: function(playlistId, options, callback) { + getPlaylist: function (playlistId, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/playlists/' + playlistId) .withQueryParameters(options) @@ -458,7 +496,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves to an object that containing * the tracks in the playlist. If rejected, it contains an error object. Not returned if a callback is given. */ - getPlaylistTracks: function(playlistId, options, callback) { + getPlaylistTracks: function (playlistId, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/playlists/' + playlistId + '/tracks') .withQueryParameters(options) @@ -475,12 +513,12 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves to an object containing information about the * created playlist. If rejected, it contains an error object. Not returned if a callback is given. */ - createPlaylist: function(name, options, callback) { + createPlaylist: function (name, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/playlists') .withHeaders({ 'Content-Type': 'application/json' }) .withBodyParameters({ - name : name, + name: name, }, options) .build() .execute(HttpManager.post, callback); @@ -494,7 +532,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, simply resolves to an empty object. If rejected, * it contains an error object. Not returned if a callback is given. */ - followPlaylist: function(playlistId, options, callback) { + followPlaylist: function (playlistId, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/playlists/' + playlistId + '/followers') .withHeaders({ 'Content-Type': 'application/json' }) @@ -510,7 +548,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, simply resolves to an empty object. If rejected, * it contains an error object. Not returned if a callback is given. */ - unfollowPlaylist: function(playlistId, callback) { + unfollowPlaylist: function (playlistId, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/playlists/' + playlistId + '/followers') .build() @@ -526,7 +564,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, simply resolves to an empty object. If rejected, * it contains an error object. Not returned if a callback is given. */ - changePlaylistDetails: function(playlistId, options, callback) { + changePlaylistDetails: function (playlistId, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/playlists/' + playlistId) .withHeaders({ 'Content-Type': 'application/json' }) @@ -544,7 +582,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, simply resolves to an empty object. If rejected, * it contains an error object. Not returned if a callback is given. */ - uploadCustomPlaylistCoverImage: function(playlistId, base64URI, callback) { + uploadCustomPlaylistCoverImage: function (playlistId, base64URI, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/playlists/' + playlistId + '/images') .withHeaders({ 'Content-Type': 'image/jpeg' }) @@ -564,7 +602,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful returns an object containing a snapshot_id. If rejected, * it contains an error object. Not returned if a callback is given. */ - addTracksToPlaylist: function(playlistId, tracks, options, callback) { + addTracksToPlaylist: function (playlistId, tracks, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/playlists/' + playlistId + '/tracks') .withHeaders({ 'Content-Type': 'application/json' }) @@ -586,14 +624,14 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful returns an object containing a snapshot_id. If rejected, * it contains an error object. Not returned if a callback is given. */ - removeTracksFromPlaylist: function(playlistId, tracks, options, callback) { + removeTracksFromPlaylist: function (playlistId, tracks, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/playlists/' + playlistId + '/tracks') .withHeaders({ 'Content-Type': 'application/json' }) .withBodyParameters( { tracks: tracks - }, + }, options ) .build() @@ -609,7 +647,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful returns an object containing a snapshot_id. If rejected, * it contains an error object. Not returned if a callback is given. */ - removeTracksFromPlaylistByPosition: function( + removeTracksFromPlaylistByPosition: function ( playlistId, positions, snapshotId, @@ -634,7 +672,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful returns an empty object. If rejected, * it contains an error object. Not returned if a callback is given. */ - replaceTracksInPlaylist: function(playlistId, uris, callback) { + replaceTracksInPlaylist: function (playlistId, uris, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/playlists/' + playlistId + '/tracks') .withHeaders({ 'Content-Type': 'application/json' }) @@ -655,7 +693,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful returns an object containing a snapshot_id. If rejected, * it contains an error object. Not returned if a callback is given. */ - reorderTracksInPlaylist: function( + reorderTracksInPlaylist: function ( playlistId, rangeStart, insertBefore, @@ -685,7 +723,7 @@ SpotifyWebApi.prototype = { * containing information about the audio features. If the promise is * rejected, it contains an error object. Not returned if a callback is given. */ - getAudioFeaturesForTrack: function(trackId, callback) { + getAudioFeaturesForTrack: function (trackId, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/audio-features/' + trackId) .build() @@ -701,7 +739,7 @@ SpotifyWebApi.prototype = { * containing information about the audio analysis. If the promise is * rejected, it contains an error object. Not returned if a callback is given. */ - getAudioAnalysisForTrack: function(trackId, callback) { + getAudioAnalysisForTrack: function (trackId, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/audio-analysis/' + trackId) .build() @@ -717,7 +755,7 @@ SpotifyWebApi.prototype = { * containing information about the audio features for the tracks. If the promise is * rejected, it contains an error object. Not returned if a callback is given. */ - getAudioFeaturesForTracks: function(trackIds, callback) { + getAudioFeaturesForTracks: function (trackIds, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/audio-features') .withQueryParameters({ @@ -735,7 +773,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves to an object containing * a list of tracks and a list of seeds. If rejected, it contains an error object. Not returned if a callback is given. */ - getRecommendations: function(options, callback) { + getRecommendations: function (options, callback) { var _opts = {}; var optionsOfTypeArray = ['seed_artists', 'seed_genres', 'seed_tracks']; for (var option in options) { @@ -766,7 +804,7 @@ SpotifyWebApi.prototype = { * a list of available genres to be used as seeds for recommendations. * If rejected, it contains an error object. Not returned if a callback is given. */ - getAvailableGenreSeeds: function(callback) { + getAvailableGenreSeeds: function (callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/recommendations/available-genre-seeds') .build() @@ -780,7 +818,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves to an object containing a paging object which in turn contains * playlist track objects. Not returned if a callback is given. */ - getMySavedTracks: function(options, callback) { + getMySavedTracks: function (options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/tracks') .withQueryParameters(options) @@ -797,7 +835,7 @@ SpotifyWebApi.prototype = { * The boolean value of true indicates that the track is part of the user's library, otherwise false. * Not returned if a callback is given. */ - containsMySavedTracks: function(trackIds, callback) { + containsMySavedTracks: function (trackIds, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/tracks/contains') .withQueryParameters({ @@ -814,7 +852,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful returns null, otherwise an error. * Not returned if a callback is given. */ - removeFromMySavedTracks: function(trackIds, callback) { + removeFromMySavedTracks: function (trackIds, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/tracks') .withHeaders({ 'Content-Type': 'application/json' }) @@ -829,7 +867,7 @@ SpotifyWebApi.prototype = { * @param {requestCallback} [callback] Optional callback method to be called instead of the promise. * @returns {Promise|undefined} A promise that if successful returns null, otherwise an error. Not returned if a callback is given. */ - addToMySavedTracks: function(trackIds, callback) { + addToMySavedTracks: function (trackIds, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/tracks') .withHeaders({ 'Content-Type': 'application/json' }) @@ -845,7 +883,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful returns null, otherwise an error. * Not returned if a callback is given. */ - removeFromMySavedAlbums: function(albumIds, callback) { + removeFromMySavedAlbums: function (albumIds, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/albums') .withHeaders({ 'Content-Type': 'application/json' }) @@ -860,7 +898,7 @@ SpotifyWebApi.prototype = { * @param {requestCallback} [callback] Optional callback method to be called instead of the promise. * @returns {Promise|undefined} A promise that if successful returns null, otherwise an error. Not returned if a callback is given. */ - addToMySavedAlbums: function(albumIds, callback) { + addToMySavedAlbums: function (albumIds, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/albums') .withHeaders({ 'Content-Type': 'application/json' }) @@ -876,7 +914,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves to an object containing a paging object which in turn contains * playlist album objects. Not returned if a callback is given. */ - getMySavedAlbums: function(options, callback) { + getMySavedAlbums: function (options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/albums') .withQueryParameters(options) @@ -893,7 +931,7 @@ SpotifyWebApi.prototype = { * The boolean value of true indicates that the album is part of the user's library, otherwise false. * Not returned if a callback is given. */ - containsMySavedAlbums: function(albumIds, callback) { + containsMySavedAlbums: function (albumIds, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/albums/contains') .withQueryParameters({ @@ -910,7 +948,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves into a paging object of artists, * otherwise an error. Not returned if a callback is given. */ - getMyTopArtists: function(options, callback) { + getMyTopArtists: function (options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/top/artists') .withQueryParameters(options) @@ -925,7 +963,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves into a paging object of tracks, * otherwise an error. Not returned if a callback is given. */ - getMyTopTracks: function(options, callback) { + getMyTopTracks: function (options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/top/tracks') .withQueryParameters(options) @@ -941,7 +979,7 @@ SpotifyWebApi.prototype = { * otherwise an error. Not returned if a callback is given. Note that the response will be empty * in case the user has enabled private session. */ - getMyRecentlyPlayedTracks: function(options, callback) { + getMyRecentlyPlayedTracks: function (options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/player/recently-played') .withQueryParameters(options) @@ -957,7 +995,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves into a paging object of tracks, * otherwise an error. Not returned if a callback is given. */ - addToQueue: function(uri, options, callback) { + addToQueue: function (uri, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/player/queue') .withQueryParameters( @@ -977,7 +1015,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves into an array of device objects, * otherwise an error. Not returned if a callback is given. */ - getMyDevices: function(callback) { + getMyDevices: function (callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/player/devices') .build() @@ -991,7 +1029,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves into a paging object of tracks, * otherwise an error. Not returned if a callback is given. */ - getMyCurrentPlayingTrack: function(options, callback) { + getMyCurrentPlayingTrack: function (options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/player/currently-playing') .withQueryParameters(options) @@ -1006,7 +1044,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves into a paging object of tracks, * otherwise an error. Not returned if a callback is given. */ - getMyCurrentPlaybackState: function(options, callback) { + getMyCurrentPlaybackState: function (options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/player') .withQueryParameters(options) @@ -1023,7 +1061,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves into an empty response, * otherwise an error. Not returned if a callback is given. */ - transferMyPlayback: function(deviceIds, options, callback) { + transferMyPlayback: function (deviceIds, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/player') .withHeaders({ 'Content-Type': 'application/json' }) @@ -1045,14 +1083,14 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves into an empty response, * otherwise an error. Not returned if a callback is given. */ - play: function(options, callback) { + play: function (options, callback) { /*jshint camelcase: false */ var _options = options || {}; var queryParams = _options.device_id ? { device_id: _options.device_id } : null; var postData = {}; - ['context_uri', 'uris', 'offset', 'position_ms'].forEach(function(field) { + ['context_uri', 'uris', 'offset', 'position_ms'].forEach(function (field) { if (field in _options) { postData[field] = _options[field]; } @@ -1074,7 +1112,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves into an empty response, * otherwise an error. Not returned if a callback is given. */ - pause: function(options, callback) { + pause: function (options, callback) { return ( WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/player/pause') @@ -1096,7 +1134,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves into an empty response, * otherwise an error. Not returned if a callback is given. */ - skipToPrevious: function(options, callback) { + skipToPrevious: function (options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/player/previous') .withQueryParameters( @@ -1114,7 +1152,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves into an empty response, * otherwise an error. Not returned if a callback is given. */ - skipToNext: function(options, callback) { + skipToNext: function (options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/player/next') .withQueryParameters( @@ -1133,7 +1171,7 @@ SpotifyWebApi.prototype = { * 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 */ - seek: function(positionMs, options, callback) { + seek: function (positionMs, options, callback) { var params = { /* jshint camelcase: false */ position_ms: positionMs @@ -1158,7 +1196,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves into an empty response, * otherwise an error. Not returned if a callback is given. */ - setRepeat: function(state, options, callback) { + setRepeat: function (state, options, callback) { var params = { state: state }; @@ -1182,7 +1220,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves into an empty response, * otherwise an error. Not returned if a callback is given. */ - setShuffle: function(state, options, callback) { + setShuffle: function (state, options, callback) { var params = { state: state }; @@ -1205,7 +1243,7 @@ SpotifyWebApi.prototype = { * 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 */ - setVolume: function(volumePercent, options, callback) { + setVolume: function (volumePercent, options, callback) { var params = { /* jshint camelcase: false */ volume_percent: volumePercent @@ -1229,7 +1267,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, simply resolves to an empty object. If rejected, * it contains an error object. Not returned if a callback is given. */ - followUsers: function(userIds, callback) { + followUsers: function (userIds, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/following') .withQueryParameters({ @@ -1248,7 +1286,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, simply resolves to an empty object. If rejected, * it contains an error object. Not returned if a callback is given. */ - followArtists: function(artistIds, callback) { + followArtists: function (artistIds, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/following') .withQueryParameters({ @@ -1267,7 +1305,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, simply resolves to an empty object. If rejected, * it contains an error object. Not returned if a callback is given. */ - unfollowUsers: function(userIds, callback) { + unfollowUsers: function (userIds, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/following') .withQueryParameters({ @@ -1286,7 +1324,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, simply resolves to an empty object. If rejected, * it contains an error object. Not returned if a callback is given. */ - unfollowArtists: function(artistIds, callback) { + unfollowArtists: function (artistIds, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/following') .withQueryParameters({ @@ -1307,7 +1345,7 @@ SpotifyWebApi.prototype = { * The boolean value of true indicates that the user is following that user, otherwise is not. * Not returned if a callback is given. */ - isFollowingUsers: function(userIds, callback) { + isFollowingUsers: function (userIds, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/following/contains') .withQueryParameters({ @@ -1325,7 +1363,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves to an object containing a paging object which contains * album objects. Not returned if a callback is given. */ - getFollowedArtists: function(options, callback) { + getFollowedArtists: function (options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/following') .withQueryParameters( @@ -1347,14 +1385,14 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful returns an array of booleans. If rejected, * it contains an error object. Not returned if a callback is given. */ - areFollowingPlaylist: function(userId, playlistId, followerIds, callback) { + areFollowingPlaylist: function (userId, playlistId, followerIds, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath( '/v1/users/' + - encodeURIComponent(userId) + - '/playlists/' + - playlistId + - '/followers/contains' + encodeURIComponent(userId) + + '/playlists/' + + playlistId + + '/followers/contains' ) .withQueryParameters({ ids: followerIds.join(',') @@ -1373,7 +1411,7 @@ SpotifyWebApi.prototype = { * The boolean value of true indicates that the user is following that artist, otherwise is not. * Not returned if a callback is given. */ - isFollowingArtists: function(artistIds, callback) { + isFollowingArtists: function (artistIds, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/following/contains') .withQueryParameters({ @@ -1391,7 +1429,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves to an object containing a paging object which contains * album objects. Not returned if a callback is given. */ - getNewReleases: function(options, callback) { + getNewReleases: function (options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/browse/new-releases') .withQueryParameters(options) @@ -1406,7 +1444,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves to an object containing a paging object which contains * featured playlists. Not returned if a callback is given. */ - getFeaturedPlaylists: function(options, callback) { + getFeaturedPlaylists: function (options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/browse/featured-playlists') .withQueryParameters(options) @@ -1421,7 +1459,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves to an object containing a paging object of categories. * Not returned if a callback is given. */ - getCategories: function(options, callback) { + getCategories: function (options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/browse/categories') .withQueryParameters(options) @@ -1437,7 +1475,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves to an object containing a category object. * Not returned if a callback is given. */ - getCategory: function(categoryId, options, callback) { + getCategory: function (categoryId, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/browse/categories/' + categoryId) .withQueryParameters(options) @@ -1453,7 +1491,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves to a paging object containing simple playlists. * Not returned if a callback is given. */ - getPlaylistsForCategory: function(categoryId, options, callback) { + getPlaylistsForCategory: function (categoryId, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/browse/categories/' + categoryId + '/playlists') .withQueryParameters(options) @@ -1470,12 +1508,12 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, returns an object containing information * about the show. Not returned if a callback is given. */ - getShow: function(showId, options, callback) { + getShow: function (showId, options, callback) { return WebApiRequest.builder(this.getAccessToken()) - .withPath('/v1/shows/' + showId) - .withQueryParameters(options) - .build() - .execute(HttpManager.get, callback); + .withPath('/v1/shows/' + showId) + .withQueryParameters(options) + .build() + .execute(HttpManager.get, callback); }, /** @@ -1487,7 +1525,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, returns an object containing information * about the shows. Not returned if a callback is given. */ - getShows: function(showIds, options, callback) { + getShows: function (showIds, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/shows') .withQueryParameters( @@ -1509,7 +1547,7 @@ SpotifyWebApi.prototype = { * The boolean value of true indicates that the show is part of the user's library, otherwise false. * Not returned if a callback is given. */ - containsMySavedShows: function(showIds, callback) { + containsMySavedShows: function (showIds, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/shows/contains') .withQueryParameters({ @@ -1526,7 +1564,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful returns null, otherwise an error. * Not returned if a callback is given. */ - removeFromMySavedShows: function(showIds, callback) { + removeFromMySavedShows: function (showIds, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/shows') .withHeaders({ 'Content-Type': 'application/json' }) @@ -1541,7 +1579,7 @@ SpotifyWebApi.prototype = { * @param {requestCallback} [callback] Optional callback method to be called instead of the promise. * @returns {Promise|undefined} A promise that if successful returns null, otherwise an error. Not returned if a callback is given. */ - addToMySavedShows: function(showIds, callback) { + addToMySavedShows: function (showIds, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/shows') .withHeaders({ 'Content-Type': 'application/json' }) @@ -1557,7 +1595,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, resolves to an object containing a paging object which in turn contains * playlist show objects. Not returned if a callback is given. */ - getMySavedShows: function(options, callback) { + getMySavedShows: function (options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/me/shows') .withQueryParameters(options) @@ -1575,7 +1613,7 @@ SpotifyWebApi.prototype = { * episodes in the album. The result is paginated. If the promise is rejected. * it contains an error object. Not returned if a callback is given. */ - getShowEpisodes: function(showId, options, callback) { + getShowEpisodes: function (showId, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/shows/' + showId + '/episodes') .withQueryParameters(options) @@ -1593,7 +1631,7 @@ SpotifyWebApi.prototype = { * search results. The result is paginated. If the promise is rejected, * it contains an error object. Not returned if a callback is given. */ - searchShows: function(query, options, callback) { + searchShows: function (query, options, callback) { return this.search(query, ['show'], options, callback); }, @@ -1607,20 +1645,20 @@ SpotifyWebApi.prototype = { * search results. The result is paginated. If the promise is rejected, * it contains an error object. Not returned if a callback is given. */ - searchEpisodes: function(query, options, callback) { + searchEpisodes: function (query, options, callback) { return this.search(query, ['episode'], options, callback); }, - /** - * Look up an episode. - * @param {string} episodeId The episode's ID. - * @param {Object} [options] The possible options, currently only market. - * @param {requestCallback} [callback] Optional callback method to be called instead of the promise. - * @example getEpisode('3Qm86XLflmIXVm1wcwkgDK').then(...) - * @returns {Promise|undefined} A promise that if successful, returns an object containing information - * about the episode. Not returned if a callback is given. - */ - getEpisode: function(episodeId, options, callback) { + /** + * Look up an episode. + * @param {string} episodeId The episode's ID. + * @param {Object} [options] The possible options, currently only market. + * @param {requestCallback} [callback] Optional callback method to be called instead of the promise. + * @example getEpisode('3Qm86XLflmIXVm1wcwkgDK').then(...) + * @returns {Promise|undefined} A promise that if successful, returns an object containing information + * about the episode. Not returned if a callback is given. + */ + getEpisode: function (episodeId, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/episodes/' + episodeId) .withQueryParameters(options) @@ -1637,7 +1675,7 @@ SpotifyWebApi.prototype = { * @returns {Promise|undefined} A promise that if successful, returns an object containing information * about the episodes. Not returned if a callback is given. */ - getEpisodes: function(episodeIds, options, callback) { + getEpisodes: function (episodeIds, options, callback) { return WebApiRequest.builder(this.getAccessToken()) .withPath('/v1/episodes') .withQueryParameters( @@ -1651,7 +1689,7 @@ SpotifyWebApi.prototype = { }, }; -SpotifyWebApi._addMethods = function(methods) { +SpotifyWebApi._addMethods = function (methods) { for (var i in methods) { if (methods.hasOwnProperty(i)) { this.prototype[i] = methods[i];