diff --git a/README.md b/README.md index ead0de7..ffdfa72 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ app.config(function (SpotifyProvider) { SpotifyProvider.setClientId(''); SpotifyProvider.setRedirectUri(''); SpotifyProvider.setScope(''); - // If you already have an auth token - SpotifyProvider.setAuthToken(''); + // If you already have an access token + SpotifyProvider.setAccessToken(''); }); ``` For example: @@ -38,8 +38,8 @@ app.config(function (SpotifyProvider) { SpotifyProvider.setClientId('ABC123DEF456GHI789JKL'); SpotifyProvider.setRedirectUri('http://www.example.com/callback.html'); SpotifyProvider.setScope('user-read-private playlist-read-private playlist-modify-private playlist-modify-public'); - // If you already have an auth token - SpotifyProvider.setAuthToken('zoasliu1248sdfuiknuha7882iu4rnuwehifskmkiuwhjg23'); + // If you already have an access token + SpotifyProvider.setAccessToken('zoasliu1248sdfuiknuha7882iu4rnuwehifskmkiuwhjg23'); }); ``` @@ -175,11 +175,11 @@ Spotify #### Get an Artist’s Related Artists Get Spotify catalog information about artists similar to a given artist. Similarity is based on analysis of the Spotify community’s listening history. ```js -Spotify.getRelatedArtists('Artist Id or Spotify Artist URI'); +Spotify.getArtistRelatedArtists('Artist Id or Spotify Artist URI'); ``` Example: ```js -Spotify.getRelatedArtists('1vCWHaC5f2uS3yhpwWbIA6').then(function (data) { +Spotify.getArtistRelatedArtists('1vCWHaC5f2uS3yhpwWbIA6').then(function (data) { console.log(data); }); ``` @@ -329,13 +329,13 @@ These endpoints allow you manage the list of artists and users that a logged in Get the current user’s followed artists. ```js -Spotify.following('type', options) +Spotify.getFollowed('type', options) ``` - type: Required. currently only ```artist``` is supported. ```js -Spotify.following('artists', { limit: 10 }).then(function (artists) { +Spotify.getFollowed('artists', { limit: 10 }).then(function (artists) { console.log(artists); }) ``` @@ -354,6 +354,16 @@ Spotify.follow('user', 'exampleuser01').then(function () { }); ``` +#### Follow Users +```js +Spotify.followUsers('ids'); +``` + +#### Follow Artists +```js +Spotify.followArtists('ids'); +``` + #### Unfollow Artists or Users Remove the current user as a follower of one or more artists or other Spotify users. ```js @@ -368,21 +378,41 @@ Spotify.unfollow('user', 'exampleuser01').then(function () { }); ``` +#### Unfollow Users +```js +Spotify.unfollowUsers('ids'); +``` + +#### Unfollow Artists +```js +Spotify.unfollowArtists('ids'); +``` + #### Check if Current User Follows Check to see if the current user is following one or more artists or other Spotify users. ```js -Spotify.userFollowingContains('type', 'ids'); +Spotify.isFollowing('type', 'ids'); ``` - type: Required. either ```artist``` or ```user``` - ids: Required. comma-separated list. Example: ```js -Spotify.userFollowingContains('user', 'exampleuser01').then(function (data) { +Spotify.isFollowing('user', 'exampleuser01').then(function (data) { console.log(data); }); ``` +#### Check if Current User Follows Users +```js +Spotify.isFollowingUsers(ids); +``` + +#### Check if Current User Follows Artists +```js +Spotify.isFollowingArtists(ids); +``` + #### Follow a Playlist Add the current user as a follower of a playlist. Requires ```playlist-modify-public``` or ```playlist-modify-private``` scope to work. ```js @@ -424,11 +454,11 @@ Spotify Checking if the user is privately following a playlist is only possible for the current user when that user has granted access to the ```playlist-read-private``` scope. ```js Spotify - .playlistFollowingContains('owner_id', 'playlist_id', 'comma separated string or array of user ids'); + .areFollowingPlaylist('owner_id', 'playlist_id', 'comma separated string or array of user ids'); ``` Example: ```js - Spotify.playlistFollowingContains('jmperezperez', '2v3iNvBX8Ay1Gt2uXtUKUT', 'possan,elogain').then(function (data) { + Spotify.areFollowingPlaylist('jmperezperez', '2v3iNvBX8Ay1Gt2uXtUKUT', 'possan,elogain').then(function (data) { console.log(data); }); ``` @@ -438,7 +468,7 @@ Spotify #### Get Current User’s Saved Tracks Get a list of the songs saved in the current Spotify user’s “Your Music” library. Requires the ```user-library-read``` scope. ```js -Spotify.getSavedUserTracks(options); +Spotify.getMySavedTracks(options); ``` ##### Options Object (Optional) @@ -446,7 +476,7 @@ Spotify.getSavedUserTracks(options); - offset - Optional. The index of the first object to return. Default: 0 (i.e., the first object). Use with limit to get the next set of objects. ```js -Spotify.getSavedUserTracks().then(function (data) { +Spotify.getMySavedTracks().then(function (data) { console.log(data); }); ``` @@ -456,12 +486,12 @@ Spotify.getSavedUserTracks().then(function (data) { Check if one or more tracks is already saved in the current Spotify user’s “Your Music” library. Requires the ```user-library-read``` scope. ```js -Spotify.userTracksContains('comma separated string or array of spotify track ids'); +Spotify.containsMySavedTracks('comma separated string or array of spotify track ids'); ``` Example: ```js Spotify - .userTracksContains('0udZHhCi7p1YzMlvI4fXoK,3SF5puV5eb6bgRSxBeMOk9') + .containsMySavedTracks('0udZHhCi7p1YzMlvI4fXoK,3SF5puV5eb6bgRSxBeMOk9') .then(function (data) { console.log(data); }); @@ -471,12 +501,12 @@ Spotify #### Save Tracks for Current User Save one or more tracks to the current user’s “Your Music” library. Requires the ```user-library-modify``` scope. ```js -Spotify.saveUserTracks('comma separated string or array of spotify track ids'); +Spotify.addToMySavedTracks('comma separated string or array of spotify track ids'); ``` Example: ```js Spotify - .saveUserTracks('0udZHhCi7p1YzMlvI4fXoK,3SF5puV5eb6bgRSxBeMOk9') + .addToMySavedTracks('0udZHhCi7p1YzMlvI4fXoK,3SF5puV5eb6bgRSxBeMOk9') .then(function (data) { console.log(data); }); @@ -486,12 +516,12 @@ Spotify #### Remove Tracks for Current User Remove one or more tracks from the current user’s “Your Music” library. Requires the ```user-library-modify``` scope. ```js -Spotify.removeUserTracks('comma separated string or array of spotify track ids'); +Spotify.removeFromMySavedTracks('comma separated string or array of spotify track ids'); ``` Example: ```js Spotify - .removeUserTracks('0udZHhCi7p1YzMlvI4fXoK,3SF5puV5eb6bgRSxBeMOk9') + .removeFromMySavedTracks('0udZHhCi7p1YzMlvI4fXoK,3SF5puV5eb6bgRSxBeMOk9') .then(function (data) { console.log(data); }); @@ -501,12 +531,12 @@ Spotify #### Save Albums for Current User Save one or more albums to the current user’s “Your Music” library. Requires the ```user-library-modify``` scope. ```js -Spotify.saveUserAlbums('comma separated string or array of spotify album ids'); +Spotify.addToMySavedAlbums('comma separated string or array of spotify album ids'); ``` Example: ```js Spotify - .saveUserAlbums('4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M') + .addToMySavedAlbums('4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M') .then(function (data) { console.log(data); }); @@ -515,7 +545,7 @@ Spotify #### Get Current User’s Saved Albums Get a list of the albums saved in the current Spotify user’s “Your Music” library. Requires the ```user-library-read``` scope. ```js -Spotify.getSavedUserAlbums(options); +Spotify.getMySavedAlbums(options); ``` ##### Options Object (Optional) @@ -524,7 +554,7 @@ Spotify.getSavedUserAlbums(options); - market - Optional. An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. ```js -Spotify.getSavedUserAlbums().then(function (data) { +Spotify.getMySavedAlbums().then(function (data) { console.log(data); }); ``` @@ -532,12 +562,12 @@ Spotify.getSavedUserAlbums().then(function (data) { #### Remove Albums for Current User Remove one or more albums from the current user’s “Your Music” library. Requires the ```user-library-modify``` scope. ```js -Spotify.removeUserAlbums('comma separated string or array of spotify album ids'); +Spotify.removeFromMySavedAlbums('comma separated string or array of spotify album ids'); ``` Example: ```js Spotify - .removeUserAlbums('4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M') + .removeFromMySavedAlbums('4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M') .then(function (data) { console.log(data); }); @@ -548,12 +578,12 @@ Spotify Check if one or more albums is already saved in the current Spotify user’s “Your Music” library. Requires the ```user-library-read``` scope. ```js -Spotify.userAlbumsContains('comma separated string or array of spotify album ids'); +Spotify.containsMySavedAlbums('comma separated string or array of spotify album ids'); ``` Example: ```js Spotify - .userAlbumsContains('4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M') + .containsMySavedAlbums('4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M') .then(function (data) { console.log(data); }); @@ -566,7 +596,7 @@ Endpoints for retrieving information about the user’s listening habits. #### Get a User’s Top Artists Get the current user’s top artists based on calculated affinity. ```js -Spotify.getUserTopArtists(options); +Spotify.getMyTopArtists(options); ``` ##### Options Object (Optional) @@ -576,7 +606,7 @@ Spotify.getUserTopArtists(options); Example: ```js -Spotify.getUserTopArtists({ limit: 50 }).then(function (data) { +Spotify.getMyTopArtists({ limit: 50 }).then(function (data) { console.log(data); }); ``` @@ -584,7 +614,7 @@ Spotify.getUserTopArtists({ limit: 50 }).then(function (data) { #### Get a User’s Top Tracks Get the current user’s top tracks based on calculated affinity. ```js -Spotify.getUserTopTracks(options); +Spotify.getMyTopTracks(options); ``` ##### Options Object (Optional) @@ -594,7 +624,7 @@ Spotify.getUserTopTracks(options); Example: ```js -Spotify.getUserTopTracks({ limit: 50 }).then(function (data) { +Spotify.getMyTopTracks({ limit: 50 }).then(function (data) { console.log(data); }); ``` @@ -674,7 +704,7 @@ Spotify #### Add Tracks to a Playlist Add one or more tracks to a user’s playlist. Adding tracks to a public playlist requires the ```playlist-modify-public``` scope. Adding tracks to a private playlist requires the ```playlist-modify-private``` scope. ```js -Spotify.addPlaylistTracks('user_id', 'playlist_id', 'comma separated string or array of spotify track uris'); +Spotify.addTracksToPlaylist('user_id', 'playlist_id', 'comma separated string or array of spotify track uris'); ``` ##### Options Object (Optional) - position - integer - Optional. The position to insert the tracks, a zero-based index. For example, to insert the tracks in the first position: position=0; to insert the tracks in the third position: position=2. If omitted, the tracks will be appended to the playlist. Tracks are added in the order they are listed in the query string or request body. @@ -683,7 +713,7 @@ Spotify.addPlaylistTracks('user_id', 'playlist_id', 'comma separated string or a Example: ```js Spotify - .addPlaylistTracks('1176458919', '2TkWjGCu8jurholsfdWtG4', 'spotify:track:4iV5W9uYEdYUVa79Axb7Rh, spotify:track:1301WleyT98MSxVHPZCA6M') + .addTracksToPlaylist('1176458919', '2TkWjGCu8jurholsfdWtG4', 'spotify:track:4iV5W9uYEdYUVa79Axb7Rh, spotify:track:1301WleyT98MSxVHPZCA6M') .then(function (data) { console.log('tracks added to playlist'); }); @@ -693,12 +723,40 @@ Spotify #### Remove Tracks from a Playlist Remove one or more tracks from a user’s playlist. Removing tracks from a public playlist requires the ```playlist-modify-public``` scope. Removing tracks from a private playlist requires the ```playlist-modify-private``` scope. ```js -Spotify.removePlaylistTracks('user_id', 'playlist_id', 'comma separated string or array of spotify track ids or uris'); +Spotify.removeTracksFromPlaylist('user_id', 'playlist_id', 'comma separated string or array of spotify track ids or uris'); ``` Example: ```js Spotify - .removePlaylistTracks('1176458919', '2TkWjGCu8jurholsfdWtG4', 'spotify:track:4iV5W9uYEdYUVa79Axb7Rh, spotify:track:1301WleyT98MSxVHPZCA6M') + .removeTracksFromPlaylist('1176458919', '2TkWjGCu8jurholsfdWtG4', 'spotify:track:4iV5W9uYEdYUVa79Axb7Rh, spotify:track:1301WleyT98MSxVHPZCA6M') + .then(function (data) { + console.log('tracks removed from playlist'); + }); +``` + +##### Remove Tracks from a Playlist given snapshot ID +```js +Spotify.removeTracksFromPlaylistWithSnapshotId('user_id', 'playlist_id', 'comma separated string or array of spotify track ids or uris', 'snapshot_id'); +``` + +Example: +```js +Spotify + .removeTracksFromPlaylistWithSnapshotId('1176458919', '2TkWjGCu8jurholsfdWtG4', ['spotify:track:4iV5W9uYEdYUVa79Axb7Rh', 'spotify:track:1301WleyT98MSxVHPZCA6M'], 'JbtmHBDBAYu3/bt8BOXKjzKx3i0b6LCa/wVjyl6qQ2Yf6nFXkbmzuEa+ZI/U1yF+') + .then(function (data) { + console.log('tracks removed from playlist'); + }); +``` + +##### Remove Tracks from a Playlist in positions +```js +Spotify.removeTracksFromPlaylistInPositions('user_id', 'playlist_id', 'array of positions', 'snapshot_id'); +``` + +Example: +```js +Spotify + .removeTracksFromPlaylistInPositions('1176458919', '2TkWjGCu8jurholsfdWtG4', [1,3,5,7,9], 'JbtmHBDBAYu3/bt8BOXKjzKx3i0b6LCa/wVjyl6qQ2Yf6nFXkbmzuEa+ZI/U1yF+') .then(function (data) { console.log('tracks removed from playlist'); }); @@ -707,7 +765,7 @@ Spotify #### Reorder a Playlist's Tracks Reorder a track or a group of tracks in a playlist. ```js -Spotify.reorderPlaylistTracks('user_id', 'playlist_id', options); +Spotify.reorderTracksInPlaylist('user_id', 'playlist_id', options); ``` ##### Options Object (Required) - range_start - integer - Required. The position of the first track to be reordered. @@ -718,7 +776,7 @@ Spotify.reorderPlaylistTracks('user_id', 'playlist_id', options); Example: ```js -Spotify.reorderPlaylistTracks('1176458919', '2TkWjGCu8jurholsfdWtG4', { +Spotify.reorderTracksInPlaylist('1176458919', '2TkWjGCu8jurholsfdWtG4', { range_start: 8, range_length: 5, insert_before: 0 @@ -731,12 +789,12 @@ Spotify.reorderPlaylistTracks('1176458919', '2TkWjGCu8jurholsfdWtG4', { #### Replace a Playlist’s Tracks Replace all the tracks in a playlist, overwriting its existing tracks. This powerful request can be useful for replacing tracks, re-ordering existing tracks, or clearing the playlist. Replacing tracks in a public playlist requires the ```playlist-modify-public``` scope. Replacing tracks in a private playlist requires the ```playlist-modify-private``` scope. ```js -Spotify.replacePlaylistTracks('user_id', 'playlist_id', 'comma separated string or array of spotify track ids or uris'); +Spotify.replaceTracksInPlaylist('user_id', 'playlist_id', 'comma separated string or array of spotify track ids or uris'); ``` Example: ```js Spotify - .replacePlaylistTracks('1176458919', '2TkWjGCu8jurholsfdWtG4', 'spotify:track:4iV5W9uYEdYUVa79Axb7Rh, spotify:track:1301WleyT98MSxVHPZCA6M') + .replaceTracksInPlaylist('1176458919', '2TkWjGCu8jurholsfdWtG4', 'spotify:track:4iV5W9uYEdYUVa79Axb7Rh, spotify:track:1301WleyT98MSxVHPZCA6M') .then(function (data) { console.log('tracks removed from playlist'); }); @@ -746,7 +804,7 @@ Spotify #### Change a Playlist’s Details Change a playlist’s name and public/private state. (The user must, of course, own the playlist.) Changing a public playlist requires the ```playlist-modify-public``` scope. Changing a private playlist requires the ```playlist-modify-private``` scope. ```js -Spotify.updatePlaylistDetails('user_id', 'playlist_id', options); +Spotify.changePlaylistDetails('user_id', 'playlist_id', options); ``` ##### Options Object (Optional) - name - string - Optional. The new name for the playlist, for example "My New Playlist Title". @@ -756,7 +814,7 @@ Spotify.updatePlaylistDetails('user_id', 'playlist_id', options); Example: ```js Spotify - .updatePlaylistDetails('1176458919', '2TkWjGCu8jurholsfdWtG4', { name: 'Updated Playlist Title' }) + .changePlaylistDetails('1176458919', '2TkWjGCu8jurholsfdWtG4', { name: 'Updated Playlist Title' }) .then(function (data) { console.log('Updated playlist details'); }); @@ -782,11 +840,11 @@ Spotify.getUser('wizzler').then(function (data) { #### Get Current User’s Profile Get detailed profile information about the current user (including the current user’s username). ```js -Spotify.getCurrentUser(); +Spotify.getMe(); ``` Example: ```js -Spotify.getCurrentUser().then(function (data) { +Spotify.getMe().then(function (data) { console.log(data); }); ``` @@ -798,7 +856,7 @@ Get Spotify catalog information about artists, albums, or tracks that match a ke ```js Spotify.search('Search Query', 'type', options); ``` -- type - Required. A comma-separated list of item types to search across. Valid types are: album, artist, playlist, and track. +- type - Required. An array or comma-separated list of item types to search across. Valid types are: album, artist, playlist, and track. ##### Options Object (Optional) - limit - Optional. The maximum number of objects to return. Default: 20. Minimum: 1. Maximum: 50. @@ -812,6 +870,25 @@ Spotify.search('Nirvana', 'artist').then(function (data) { }); ``` +#### Search for Albums +```js +Spotify.searchAlbums('Search Query', options); +``` + +#### Search for Artists +```js +Spotify.searchArtists('Search Query', options); +``` + +#### Search for Tracks +```js +Spotify.searchTracks('Search Query', options); +``` + +#### Search for Playlists +```js +Spotify.searchPlaylists('Search Query', options); +``` ### Tracks #### Get a Track @@ -842,11 +919,11 @@ Spotify.getTracks('0eGsygTp906u18L0Oimnem,1lDWb6b6ieDQ2xT7ewTC3G').then(function Get audio feature information for a single track identified by its unique Spotify ID. ```js -Spotify.getTrackAudioFeatures('Track Id or Spotify Track URI'); +Spotify.getAudioFeaturesForTrack('Track Id or Spotify Track URI'); ``` Example: ```js -Spotify.getTrackAudioFeatures('0eGsygTp906u18L0Oimnem').then(function (data) { +Spotify.getAudioFeaturesForTrack('0eGsygTp906u18L0Oimnem').then(function (data) { console.log(data); }); ``` @@ -855,11 +932,11 @@ Spotify.getTrackAudioFeatures('0eGsygTp906u18L0Oimnem').then(function (data) { Get audio features for multiple tracks based on their Spotify IDs. ```js -Spotify.getTracksAudioFeatures('Comma separated list or array of Track Ids'); +Spotify.getAudioFeaturesForTracks('Comma separated list or array of Track Ids'); ``` Example: ```js -Spotify.getTracksAudioFeatures('0eGsygTp906u18L0Oimnem,1lDWb6b6ieDQ2xT7ewTC3G').then(function (data) { +Spotify.getAudioFeaturesForTracks('0eGsygTp906u18L0Oimnem,1lDWb6b6ieDQ2xT7ewTC3G').then(function (data) { console.log(data); }); ``` diff --git a/bower.json b/bower.json index 45b75a2..3a9ef60 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-spotify", - "version": "1.4.2", + "version": "1.4.0", "authors": [ "Ed Moore " ], diff --git a/dist/angular-spotify.min.js b/dist/angular-spotify.min.js index 2d47b74..de540df 100644 --- a/dist/angular-spotify.min.js +++ b/dist/angular-spotify.min.js @@ -1,2 +1,2 @@ -/*! angular-spotify v1.4.2 2016-06-03 */ -!function(a,b,c){"use strict";b.module("spotify",[]).provider("Spotify",function(){var c={};c.clientId=null,c.redirectUri=null,c.scope=null,c.authToken=null,this.setClientId=function(a){return c.clientId=a,c.clientId},this.getClientId=function(){return c.clientId},this.setAuthToken=function(a){return c.authToken=a,c.authToken},this.setRedirectUri=function(a){return c.redirectUri=a,c.redirectUri},this.getRedirectUri=function(){return c.redirectUri},this.setScope=function(a){return c.scope=a,c.scope};var d={};d.toQueryString=function(a){var c=[];return b.forEach(a,function(a,b){this.push(encodeURIComponent(b)+"="+encodeURIComponent(a))},c),c.join("&")},c.apiBase="https://api.spotify.com/v1",this.$get=["$q","$http","$window",function(e,f,g){function h(){this.clientId=c.clientId,this.redirectUri=c.redirectUri,this.apiBase=c.apiBase,this.scope=c.scope,this.authToken=c.authToken,this.toQueryString=d.toQueryString}function i(b,c,d,e){var f=a.open(b,c,d),g=a.setInterval(function(){try{f&&!f.closed||(a.clearInterval(g),e(f))}catch(b){}},1e3);return f}return h.prototype={api:function(a,b,c,d,g){var h=e.defer();return f({url:this.apiBase+a,method:b?b:"GET",params:c,data:d,headers:g,withCredentials:!1}).success(function(a){h.resolve(a)}).error(function(a){h.reject(a)}),h.promise},_auth:function(a){var b={Authorization:"Bearer "+this.authToken};return a&&(b["Content-Type"]="application/json"),b},getAlbum:function(a){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/albums/"+a)},getAlbums:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/albums","GET",{ids:a?a.toString():""})},getAlbumTracks:function(a,b){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/albums/"+a+"/tracks","GET",b)},getArtist:function(a){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/artists/"+a)},getArtists:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/artists/","GET",{ids:a?a.toString():""})},getArtistAlbums:function(a,b){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/artists/"+a+"/albums","GET",b)},getArtistTopTracks:function(a,b){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/artists/"+a+"/top-tracks","GET",{country:b})},getRelatedArtists:function(a){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/artists/"+a+"/related-artists")},getFeaturedPlaylists:function(a){return this.api("/browse/featured-playlists","GET",a,null,this._auth())},getNewReleases:function(a){return this.api("/browse/new-releases","GET",a,null,this._auth())},getCategories:function(a){return this.api("/browse/categories","GET",a,null,this._auth())},getCategory:function(a,b){return this.api("/browse/categories/"+a,"GET",b,null,this._auth())},getCategoryPlaylists:function(a,b){return this.api("/browse/categories/"+a+"/playlists","GET",b,null,this._auth())},getRecommendations:function(a){return this.api("/recommendations","GET",a,null,this._auth())},getAvailableGenreSeeds:function(){return this.api("/recommendations/available-genre-seeds","GET",null,null,this._auth())},following:function(a,b){return b=b||{},b.type=a,this.api("/me/following","GET",b,null,this._auth())},follow:function(a,b){return this.api("/me/following","PUT",{type:a,ids:b},null,this._auth())},unfollow:function(a,b){return this.api("/me/following","DELETE",{type:a,ids:b},null,this._auth())},userFollowingContains:function(a,b){return this.api("/me/following/contains","GET",{type:a,ids:b},null,this._auth())},followPlaylist:function(a,b,c){return this.api("/users/"+a+"/playlists/"+b+"/followers","PUT",null,{"public":c||null},this._auth(!0))},unfollowPlaylist:function(a,b){return this.api("/users/"+a+"/playlists/"+b+"/followers","DELETE",null,null,this._auth())},playlistFollowingContains:function(a,b,c){return this.api("/users/"+a+"/playlists/"+b+"/followers/contains","GET",{ids:c.toString()},null,this._auth())},getSavedUserTracks:function(a){return this.api("/me/tracks","GET",a,null,this._auth())},userTracksContains:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/me/tracks/contains","GET",{ids:a.toString()},null,this._auth())},saveUserTracks:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/me/tracks","PUT",{ids:a.toString()},null,this._auth())},removeUserTracks:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/me/tracks","DELETE",{ids:a.toString()},null,this._auth(!0))},saveUserAlbums:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/me/albums","PUT",{ids:a.toString()},null,this._auth())},getSavedUserAlbums:function(a){return this.api("/me/albums","GET",a,null,this._auth())},removeUserAlbums:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/me/albums","DELETE",{ids:a.toString()},null,this._auth(!0))},userAlbumsContains:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/me/albums/contains","GET",{ids:a.toString()},null,this._auth())},getUserTopArtists:function(a){return a=a||{},this.api("/me/top/artists","GET",a,null,this._auth())},getUserTopTracks:function(a){return a=a||{},this.api("/me/top/tracks","GET",a,null,this._auth())},getUserPlaylists:function(a,b){return this.api("/users/"+a+"/playlists","GET",b,null,{Authorization:"Bearer "+this.authToken})},getPlaylist:function(a,b,c){return this.api("/users/"+a+"/playlists/"+b,"GET",c,null,this._auth())},getPlaylistTracks:function(a,b,c){return this.api("/users/"+a+"/playlists/"+b+"/tracks","GET",c,null,this._auth())},createPlaylist:function(a,b){return this.api("/users/"+a+"/playlists","POST",null,b,this._auth(!0))},addPlaylistTracks:function(a,c,d,e){return d=b.isArray(d)?d:d.split(","),b.forEach(d,function(a,b){d[b]=-1===a.indexOf("spotify:")?"spotify:track:"+a:a}),this.api("/users/"+a+"/playlists/"+c+"/tracks","POST",{uris:d.toString(),position:e?e.position:null},null,this._auth(!0))},removePlaylistTracks:function(a,c,d){d=b.isArray(d)?d:d.split(",");var e;return b.forEach(d,function(a,b){e=d[b],d[b]={uri:-1===e.indexOf("spotify:")?"spotify:track:"+e:e}}),this.api("/users/"+a+"/playlists/"+c+"/tracks","DELETE",null,{tracks:d},this._auth(!0))},reorderPlaylistTracks:function(a,b,c){return this.api("/users/"+a+"/playlists/"+b+"/tracks","PUT",null,c,this._auth(!0))},replacePlaylistTracks:function(a,c,d){d=b.isArray(d)?d:d.split(",");var e;return b.forEach(d,function(a,b){e=d[b],d[b]=-1===e.indexOf("spotify:")?"spotify:track:"+e:e}),this.api("/users/"+a+"/playlists/"+c+"/tracks","PUT",{uris:d.toString()},null,this._auth(!0))},updatePlaylistDetails:function(a,b,c){return this.api("/users/"+a+"/playlists/"+b,"PUT",null,c,this._auth(!0))},getUser:function(a){return this.api("/users/"+a)},getCurrentUser:function(){return this.api("/me","GET",null,null,this._auth())},search:function(a,b,c){return c=c||{},c.q=a,c.type=b,this.api("/search","GET",c)},getTrack:function(a){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/tracks/"+a)},getTracks:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/tracks/","GET",{ids:a?a.toString():""})},getTrackAudioFeatures:function(a){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/audio-features/"+a,"GET",null,null,this._auth())},getTracksAudioFeatures:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/audio-features/","GET",{ids:a?a.toString():""},null,this._auth())},setAuthToken:function(a){return this.authToken=a,this.authToken},login:function(){function a(d){"spotify-token"===d.key&&(m&&m.close(),l=!0,c.setAuthToken(d.newValue),g.removeEventListener("storage",a,!1),b.resolve(d.newValue))}var b=e.defer(),c=this,d=400,f=500,h=screen.width/2-d/2,j=screen.height/2-f/2,k={client_id:this.clientId,redirect_uri:this.redirectUri,scope:this.scope||"",response_type:"token"},l=!1,m=i("https://accounts.spotify.com/authorize?"+this.toQueryString(k),"Spotify","menubar=no,location=no,resizable=yes,scrollbars=yes,status=no,width="+d+",height="+f+",top="+j+",left="+h,function(){l||b.reject()});return g.addEventListener("storage",a,!1),b.promise}},new h}]})}(window,angular); \ No newline at end of file +/*! angular-spotify v1.4.0 2016-04-11 */ +!function(a,b,c){"use strict";b.module("spotify",[]).provider("Spotify",function(){var c={};c.clientId=null,c.redirectUri=null,c.scope=null,c.authToken=null,this.setClientId=function(a){return c.clientId=a,c.clientId},this.getClientId=function(){return c.clientId},this.setAuthToken=function(a){return c.authToken=a,c.authToken},this.setRedirectUri=function(a){return c.redirectUri=a,c.redirectUri},this.getRedirectUri=function(){return c.redirectUri},this.setScope=function(a){return c.scope=a,c.scope};var d={};d.toQueryString=function(a){var c=[];return b.forEach(a,function(a,b){this.push(encodeURIComponent(b)+"="+encodeURIComponent(a))},c),c.join("&")},c.apiBase="https://api.spotify.com/v1",this.$get=["$q","$http","$window",function(e,f,g){function h(){this.clientId=c.clientId,this.redirectUri=c.redirectUri,this.apiBase=c.apiBase,this.scope=c.scope,this.authToken=c.authToken,this.toQueryString=d.toQueryString}function i(b,c,d,e){var f=a.open(b,c,d),g=a.setInterval(function(){try{f&&!f.closed||(a.clearInterval(g),e(f))}catch(b){}},1e3);return f}return h.prototype={api:function(a,b,c,d,g){var h=e.defer();return f({url:this.apiBase+a,method:b?b:"GET",params:c,data:d,headers:g,withCredentials:!1}).success(function(a){h.resolve(a)}).error(function(a){h.reject(a)}),h.promise},_auth:function(a){var b={Authorization:"Bearer "+this.authToken};return a&&(b["Content-Type"]="application/json"),b},getAlbum:function(a){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/albums/"+a)},getAlbums:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/albums","GET",{ids:a?a.toString():""})},getAlbumTracks:function(a,b){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/albums/"+a+"/tracks","GET",b)},getArtist:function(a){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/artists/"+a)},getArtists:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/artists/","GET",{ids:a?a.toString():""})},getArtistAlbums:function(a,b){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/artists/"+a+"/albums","GET",b)},getArtistTopTracks:function(a,b){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/artists/"+a+"/top-tracks","GET",{country:b})},getRelatedArtists:function(a){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/artists/"+a+"/related-artists")},getFeaturedPlaylists:function(a){return this.api("/browse/featured-playlists","GET",a,null,this._auth())},getNewReleases:function(a){return this.api("/browse/new-releases","GET",a,null,this._auth())},getCategories:function(a){return this.api("/browse/categories","GET",a,null,this._auth())},getCategory:function(a,b){return this.api("/browse/categories/"+a,"GET",b,null,this._auth())},getCategoryPlaylists:function(a,b){return this.api("/browse/categories/"+a+"/playlists","GET",b,null,this._auth())},getRecommendations:function(a){return this.api("/recommendations","GET",a,null,this._auth())},getAvailableGenreSeeds:function(){return this.api("/recommendations/available-genre-seeds","GET",null,null,this._auth())},following:function(a,b){return b=b||{},b.type=a,this.api("/me/following","GET",b,null,this._auth())},follow:function(a,b){return this.api("/me/following","PUT",{type:a,ids:b},null,this._auth())},unfollow:function(a,b){return this.api("/me/following","DELETE",{type:a,ids:b},null,this._auth())},userFollowingContains:function(a,b){return this.api("/me/following/contains","GET",{type:a,ids:b},null,this._auth())},followPlaylist:function(a,b,c){return this.api("/users/"+a+"/playlists/"+b+"/followers","PUT",null,{"public":c||null},this._auth(!0))},unfollowPlaylist:function(a,b){return this.api("/users/"+a+"/playlists/"+b+"/followers","DELETE",null,null,this._auth())},playlistFollowingContains:function(a,b,c){return this.api("/users/"+a+"/playlists/"+b+"/followers/contains","GET",{ids:c.toString()},null,this._auth())},getSavedUserTracks:function(a){return this.api("/me/tracks","GET",a,null,this._auth())},userTracksContains:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/me/tracks/contains","GET",{ids:a.toString()},null,this._auth())},saveUserTracks:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/me/tracks","PUT",{ids:a.toString()},null,this._auth())},removeUserTracks:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/me/tracks","DELETE",{ids:a.toString()},null,this._auth(!0))},saveUserAlbums:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/me/albums","PUT",{ids:a.toString()},null,this._auth())},getSavedUserAlbums:function(a){return this.api("/me/albums","GET",a,null,this._auth())},removeUserAlbums:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/me/albums","DELETE",{ids:a.toString()},null,this._auth(!0))},userAlbumsContains:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/me/albums/contains","GET",{ids:a.toString()},null,this._auth())},getUserTopArtists:function(a){return a=a||{},this.api("/me/top/artists","GET",a,null,this._auth())},getUserTopTracks:function(a){return a=a||{},this.api("/me/top/tracks","GET",a,null,this._auth())},getUserPlaylists:function(a,b){return this.api("/users/"+a+"/playlists","GET",b,null,{Authorization:"Bearer "+this.authToken})},getPlaylist:function(a,b,c){return this.api("/users/"+a+"/playlists/"+b,"GET",c,null,this._auth())},getPlaylistTracks:function(a,b,c){return this.api("/users/"+a+"/playlists/"+b+"/tracks","GET",c,null,this._auth())},createPlaylist:function(a,b){return this.api("/users/"+a+"/playlists","POST",null,b,this._auth(!0))},addPlaylistTracks:function(a,c,d,e){return d=b.isArray(d)?d:d.split(","),b.forEach(d,function(a,b){d[b]=-1===a.indexOf("spotify:")?"spotify:track:"+a:a}),this.api("/users/"+a+"/playlists/"+c+"/tracks","POST",{uris:d.toString(),position:e?e.position:null},null,this._auth(!0))},removePlaylistTracks:function(a,c,d){d=b.isArray(d)?d:d.split(",");var e;return b.forEach(d,function(a,b){e=d[b],d[b]={uri:-1===e.indexOf("spotify:")?"spotify:track:"+e:e}}),this.api("/users/"+a+"/playlists/"+c+"/tracks","DELETE",null,{tracks:d},this._auth(!0))},reorderPlaylistTracks:function(a,b,c){return this.api("/users/"+a+"/playlists/"+b+"/tracks","PUT",null,c,this._auth(!0))},replacePlaylistTracks:function(a,c,d){d=b.isArray(d)?d:d.split(",");var e;return b.forEach(d,function(a,b){e=d[b],d[b]=-1===e.indexOf("spotify:")?"spotify:track:"+e:e}),this.api("/users/"+a+"/playlists/"+c+"/tracks","PUT",{uris:d.toString()},null,this._auth(!0))},updatePlaylistDetails:function(a,b,c){return this.api("/users/"+a+"/playlists/"+b,"PUT",null,c,this._auth(!0))},getUser:function(a){return this.api("/users/"+a)},getCurrentUser:function(){return this.api("/me","GET",null,null,this._auth())},search:function(a,b,c){return c=c||{},c.q=a,c.type=b,this.api("/search","GET",c)},getTrack:function(a){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/tracks/"+a)},getTracks:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/tracks/","GET",{ids:a?a.toString():""})},getTrackAudioFeatures:function(a){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/audio-features/"+a)},getTracksAudioFeatures:function(a){return a=b.isString(a)?a.split(","):a,b.forEach(a,function(b,c){a[c]=b.indexOf("spotify:")>-1?b.split(":")[2]:b}),this.api("/audio-features/","GET",{ids:a?a.toString():""})},setAuthToken:function(a){return this.authToken=a,this.authToken},login:function(){function a(d){"spotify-token"===d.key&&(m&&m.close(),l=!0,c.setAuthToken(d.newValue),g.removeEventListener("storage",a,!1),b.resolve(d.newValue))}var b=e.defer(),c=this,d=400,f=500,h=screen.width/2-d/2,j=screen.height/2-f/2,k={client_id:this.clientId,redirect_uri:this.redirectUri,scope:this.scope||"",response_type:"token"},l=!1,m=i("https://accounts.spotify.com/authorize?"+this.toQueryString(k),"Spotify","menubar=no,location=no,resizable=yes,scrollbars=yes,status=no,width="+d+",height="+f+",top="+j+",left="+h,function(){l||b.reject()});return g.addEventListener("storage",a,!1),b.promise}},new h}]})}(window,angular); \ No newline at end of file diff --git a/examples/main.controller.js b/examples/main.controller.js index 1a7202d..7338273 100644 --- a/examples/main.controller.js +++ b/examples/main.controller.js @@ -80,7 +80,7 @@ angular console.log(data); }); - Spotify.getRelatedArtists('0LcJLqbBmaGUft1e9Mm8HV').then(function (data) { + Spotify.getArtistRelatedArtists('0LcJLqbBmaGUft1e9Mm8HV').then(function (data) { console.log('=================== Get Releated Artists ==================='); console.log(data); }); diff --git a/package.json b/package.json index cbb78cf..03b8784 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-spotify", - "version": "1.4.2", + "version": "1.4.0", "description": "Angular Service to connect to Spotify Web API", "main": "src/angular-spotify.js", "devDependencies": { diff --git a/src/angular-spotify.js b/src/angular-spotify.js index 62ef384..39a8b73 100644 --- a/src/angular-spotify.js +++ b/src/angular-spotify.js @@ -1,34 +1,44 @@ -(function (window, angular, undefined) { +(function (window, angular) { 'use strict'; + function getSpotifyId (s) { + return s.indexOf('spotify:') === -1 ? s : s.split(':')[2]; + } + + function stringToArray (s) { + if (!s) { return; } + var arr = angular.isString(s) ? s.split(',') : s; + return arr.map(function (value) { + return getSpotifyId(value); + }); + } + angular .module('spotify', []) .provider('Spotify', function () { // Module global settings. - var settings = {}; - settings.clientId = null; - settings.redirectUri = null; - settings.scope = null; - settings.authToken = null; + var settings = { + clientId: null, + redirectUri: null, + scope: null, + accessToken: null + }; this.setClientId = function (clientId) { - settings.clientId = clientId; - return settings.clientId; + return settings.clientId = clientId; // jshint ignore:line }; this.getClientId = function () { return settings.clientId; }; - this.setAuthToken = function (authToken) { - settings.authToken = authToken; - return settings.authToken; + this.setAccessToken = function (accessToken) { + return settings.accessToken = accessToken; // jshint ignore:line }; this.setRedirectUri = function (redirectUri) { - settings.redirectUri = redirectUri; - return settings.redirectUri; + return settings.redirectUri = redirectUri; // jshint ignore:line }; this.getRedirectUri = function () { @@ -36,8 +46,7 @@ }; this.setScope = function (scope) { - settings.scope = scope; - return settings.scope; + return settings.scope = scope; // jshint ignore:line }; var utils = {}; @@ -61,7 +70,7 @@ this.redirectUri = settings.redirectUri; this.apiBase = settings.apiBase; this.scope = settings.scope; - this.authToken = settings.authToken; + this.accessToken = settings.accessToken; this.toQueryString = utils.toQueryString; } @@ -71,23 +80,31 @@ try { if (!win || win.closed) { window.clearInterval(interval); - cb(win); + return cb(win); } - } catch (e) {} + } catch (e) { + console.error(e); + } }, 1000); return win; } NgSpotify.prototype = { - api: function (endpoint, method, params, data, headers) { + api: function (endpoint, options) { var deferred = $q.defer(); + options = options || {}; + options.method = options.method || 'GET'; + options.headers = options.headers || {}; + if (this.accessToken) { + options.headers.Authorization = 'Bearer ' + this.accessToken; + } $http({ url: this.apiBase + endpoint, - method: method ? method : 'GET', - params: params, - data: data, - headers: headers, + method: options.method, + params: options.params, + data: options.data, + headers: options.headers, withCredentials: false }) .success(function (data) { @@ -99,16 +116,6 @@ return deferred.promise; }, - _auth: function (isJson) { - var auth = { - 'Authorization': 'Bearer ' + this.authToken - }; - if (isJson) { - auth['Content-Type'] = 'application/json'; - } - return auth; - }, - /** ====================== Albums ===================== */ @@ -118,9 +125,8 @@ * Pass in album id or spotify uri */ getAlbum: function (album) { - album = album.indexOf('spotify:') === -1 ? album : album.split(':')[2]; - - return this.api('/albums/' + album); + var a = getSpotifyId(album); + return this.api('/albums/' + a); }, /** @@ -128,12 +134,11 @@ * Pass in comma separated string or array of album ids */ getAlbums: function (albums) { - albums = angular.isString(albums) ? albums.split(',') : albums; - angular.forEach(albums, function (value, index) { - albums[index] = value.indexOf('spotify:') > -1 ? value.split(':')[2] : value; - }); - return this.api('/albums', 'GET', { - ids: albums ? albums.toString() : '' + var a = stringToArray(albums); + return this.api('/albums', { + params: { + ids: a ? a.toString() : '' + } }); }, @@ -142,9 +147,9 @@ * Pass in album id or spotify uri */ getAlbumTracks: function (album, options) { - album = album.indexOf('spotify:') === -1 ? album : album.split(':')[2]; - - return this.api('/albums/' + album + '/tracks', 'GET', options); + var a = getSpotifyId(album); + var o = options && { params: options }; + return this.api('/albums/' + a + '/tracks', o); }, @@ -156,29 +161,27 @@ * Get an Artist */ getArtist: function (artist) { - artist = artist.indexOf('spotify:') === -1 ? artist : artist.split(':')[2]; - - return this.api('/artists/' + artist); + var a = getSpotifyId(artist); + return this.api('/artists/' + a); }, /** * Get multiple artists */ getArtists: function (artists) { - artists = angular.isString(artists) ? artists.split(',') : artists; - angular.forEach(artists, function (value, index) { - artists[index] = value.indexOf('spotify:') > -1 ? value.split(':')[2] : value; - }); - return this.api('/artists/', 'GET', { - ids: artists ? artists.toString() : '' + var a = stringToArray(artists); + return this.api('/artists/', { + params: { + ids: a ? a.toString() : '' + } }); }, //Artist Albums getArtistAlbums: function (artist, options) { - artist = artist.indexOf('spotify:') === -1 ? artist : artist.split(':')[2]; - - return this.api('/artists/' + artist + '/albums', 'GET', options); + var a = getSpotifyId(artist); + var o = options && { params: options }; + return this.api('/artists/' + a + '/albums', o); }, /** @@ -186,17 +189,17 @@ * The country: an ISO 3166-1 alpha-2 country code. */ getArtistTopTracks: function (artist, country) { - artist = artist.indexOf('spotify:') === -1 ? artist : artist.split(':')[2]; - - return this.api('/artists/' + artist + '/top-tracks', 'GET', { - country: country + var a = getSpotifyId(artist); + return this.api('/artists/' + a + '/top-tracks', { + params: { + country: country + } }); }, - getRelatedArtists: function (artist) { - artist = artist.indexOf('spotify:') === -1 ? artist : artist.split(':')[2]; - - return this.api('/artists/' + artist + '/related-artists'); + getArtistRelatedArtists: function (artist) { + var a = getSpotifyId(artist); + return this.api('/artists/' + a + '/related-artists'); }, @@ -204,155 +207,233 @@ ====================== Browse ===================== */ getFeaturedPlaylists: function (options) { - return this.api('/browse/featured-playlists', 'GET', options, null, this._auth()); + return this.api('/browse/featured-playlists', { + params: options + }); }, getNewReleases: function (options) { - return this.api('/browse/new-releases', 'GET', options, null, this._auth()); + return this.api('/browse/new-releases', { + params: options + }); }, getCategories: function (options) { - return this.api('/browse/categories', 'GET', options, null, this._auth()); + var o = {}; + if (options) { o.params = options; } + return this.api('/browse/categories', o); }, getCategory: function (category_id, options) { - return this.api('/browse/categories/' + category_id, 'GET', options, null, this._auth()); + var o = {}; + if (options) { o.params = options; } + return this.api('/browse/categories/' + category_id, o); }, getCategoryPlaylists: function (category_id, options) { - return this.api('/browse/categories/' + category_id + '/playlists', 'GET', options, null, this._auth()); + var o = {}; + if (options) { o.params = options; } + return this.api('/browse/categories/' + category_id + '/playlists', o); }, getRecommendations: function (options) { - return this.api('/recommendations', 'GET', options, null, this._auth()); + return this.api('/recommendations', { + params: options + }); }, getAvailableGenreSeeds: function () { - return this.api('/recommendations/available-genre-seeds', 'GET', null, null, this._auth()); + return this.api('/recommendations/available-genre-seeds'); }, /** ====================== Following ===================== */ - following: function (type, options) { - options = options || {}; - options.type = type; - return this.api('/me/following', 'GET', options, null, this._auth()); + getFollowed: function (type, options) { + var params = options || {}; + params.type = type; + return this.api('/me/following', { + params: params + }); }, follow: function (type, ids) { - return this.api('/me/following', 'PUT', { type: type, ids: ids }, null, this._auth()); + var arr = stringToArray(ids); + return this.api('/me/following', { + method: 'PUT', + params: { + type: type, + ids: arr.join(',') + } + }); + }, + + followUsers: function (ids) { + return this.follow('user', ids); + }, + + followArtists: function (ids) { + return this.follow('artist', ids); }, unfollow: function (type, ids) { - return this.api('/me/following', 'DELETE', { type: type, ids: ids }, null, this._auth()); + var arr = stringToArray(ids); + return this.api('/me/following', { + method: 'DELETE', + params: { + type: type, + ids: arr.join(',') + } + }); + }, + + unfollowUsers: function (ids) { + return this.unfollow('user', ids); + }, + + unfollowArtists: function (ids) { + return this.unfollow('artist', ids); + }, + + isFollowing: function (type, ids) { + var arr = stringToArray(ids); + return this.api('/me/following/contains', { + params: { + type: type, + ids: arr.join(',') + } + }); + }, + + isFollowingUsers: function (ids) { + return this.isFollowing('user', ids); }, - userFollowingContains: function (type, ids) { - return this.api('/me/following/contains', 'GET', { type: type, ids: ids }, null, this._auth()); + isFollowingArtists: function (ids) { + return this.isFollowing('artist', ids); }, followPlaylist: function (userId, playlistId, isPublic) { - return this.api('/users/' + userId + '/playlists/' + playlistId + '/followers', 'PUT', null, { - public: isPublic || null - }, this._auth(true)); + return this.api('/users/' + userId + '/playlists/' + playlistId + '/followers', { + method: 'PUT', + data: { + public: isPublic || null + }, + headers: { + 'Content-Type': 'application/json' + } + }); }, unfollowPlaylist: function (userId, playlistId) { - return this.api('/users/' + userId + '/playlists/' + playlistId + '/followers', 'DELETE', null, null, this._auth()); + return this.api('/users/' + userId + '/playlists/' + playlistId + '/followers', { + method: 'DELETE' + }); }, - playlistFollowingContains: function(userId, playlistId, ids) { - return this.api('/users/' + userId + '/playlists/' + playlistId + '/followers/contains', 'GET', { - ids: ids.toString() - }, null, this._auth()); + areFollowingPlaylist: function(userId, playlistId, ids) { + return this.api('/users/' + userId + '/playlists/' + playlistId + '/followers/contains', { + params: { + ids: ids.toString() + } + }); }, /** ====================== Library ===================== */ - getSavedUserTracks: function (options) { - return this.api('/me/tracks', 'GET', options, null, this._auth()); + getMySavedTracks: function (options) { + var o = {}; + if (options) { o.params = options; } + return this.api('/me/tracks', o); }, - userTracksContains: function (tracks) { - tracks = angular.isString(tracks) ? tracks.split(',') : tracks; - angular.forEach(tracks, function (value, index) { - tracks[index] = value.indexOf('spotify:') > -1 ? value.split(':')[2] : value; + containsMySavedTracks: function (tracks) { + var trks = stringToArray(tracks); + return this.api('/me/tracks/contains', { + params: { + ids: trks.toString() + } }); - return this.api('/me/tracks/contains', 'GET', { - ids: tracks.toString() - }, null, this._auth()); }, - saveUserTracks: function (tracks) { - tracks = angular.isString(tracks) ? tracks.split(',') : tracks; - angular.forEach(tracks, function (value, index) { - tracks[index] = value.indexOf('spotify:') > -1 ? value.split(':')[2] : value; + addToMySavedTracks: function (tracks) { + var trks = stringToArray(tracks); + return this.api('/me/tracks', { + method: 'PUT', + params: { + ids: trks.toString() + } }); - return this.api('/me/tracks', 'PUT', { - ids: tracks.toString() - }, null, this._auth()); }, - removeUserTracks: function (tracks) { - tracks = angular.isString(tracks) ? tracks.split(',') : tracks; - angular.forEach(tracks, function (value, index) { - tracks[index] = value.indexOf('spotify:') > -1 ? value.split(':')[2] : value; + removeFromMySavedTracks: function (tracks) { + var trks = stringToArray(tracks); + return this.api('/me/tracks', { + method: 'DELETE', + params: { + ids: trks.toString() + }, + headers: { + 'Content-Type': 'application/json' + } }); - return this.api('/me/tracks', 'DELETE', { - ids: tracks.toString() - }, null, this._auth(true)); }, - saveUserAlbums: function (albums) { - albums = angular.isString(albums) ? albums.split(',') : albums; - angular.forEach(albums, function (value, index) { - albums[index] = value.indexOf('spotify:') > -1 ? value.split(':')[2] : value; + addToMySavedAlbums: function (albums) { + var albs = stringToArray(albums); + return this.api('/me/albums', { + method: 'PUT', + params: { + ids: albs.toString() + } }); - return this.api('/me/albums', 'PUT', { - ids: albums.toString() - }, null, this._auth()); }, - getSavedUserAlbums: function (options) { - return this.api('/me/albums', 'GET', options, null, this._auth()); + getMySavedAlbums: function (options) { + var o = {}; + if (options) { o.params = options; } + return this.api('/me/albums', o); }, - removeUserAlbums: function (albums) { - albums = angular.isString(albums) ? albums.split(',') : albums; - angular.forEach(albums, function (value, index) { - albums[index] = value.indexOf('spotify:') > -1 ? value.split(':')[2] : value; + removeFromMySavedAlbums: function (albums) { + var albs = stringToArray(albums); + return this.api('/me/albums', { + method: 'DELETE', + params: { + ids: albs.toString() + }, + headers: { + 'Content-Type': 'application/json' + } }); - return this.api('/me/albums', 'DELETE', { - ids: albums.toString() - }, null, this._auth(true)); }, - userAlbumsContains: function (albums) { - albums = angular.isString(albums) ? albums.split(',') : albums; - angular.forEach(albums, function (value, index) { - albums[index] = value.indexOf('spotify:') > -1 ? value.split(':')[2] : value; + containsMySavedAlbums: function (albums) { + var albs = stringToArray(albums); + return this.api('/me/albums/contains', { + params: { + ids: albs.toString() + } }); - return this.api('/me/albums/contains', 'GET', { - ids: albums.toString() - }, null, this._auth()); }, /** ====================== Personalization ===================== */ - getUserTopArtists: function (options) { - options = options || {}; - return this.api('/me/top/artists', 'GET', options, null, this._auth()); + getMyTopArtists: function (options) { + var o = {}; + if (options) { o.params = options; } + return this.api('/me/top/artists', o); }, - getUserTopTracks: function (options) { - options = options || {}; - return this.api('/me/top/tracks', 'GET', options, null, this._auth()); + getMyTopTracks: function (options) { + var o = {}; + if (options) { o.params = options; } + return this.api('/me/top/tracks', o); }, @@ -360,66 +441,117 @@ ====================== Playlists ===================== */ getUserPlaylists: function (userId, options) { - return this.api('/users/' + userId + '/playlists', 'GET', options, null, { - 'Authorization': 'Bearer ' + this.authToken - }); + var o = {}; + if (options) { o.params = options; } + return this.api('/users/' + userId + '/playlists', o); }, getPlaylist: function (userId, playlistId, options) { - return this.api('/users/' + userId + '/playlists/' + playlistId, 'GET', options, null, this._auth()); + var o = {}; + if (options) { o.params = options; } + return this.api('/users/' + userId + '/playlists/' + playlistId, o); }, getPlaylistTracks: function (userId, playlistId, options) { - return this.api('/users/' + userId + '/playlists/' + playlistId + '/tracks', 'GET', options, null, this._auth()); + var o = {}; + if (options) { o.params = options; } + return this.api('/users/' + userId + '/playlists/' + playlistId + '/tracks', o); }, createPlaylist: function (userId, options) { - return this.api('/users/' + userId + '/playlists', 'POST', null, options, this._auth(true)); + return this.api('/users/' + userId + '/playlists', { + method: 'POST', + data: options, + headers: { + 'Content-Type': 'application/json' + } + }); }, - addPlaylistTracks: function (userId, playlistId, tracks, options) { - tracks = angular.isArray(tracks) ? tracks : tracks.split(','); - angular.forEach(tracks, function (value, index) { - tracks[index] = value.indexOf('spotify:') === -1 ? 'spotify:track:' + value : value; + addTracksToPlaylist: function (userId, playlistId, tracks, options) { + var arr = stringToArray(tracks); + var trks = arr.map(function (value) { + return value.indexOf('spotify:') === -1 ? 'spotify:track:' + value : value; + }); + return this.api('/users/' + userId + '/playlists/' + playlistId + '/tracks', { + method: 'POST', + params: { + uris: trks.toString(), + position: options ? options.position : null + }, + headers: { + 'Content-Type': 'application/json' + } }); - return this.api('/users/' + userId + '/playlists/' + playlistId + '/tracks', 'POST', { - uris: tracks.toString(), - position: options ? options.position : null - }, null, this._auth(true)); }, - removePlaylistTracks: function (userId, playlistId, tracks) { - tracks = angular.isArray(tracks) ? tracks : tracks.split(','); - var track; - angular.forEach(tracks, function (value, index) { - track = tracks[index]; - tracks[index] = { - uri: track.indexOf('spotify:') === -1 ? 'spotify:track:' + track : track - }; + removeTracksFromPlaylist: function (userId, playlistId, tracks, options) { + var data = options || {}; + if (tracks) { + var arr = stringToArray(tracks); + var trks = arr.map(function (track) { + return { + uri: track.indexOf('spotify:') === -1 ? 'spotify:track:' + track : track + }; + }); + data.tracks = trks; + } + return this.api('/users/' + userId + '/playlists/' + playlistId + '/tracks', { + method: 'DELETE', + data: data, + headers: { + 'Content-Type': 'application/json' + } }); - return this.api('/users/' + userId + '/playlists/' + playlistId + '/tracks', 'DELETE', null, { - tracks: tracks - }, this._auth(true)); }, - reorderPlaylistTracks: function (userId, playlistId, options) { - return this.api('/users/' + userId + '/playlists/' + playlistId + '/tracks', 'PUT', null, options, this._auth(true)); + removeTracksFromPlaylistWithSnapshotId: function (userId, playlistId, tracks, snapshotId) { + return this.removeTracksFromPlaylist(userId, playlistId, tracks, { + snapshot_id: snapshotId + }); }, - replacePlaylistTracks: function (userId, playlistId, tracks) { - tracks = angular.isArray(tracks) ? tracks : tracks.split(','); - var track; - angular.forEach(tracks, function (value, index) { - track = tracks[index]; - tracks[index] = track.indexOf('spotify:') === -1 ? 'spotify:track:' + track : track; + removeTracksFromPlaylistInPositions: function (userId, playlistId, positions, snapshotId) { + return this.removeTracksFromPlaylist(userId, playlistId, null, { + positions: positions, + snapshot_id: snapshotId }); - return this.api('/users/' + userId + '/playlists/' + playlistId + '/tracks', 'PUT', { - uris: tracks.toString() - }, null, this._auth(true)); }, - updatePlaylistDetails: function (userId, playlistId, options) { - return this.api('/users/' + userId + '/playlists/' + playlistId, 'PUT', null, options, this._auth(true)); + reorderTracksInPlaylist: function (userId, playlistId, options) { + return this.api('/users/' + userId + '/playlists/' + playlistId + '/tracks', { + method: 'PUT', + data: options, + headers: { + 'Content-Type': 'application/json' + } + }); + }, + + replaceTracksInPlaylist: function (userId, playlistId, tracks) { + var arr = tracks = stringToArray(tracks); + var trks = arr.map(function (track) { + return track.indexOf('spotify:') === -1 ? 'spotify:track:' + track : track; + }); + return this.api('/users/' + userId + '/playlists/' + playlistId + '/tracks', { + method: 'PUT', + params: { + uris: trks.toString() + }, + headers: { + 'Content-Type': 'application/json' + } + }); + }, + + changePlaylistDetails: function (userId, playlistId, options) { + return this.api('/users/' + userId + '/playlists/' + playlistId, { + method: 'PUT', + data: options, + headers: { + 'Content-Type': 'application/json' + } + }); }, /** @@ -430,8 +562,8 @@ return this.api('/users/' + userId); }, - getCurrentUser: function () { - return this.api('/me', 'GET', null, null, this._auth()); + getMe: function () { + return this.api('/me'); }, @@ -441,12 +573,30 @@ * q = search query * type = artist, album or track */ - search: function (q, type, options) { - options = options || {}; - options.q = q; - options.type = type; + search: function (q, types, options) { + var params = options || {}; + params.q = q; + params.type = angular.isArray(types) ? types.join(',') : types; + + return this.api('/search', { + params: params + }); + }, - return this.api('/search', 'GET', options); + searchAlbums: function (q, options) { + return this.search(q, 'album', options); + }, + + searchArtists: function (q, options) { + return this.search(q, 'artist', options); + }, + + searchTracks: function (q, options) { + return this.search(q, 'track', options); + }, + + searchPlaylists: function (q, options) { + return this.search(q, 'playlist', options); }, @@ -454,53 +604,54 @@ ====================== Tracks ===================== */ getTrack: function (track) { - track = track.indexOf('spotify:') === -1 ? track : track.split(':')[2]; - - return this.api('/tracks/' + track); + var t = getSpotifyId(track); + return this.api('/tracks/' + t); }, getTracks: function (tracks) { - tracks = angular.isString(tracks) ? tracks.split(',') : tracks; - angular.forEach(tracks, function (value, index) { - tracks[index] = value.indexOf('spotify:') > -1 ? value.split(':')[2] : value; - }); - return this.api('/tracks/', 'GET', { - ids: tracks ? tracks.toString() : '' + var trks = stringToArray(tracks); + return this.api('/tracks/', { + params: { + ids: trks ? trks.toString() : '' + } }); }, - getTrackAudioFeatures: function (track) { - track = track.indexOf('spotify:') === -1 ? track : track.split(':')[2]; - return this.api('/audio-features/' + track, 'GET', null, null, this._auth()); + getAudioFeaturesForTrack: function (track) { + var t = getSpotifyId(track); + return this.api('/audio-features/' + t); }, - getTracksAudioFeatures: function (tracks) { - tracks = angular.isString(tracks) ? tracks.split(',') : tracks; - angular.forEach(tracks, function (value, index) { - tracks[index] = value.indexOf('spotify:') > -1 ? value.split(':')[2] : value; + getAudioFeaturesForTracks: function (tracks) { + var trks = stringToArray(tracks); + return this.api('/audio-features/', { + params: { + ids: trks ? trks.toString() : '' + } }); - return this.api('/audio-features/', 'GET', { - ids: tracks ? tracks.toString() : '' - }, null, this._auth()); }, /** ====================== Login ===================== */ - setAuthToken: function (authToken) { - this.authToken = authToken; - return this.authToken; + setAccessToken: function (accessToken) { + this.accessToken = accessToken; + return this.accessToken; + }, + + getAccessToken: function () { + return this.accessToken; }, login: function () { var deferred = $q.defer(); var that = this; - var w = 400, - h = 500, - left = (screen.width / 2) - (w / 2), - top = (screen.height / 2) - (h / 2); + var w = 400; + var h = 500; + var left = (screen.width / 2) - (w / 2); + var top = (screen.height / 2) - (h / 2); var params = { client_id: this.clientId, @@ -526,7 +677,7 @@ if (authWindow) { authWindow.close(); } authCompleted = true; - that.setAuthToken(e.newValue); + that.setAccessToken(e.newValue); $window.removeEventListener('storage', storageChanged, false); deferred.resolve(e.newValue); diff --git a/test/spec/angular-spotify.spec.js b/test/spec/angular-spotify.spec.js index e4f45e6..aa4be35 100644 --- a/test/spec/angular-spotify.spec.js +++ b/test/spec/angular-spotify.spec.js @@ -14,38 +14,6 @@ describe('angular-spotify', function () { inject(function () {}); }); - it('should be defined', function () { - expect(spotifyProvider).toBeDefined(); - }); - - it('should have a method setClientId()', function () { - expect(spotifyProvider.setClientId).toBeDefined(); - }); - - it('should have a method getClientId()', function () { - expect(spotifyProvider.getClientId).toBeDefined(); - }); - - it('should have a method setRedirectUri()', function () { - expect(spotifyProvider.setRedirectUri).toBeDefined(); - }); - - it('should have a method getRedirectUri()', function () { - expect(spotifyProvider.getRedirectUri).toBeDefined(); - }); - - it('should have a method setScope()', function () { - expect(spotifyProvider.setScope).toBeDefined(); - }); - - it('should have a method setScope()', function () { - expect(spotifyProvider.setScope).toBeDefined(); - }); - - it('should have a method setAuthToken', function () { - expect(spotifyProvider.setAuthToken).toBeDefined(); - }); - it('should set the client id', function () { expect(spotifyProvider.setClientId('ABCDEFGHIJKLMNOP')).toBe('ABCDEFGHIJKLMNOP'); }); @@ -69,7 +37,7 @@ describe('angular-spotify', function () { }); it('should set the authToken', function () { - expect(spotifyProvider.setAuthToken('ABCDEFGHIJKLMNOP')).toBe('ABCDEFGHIJKLMNOP'); + expect(spotifyProvider.setAccessToken('ABCDEFGHIJKLMNOP')).toBe('ABCDEFGHIJKLMNOP'); }); }); @@ -85,187 +53,23 @@ describe('angular-spotify', function () { Spotify = _Spotify_; })); - it('should be defined', function () { - expect(Spotify).toBeDefined(); - }); - it('should be an object', function () { expect(typeof Spotify).toBe('object'); }); - it('should have a method api()', function () { - expect(Spotify.api).toBeDefined(); - }); - - it('should have a method search()', function () { - expect(Spotify.search).toBeDefined(); - }); - - it('should have a method getAlbum()', function () { - expect(Spotify.getAlbum).toBeDefined(); - }); - - it('should have a method getAlbums()', function () { - expect(Spotify.getAlbums).toBeDefined(); - }); - - it('should have a method getAlbumTracks()', function () { - expect(Spotify.getAlbumTracks).toBeDefined(); - }); - - it('should have a method getArtist()', function () { - expect(Spotify.getArtist).toBeDefined(); - }); - - it('should have a method getArtists()', function () { - expect(Spotify.getArtists).toBeDefined(); - }); - - it('should have a method getArtistAlbums()', function () { - expect(Spotify.getArtistAlbums).toBeDefined(); - }); - - it('should have a method getArtistTopTracks()', function () { - expect(Spotify.getArtistTopTracks).toBeDefined(); - }); - - it('should have a method getRelatedArtists()', function () { - expect(Spotify.getRelatedArtists).toBeDefined(); - }); - - it('should have a method getTrack()', function () { - expect(Spotify.getTrack).toBeDefined(); - }); - - it('should have a method getTracks()', function () { - expect(Spotify.getTracks).toBeDefined(); - }); - - it('should have a method getUserPlaylists()', function () { - expect(Spotify.getUserPlaylists).toBeDefined(); - }); - - it('should have a method getPlaylist()', function () { - expect(Spotify.getPlaylist).toBeDefined(); - }); - - it('should have a method getPlaylistTracks()', function () { - expect(Spotify.getPlaylistTracks).toBeDefined(); - }); - - it('should have a method createPlaylist()', function () { - expect(Spotify.createPlaylist).toBeDefined(); - }); - - it('should have a method addPlaylistTracks()', function () { - expect(Spotify.addPlaylistTracks).toBeDefined(); - }); - - it('should have a method removePlaylistTracks()', function () { - expect(Spotify.removePlaylistTracks).toBeDefined(); - }); - - it('should have a method reorderPlaylistTracks()', function () { - expect(Spotify.reorderPlaylistTracks).toBeDefined(); - }); - - it('should have a method replacePlaylistTracks()', function () { - expect(Spotify.replacePlaylistTracks).toBeDefined(); - }); - - it('should have a method updatePlaylistDetails()', function () { - expect(Spotify.updatePlaylistDetails).toBeDefined(); - }); - - it('should have a method getUser()', function () { - expect(Spotify.getUser).toBeDefined(); - }); - - it('should have a method getCurrentUser()', function () { - expect(Spotify.getCurrentUser).toBeDefined(); - }); - - it('should have a method getSavedUserTracks()', function () { - expect(Spotify.getSavedUserTracks).toBeDefined(); - }); - - it('should have a method userTracksContains()', function () { - expect(Spotify.userTracksContains).toBeDefined(); - }); - - it('should have a method saveUserTracks()', function () { - expect(Spotify.saveUserTracks).toBeDefined(); - }); - - it('should have a method removeUserTracks()', function () { - expect(Spotify.removeUserTracks).toBeDefined(); - }); - - it('should have a method setAuthToken()', function () { - expect(Spotify.setAuthToken).toBeDefined(); - }); - - it('should have a method login()', function () { - expect(Spotify.login).toBeDefined(); - }); - it('should set the AuthToken', function () { - expect(Spotify.setAuthToken('ABCDEFGHIJKLMNOP')).toBe('ABCDEFGHIJKLMNOP'); - }); - - it('should turn an object into a query string', function () { - expect(Spotify.toQueryString({a: 't', b: 4, c: 'q'})).toBe('a=t&b=4&c=q'); + expect(Spotify.setAccessToken('ABCDEFGHIJKLMNOP')).toBe('ABCDEFGHIJKLMNOP'); }); - it('should have a method getFeaturedPlaylists()', function () { - expect(Spotify.getFeaturedPlaylists).toBeDefined(); + it('should get the AuthToken', function () { + Spotify.setAccessToken('ABCDEFGHIJKLMNOP'); + expect(Spotify.getAccessToken()).toBe('ABCDEFGHIJKLMNOP'); }); - it('should have a method getNewReleases()', function () { - expect(Spotify.getNewReleases).toBeDefined(); - }); - - it('should have a method following()', function () { - expect(Spotify.following).toBeDefined(); - }); - - it('should have a method follow()', function () { - expect(Spotify.follow).toBeDefined(); - }); - - it('should have a method unfollow()', function () { - expect(Spotify.unfollow).toBeDefined(); - }); - - it('should have a method userFollowingContains()', function () { - expect(Spotify.userFollowingContains).toBeDefined(); - }); - - it('should have a method followPlaylist()', function () { - expect(Spotify.followPlaylist).toBeDefined(); - }); - - it('should have a method unfollowPlaylist()', function () { - expect(Spotify.unfollowPlaylist).toBeDefined(); - }); - - it('should have a method playlistFollowingContains()', function () { - expect(Spotify.playlistFollowingContains).toBeDefined(); - }); - - it('should have a method getCategories()', function () { - expect(Spotify.getCategories).toBeDefined(); - }); - - it('should have a method getCategory()', function () { - expect(Spotify.getCategory).toBeDefined(); - }); - - it('should have a method getCategoryPlaylists()', function () { - expect(Spotify.getCategoryPlaylists).toBeDefined(); + it('should turn an object into a query string', function () { + expect(Spotify.toQueryString({ a: 't', b: 4, c: 'q' })).toBe('a=t&b=4&c=q'); }); - describe('Spotify.api', function () { var $httpBackend; var Spotify; @@ -274,7 +78,7 @@ describe('angular-spotify', function () { beforeEach(inject(function(_Spotify_, _$httpBackend_) { Spotify = _Spotify_; $httpBackend = _$httpBackend_; - jasmine.getJSONFixtures().fixturesPath='base/test/mock'; + jasmine.getJSONFixtures().fixturesPath = 'base/test/mock'; })); afterEach(function(){ @@ -288,9 +92,11 @@ describe('angular-spotify', function () { ); var result; - Spotify.api('/search', 'GET', { - q: 'Nirvana', - type: 'artist' + Spotify.api('/search', { + params: { + q: 'Nirvana', + type: 'artist' + } }).then(function (data) { result = data; }); @@ -307,9 +113,12 @@ describe('angular-spotify', function () { }).respond({}); var result; - Spotify.api('/users/wizzler/playlists', 'POST', null, { - name: 'TESTING', - public: false + Spotify.api('/users/wizzler/playlists', { + method: 'POST', + data: { + name: 'TESTING', + public: false + } }).then(function (data) { result = data; }); @@ -328,11 +137,13 @@ describe('angular-spotify', function () { }).respond({}); var result; - Spotify.api('/users/wizzler/playlists', 'POST', null, { - name: 'TESTING', - public: false - }, { - 'Authorization': 'Bearer TESTING' + Spotify.setAccessToken('TESTING'); + Spotify.api('/users/wizzler/playlists', { + method: 'POST', + data: { + name: 'TESTING', + public: false + } }).then(function (data) { result = data; }); @@ -343,8 +154,7 @@ describe('angular-spotify', function () { }); }); - describe('Spotify.search', function () { - + describe('Search', function () { var $httpBackend; var $rootScope; var Spotify; @@ -357,44 +167,178 @@ describe('angular-spotify', function () { jasmine.getJSONFixtures().fixturesPath='base/test/mock'; })); - it('should make an ajax call to https://api.spotify.com/v1/search', function () { + describe('Spotify.search', function () { + it('should make an ajax call to https://api.spotify.com/v1/search', function () { + + spyOn(Spotify, 'api'); + + Spotify.search('Nirvana', 'artist'); + + expect(Spotify.api).toHaveBeenCalledWith('/search', { + params: { + q: 'Nirvana', + type: 'artist' + } + }); + }); - spyOn(Spotify, 'api'); + it('should call with multiple types', function () { - Spotify.search('Nirvana', 'artist'); + spyOn(Spotify, 'api'); - expect(Spotify.api).toHaveBeenCalledWith('/search', 'GET', { - q: 'Nirvana', - type: 'artist' + Spotify.search('Muse', ['artist', 'track']); + + expect(Spotify.api).toHaveBeenCalledWith('/search', { + params: { + q: 'Muse', + type: 'artist,track' + } + }); + }); + + it('should return an array of artists', function () { + $httpBackend.when('GET', api + '/search?q=Nirvana&type=artist').respond( + getJSONFixture('search.artist.json') + ); + + Spotify.search('Nirvana', 'artist').then(function (data) { + expect(data).toBeDefined(); + expect(data.artists.items.length).toBe(20); + }); + + $httpBackend.flush(); + }); + + it('should reject the promise and respond with error', function () { + $httpBackend.when('GET', api + '/search?q=Nirvana').respond(400, getJSONFixture('search.missing-type.json')); + + var result; + Spotify.search('Nirvana').then(function () { + }, function (reason) { + result = reason; + }); + + $httpBackend.flush(); + expect(result).toBeDefined(); + expect(result instanceof Object).toBeTruthy(); + expect(result.error.status).toBe(400); }); }); - it('should return an array of artists', function () { - $httpBackend.when('GET', api + '/search?q=Nirvana&type=artist').respond( - getJSONFixture('search.artist.json') - ); + describe('Spotify.searchAlbums', function () { + it('should call the api with the correct params', function () { + spyOn(Spotify, 'api'); - Spotify.search('Nirvana', 'artist').then(function (data) { - expect(data).toBeDefined(); - expect(data.artists.items.length).toBe(20); + Spotify.searchAlbums('Nevermind'); + + expect(Spotify.api).toHaveBeenCalledWith('/search', { + params: { + q: 'Nevermind', + type: 'album' + } + }); }); - $httpBackend.flush(); + it('should search with options', function () { + spyOn(Spotify, 'api'); + + Spotify.searchAlbums('Nevermind', { limit: 10 }); + + expect(Spotify.api).toHaveBeenCalledWith('/search', { + params: { + q: 'Nevermind', + type: 'album', + limit: 10 + } + }); + }); }); - it('should reject the promise and respond with error', function () { - $httpBackend.when('GET', api + '/search?q=Nirvana').respond(400, getJSONFixture('search.missing-type.json')); + describe('Spotify.searchArtists', function () { + it('should call the api with the correct params', function () { + spyOn(Spotify, 'api'); - var result; - Spotify.search('Nirvana').then(function () { - }, function (reason) { - result = reason; + Spotify.searchArtists('Nirvana'); + + expect(Spotify.api).toHaveBeenCalledWith('/search', { + params: { + q: 'Nirvana', + type: 'artist' + } + }); }); - $httpBackend.flush(); - expect(result).toBeDefined(); - expect(result instanceof Object).toBeTruthy(); - expect(result.error.status).toBe(400); + it('should search with options', function () { + spyOn(Spotify, 'api'); + + Spotify.searchArtists('Nirvana', { limit: 10 }); + + expect(Spotify.api).toHaveBeenCalledWith('/search', { + params: { + q: 'Nirvana', + type: 'artist', + limit: 10 + } + }); + }); + }); + + describe('Spotify.searchTracks', function () { + it('should call the api with the correct params', function () { + spyOn(Spotify, 'api'); + + Spotify.searchTracks('Smells Like Teen Spirit'); + + expect(Spotify.api).toHaveBeenCalledWith('/search', { + params: { + q: 'Smells Like Teen Spirit', + type: 'track' + } + }); + }); + + it('should search with options', function () { + spyOn(Spotify, 'api'); + + Spotify.searchTracks('Smells Like Teen Spirit', { limit: 10 }); + + expect(Spotify.api).toHaveBeenCalledWith('/search', { + params: { + q: 'Smells Like Teen Spirit', + type: 'track', + limit: 10 + } + }); + }); + }); + + describe('Spotify.searchPlaylists', function () { + it('should call the api with the correct params', function () { + spyOn(Spotify, 'api'); + + Spotify.searchPlaylists('#ThrowbackThursday'); + + expect(Spotify.api).toHaveBeenCalledWith('/search', { + params: { + q: '#ThrowbackThursday', + type: 'playlist' + } + }); + }); + + it('should search with options', function () { + spyOn(Spotify, 'api'); + + Spotify.searchPlaylists('#ThrowbackThursday', { limit: 10 }); + + expect(Spotify.api).toHaveBeenCalledWith('/search', { + params: { + q: '#ThrowbackThursday', + type: 'playlist', + limit: 10 + } + }); + }); }); }); @@ -491,8 +435,10 @@ describe('angular-spotify', function () { Spotify.getAlbums('spotify:album:41MnTivkwTO3UUJ8DrqEJJ,spotify:album:6JWc4iAiJ9FjyK0B59ABb4,spotify:album:6UXCm6bOO4gFlDQZV5yL37'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/albums', 'GET', { - ids: '41MnTivkwTO3UUJ8DrqEJJ,6JWc4iAiJ9FjyK0B59ABb4,6UXCm6bOO4gFlDQZV5yL37' + expect(Spotify.api).toHaveBeenCalledWith('/albums', { + params: { + ids: '41MnTivkwTO3UUJ8DrqEJJ,6JWc4iAiJ9FjyK0B59ABb4,6UXCm6bOO4gFlDQZV5yL37' + } }); }); @@ -543,7 +489,19 @@ describe('angular-spotify', function () { Spotify.getAlbumTracks('spotify:album:0sNOF9WDwhWunNAHPD3Baj'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/albums/0sNOF9WDwhWunNAHPD3Baj/tracks', 'GET', undefined); + expect(Spotify.api).toHaveBeenCalledWith('/albums/0sNOF9WDwhWunNAHPD3Baj/tracks', undefined); + }); + + it('should resolve with options', function () { + spyOn(Spotify, 'api'); + Spotify.getAlbumTracks('spotify:album:0sNOF9WDwhWunNAHPD3Baj', { limit: 20 }); + + expect(Spotify.api).toHaveBeenCalled(); + expect(Spotify.api).toHaveBeenCalledWith('/albums/0sNOF9WDwhWunNAHPD3Baj/tracks', { + params: { + limit: 20 + } + }); }); it('should resolve to an object of album tracks', function () { @@ -667,8 +625,10 @@ describe('angular-spotify', function () { Spotify.getArtists('spotify:artist:0oSGxfWSnnOXhD2fKuz2Gy,spotify:artist:3dBVyJ7JuOMt4GE9607Qin'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/artists/', 'GET', { - ids: '0oSGxfWSnnOXhD2fKuz2Gy,3dBVyJ7JuOMt4GE9607Qin' + expect(Spotify.api).toHaveBeenCalledWith('/artists/', { + params: { + ids: '0oSGxfWSnnOXhD2fKuz2Gy,3dBVyJ7JuOMt4GE9607Qin' + } }); }); @@ -705,7 +665,19 @@ describe('angular-spotify', function () { Spotify.getArtistAlbums('spotify:artist:0LcJLqbBmaGUft1e9Mm8HV'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/artists/0LcJLqbBmaGUft1e9Mm8HV/albums', 'GET', undefined); + expect(Spotify.api).toHaveBeenCalledWith('/artists/0LcJLqbBmaGUft1e9Mm8HV/albums', undefined); + }); + + it('should resolve with options', function () { + spyOn(Spotify, 'api'); + + Spotify.getArtistAlbums('spotify:artist:0LcJLqbBmaGUft1e9Mm8HV', { limit: 20 }); + expect(Spotify.api).toHaveBeenCalled(); + expect(Spotify.api).toHaveBeenCalledWith('/artists/0LcJLqbBmaGUft1e9Mm8HV/albums', { + params: { + limit: 20 + } + }); }); it('should resolve to an array of artist albums', function () { @@ -756,8 +728,10 @@ describe('angular-spotify', function () { Spotify.getArtistTopTracks('spotify:artist:0LcJLqbBmaGUft1e9Mm8HV', 'AU'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/artists/0LcJLqbBmaGUft1e9Mm8HV/top-tracks', 'GET', { - country: 'AU' + expect(Spotify.api).toHaveBeenCalledWith('/artists/0LcJLqbBmaGUft1e9Mm8HV/top-tracks', { + params: { + country: 'AU' + } }); }); @@ -821,15 +795,15 @@ describe('angular-spotify', function () { }); }); - describe('Spotify.getRelatedArtists', function() { + describe('Spotify.getArtistRelatedArtists', function() { it('should make an ajax call to https://api.spotify.com/v1/artists/{id}/related-artists', function () { - expect(Spotify.getRelatedArtists('0LcJLqbBmaGUft1e9Mm8HV')).toBeDefined(); + expect(Spotify.getArtistRelatedArtists('0LcJLqbBmaGUft1e9Mm8HV')).toBeDefined(); }); it('should convert spotify uri to just an id', function () { spyOn(Spotify, 'api'); - Spotify.getRelatedArtists('spotify:artist:0LcJLqbBmaGUft1e9Mm8HV'); + Spotify.getArtistRelatedArtists('spotify:artist:0LcJLqbBmaGUft1e9Mm8HV'); expect(Spotify.api).toHaveBeenCalled(); expect(Spotify.api).toHaveBeenCalledWith('/artists/0LcJLqbBmaGUft1e9Mm8HV/related-artists'); @@ -840,7 +814,7 @@ describe('angular-spotify', function () { var result; Spotify - .getRelatedArtists('0LcJLqbBmaGUft1e9Mm8HV') + .getArtistRelatedArtists('0LcJLqbBmaGUft1e9Mm8HV') .then(function (data) { result = data; }); @@ -860,7 +834,7 @@ describe('angular-spotify', function () { var result; Spotify - .getRelatedArtists('ABCDEFGHIJKLMNOP') + .getArtistRelatedArtists('ABCDEFGHIJKLMNOP') .then(function () { }, function (reason) { result = reason; @@ -964,8 +938,10 @@ describe('angular-spotify', function () { Spotify.getTracks('spotify:track:0eGsygTp906u18L0Oimnem,spotify:track:1lDWb6b6ieDQ2xT7ewTC3G'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/tracks/', 'GET', { - ids: '0eGsygTp906u18L0Oimnem,1lDWb6b6ieDQ2xT7ewTC3G' + expect(Spotify.api).toHaveBeenCalledWith('/tracks/', { + params: { + ids: '0eGsygTp906u18L0Oimnem,1lDWb6b6ieDQ2xT7ewTC3G' + } }); }); @@ -992,21 +968,19 @@ describe('angular-spotify', function () { }); }); - describe('Spotify.getTrackAudioFeatures', function () { + describe('Spotify.getAudioFeaturesForTrack', function () { it('should make an ajax call to https://api.spotify.com/v1/audio-features/{id}', function () { - expect(Spotify.getTrackAudioFeatures('0eGsygTp906u18L0Oimnem')).toBeDefined(); + expect(Spotify.getAudioFeaturesForTrack('0eGsygTp906u18L0Oimnem')).toBeDefined(); }); it('should convert spotify uri to just an id', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.getTrackAudioFeatures('spotify:artist:0eGsygTp906u18L0Oimnem'); + Spotify.getAudioFeaturesForTrack('spotify:artist:0eGsygTp906u18L0Oimnem'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/audio-features/0eGsygTp906u18L0Oimnem', 'GET', null, null, { - 'Authorization': 'Bearer TESTING' - }); + expect(Spotify.api).toHaveBeenCalledWith('/audio-features/0eGsygTp906u18L0Oimnem'); }); it('should resolve to an object of a track', function () { @@ -1016,7 +990,7 @@ describe('angular-spotify', function () { var result; Spotify - .getTrackAudioFeatures('0eGsygTp906u18L0Oimnem') + .getAudioFeaturesForTrack('0eGsygTp906u18L0Oimnem') .then(function (data) { result = data; }); @@ -1036,7 +1010,7 @@ describe('angular-spotify', function () { var result; Spotify - .getTrackAudioFeatures('ABCDEFGHIJKLMNOP') + .getAudioFeaturesForTrack('ABCDEFGHIJKLMNOP') .then(function () { }, function (reason) { result = reason; @@ -1049,9 +1023,9 @@ describe('angular-spotify', function () { }); }); - describe('Spotify.getTracksAudioFeatures', function() { + describe('Spotify.getAudioFeaturesForTracks', function() { it('should make an ajax call to https://api.spotify.com/v1/audio-features?ids={id}', function () { - expect(Spotify.getTracksAudioFeatures('0eGsygTp906u18L0Oimnem,1lDWb6b6ieDQ2xT7ewTC3G')).toBeDefined(); + expect(Spotify.getAudioFeaturesForTracks('0eGsygTp906u18L0Oimnem,1lDWb6b6ieDQ2xT7ewTC3G')).toBeDefined(); }); it('should resolve to an array of tracks', function () { @@ -1059,7 +1033,7 @@ describe('angular-spotify', function () { var result; Spotify - .getTracksAudioFeatures('0eGsygTp906u18L0Oimnem,1lDWb6b6ieDQ2xT7ewTC3G') + .getAudioFeaturesForTracks('0eGsygTp906u18L0Oimnem,1lDWb6b6ieDQ2xT7ewTC3G') .then(function (data) { result = data; }); @@ -1072,14 +1046,14 @@ describe('angular-spotify', function () { it('should convert spotify uris to Ids', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); - Spotify.getTracksAudioFeatures('spotify:track:0eGsygTp906u18L0Oimnem,spotify:track:1lDWb6b6ieDQ2xT7ewTC3G'); + Spotify.setAccessToken('TESTING'); + Spotify.getAudioFeaturesForTracks('spotify:track:0eGsygTp906u18L0Oimnem,spotify:track:1lDWb6b6ieDQ2xT7ewTC3G'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/audio-features/', 'GET', { - ids: '0eGsygTp906u18L0Oimnem,1lDWb6b6ieDQ2xT7ewTC3G' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/audio-features/', { + params: { + ids: '0eGsygTp906u18L0Oimnem,1lDWb6b6ieDQ2xT7ewTC3G' + } }); }); @@ -1093,7 +1067,7 @@ describe('angular-spotify', function () { var result; Spotify - .getTracksAudioFeatures() + .getAudioFeaturesForTracks() .then(function () { }, function (reason) { result = reason; @@ -1115,14 +1089,12 @@ describe('angular-spotify', function () { it('should call the correct URL', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.getUserPlaylists('wizzler'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/users/wizzler/playlists', 'GET', undefined, null, { - 'Authorization': 'Bearer TESTING' - }); + expect(Spotify.api).toHaveBeenCalledWith('/users/wizzler/playlists', {}); }); }); @@ -1132,14 +1104,12 @@ describe('angular-spotify', function () { it('should call the correct url', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.getPlaylist('triple.j.abc', '73ppZmbaAS2aW9hmDTTDcb'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb', 'GET', undefined, null, { - 'Authorization': 'Bearer TESTING' - }); + expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb', {}); }); }); @@ -1149,14 +1119,12 @@ describe('angular-spotify', function () { it('should call the correct url', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.getPlaylistTracks('triple.j.abc', '73ppZmbaAS2aW9hmDTTDcb'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb/tracks', 'GET', undefined, null, { - 'Authorization': 'Bearer TESTING' - }); + expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb/tracks', {}); }); }); @@ -1166,202 +1134,281 @@ describe('angular-spotify', function () { it('should call the correct url', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.createPlaylist('1176458919', { name: 'Awesome Mix Vol. 1' }); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/users/1176458919/playlists', 'POST', null, { - name: 'Awesome Mix Vol. 1' - }, { - 'Authorization': 'Bearer TESTING', - 'Content-Type': 'application/json' + expect(Spotify.api).toHaveBeenCalledWith('/users/1176458919/playlists', { + method: 'POST', + data:{ + name: 'Awesome Mix Vol. 1' + }, + headers: { + 'Content-Type': 'application/json' + } }); }); }); - describe('Spotify.addPlaylistTracks', function() { + describe('Spotify.addTracksToPlaylist', function() { it('should call the correct url', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.addPlaylistTracks('triple.j.abc', '73ppZmbaAS2aW9hmDTTDcb', [ + Spotify.addTracksToPlaylist('triple.j.abc', '73ppZmbaAS2aW9hmDTTDcb', [ 'spotify:track:5LwukQO2fCx35GUUN6d6NW', 'spotify:track:4w8CsAnzn0lXJxYlAuCtCW', 'spotify:track:2Foc5Q5nqNiosCNqttzHof' ]); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb/tracks', 'POST', { - uris: 'spotify:track:5LwukQO2fCx35GUUN6d6NW,spotify:track:4w8CsAnzn0lXJxYlAuCtCW,spotify:track:2Foc5Q5nqNiosCNqttzHof', - position: null - }, null, { - 'Authorization': 'Bearer TESTING', - 'Content-Type': 'application/json' + expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb/tracks', { + method: 'POST', + params: { + uris: 'spotify:track:5LwukQO2fCx35GUUN6d6NW,spotify:track:4w8CsAnzn0lXJxYlAuCtCW,spotify:track:2Foc5Q5nqNiosCNqttzHof', + position: null + }, + headers: { + 'Content-Type': 'application/json' + } }); }); it('should be able to pass Track IDs', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.addPlaylistTracks('triple.j.abc', '73ppZmbaAS2aW9hmDTTDcb', [ + Spotify.addTracksToPlaylist('triple.j.abc', '73ppZmbaAS2aW9hmDTTDcb', [ '5LwukQO2fCx35GUUN6d6NW', '4w8CsAnzn0lXJxYlAuCtCW', '2Foc5Q5nqNiosCNqttzHof' ]); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb/tracks', 'POST', { - uris: 'spotify:track:5LwukQO2fCx35GUUN6d6NW,spotify:track:4w8CsAnzn0lXJxYlAuCtCW,spotify:track:2Foc5Q5nqNiosCNqttzHof', - position: null - }, null, { - 'Authorization': 'Bearer TESTING', - 'Content-Type': 'application/json' + expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb/tracks', { + method: 'POST', + params: { + uris: 'spotify:track:5LwukQO2fCx35GUUN6d6NW,spotify:track:4w8CsAnzn0lXJxYlAuCtCW,spotify:track:2Foc5Q5nqNiosCNqttzHof', + position: null + }, + headers: { + 'Content-Type': 'application/json' + } }); }); }); - describe('Spotify.removePlaylistTracks', function() { + describe('Spotify.removeTracksFromPlaylist', function() { it('should call the correct url', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.removePlaylistTracks('triple.j.abc', '73ppZmbaAS2aW9hmDTTDcb', [ + Spotify.removeTracksFromPlaylist('triple.j.abc', '73ppZmbaAS2aW9hmDTTDcb', [ 'spotify:track:5LwukQO2fCx35GUUN6d6NW', 'spotify:track:4w8CsAnzn0lXJxYlAuCtCW', 'spotify:track:2Foc5Q5nqNiosCNqttzHof' ]); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb/tracks', 'DELETE', null, { - tracks: [ - {uri: 'spotify:track:5LwukQO2fCx35GUUN6d6NW'}, - {uri: 'spotify:track:4w8CsAnzn0lXJxYlAuCtCW'}, - {uri: 'spotify:track:2Foc5Q5nqNiosCNqttzHof'} - ] - }, { - 'Authorization': 'Bearer TESTING', - 'Content-Type': 'application/json' + expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb/tracks', { + method: 'DELETE', + data: { + tracks: [ + {uri: 'spotify:track:5LwukQO2fCx35GUUN6d6NW'}, + {uri: 'spotify:track:4w8CsAnzn0lXJxYlAuCtCW'}, + {uri: 'spotify:track:2Foc5Q5nqNiosCNqttzHof'} + ] + }, + headers: { + 'Content-Type': 'application/json' + } }); }); it('should be able to pass track IDs', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.removePlaylistTracks('triple.j.abc', '73ppZmbaAS2aW9hmDTTDcb', [ + Spotify.removeTracksFromPlaylist('triple.j.abc', '73ppZmbaAS2aW9hmDTTDcb', [ '5LwukQO2fCx35GUUN6d6NW', '4w8CsAnzn0lXJxYlAuCtCW', '2Foc5Q5nqNiosCNqttzHof' ]); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb/tracks', 'DELETE', null, { - tracks: [ - {uri: 'spotify:track:5LwukQO2fCx35GUUN6d6NW'}, - {uri: 'spotify:track:4w8CsAnzn0lXJxYlAuCtCW'}, - {uri: 'spotify:track:2Foc5Q5nqNiosCNqttzHof'} - ] - }, { - 'Authorization': 'Bearer TESTING', - 'Content-Type': 'application/json' + expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb/tracks', { + method: 'DELETE', + data: { + tracks: [ + {uri: 'spotify:track:5LwukQO2fCx35GUUN6d6NW'}, + {uri: 'spotify:track:4w8CsAnzn0lXJxYlAuCtCW'}, + {uri: 'spotify:track:2Foc5Q5nqNiosCNqttzHof'} + ] + }, + headers: { + 'Content-Type': 'application/json' + } }); }); }); - describe('Spotify.reorderPlaylistTracks', function () { + describe('Spotify.removeTracksFromPlaylistWithSnapshotId', function () { + it('should call with the correct params', function () { + spyOn(Spotify, 'api'); + + Spotify.setAccessToken('TESTING'); + + Spotify.removeTracksFromPlaylistWithSnapshotId('triple.j.abc', '73ppZmbaAS2aW9hmDTTDcb', [ + '5LwukQO2fCx35GUUN6d6NW', + '4w8CsAnzn0lXJxYlAuCtCW', + '2Foc5Q5nqNiosCNqttzHof' + ], 'a1b2c3d4e5f6g7h8i9'); + + expect(Spotify.api).toHaveBeenCalled(); + expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb/tracks', { + method: 'DELETE', + data: { + tracks: [ + {uri: 'spotify:track:5LwukQO2fCx35GUUN6d6NW'}, + {uri: 'spotify:track:4w8CsAnzn0lXJxYlAuCtCW'}, + {uri: 'spotify:track:2Foc5Q5nqNiosCNqttzHof'} + ], + snapshot_id: 'a1b2c3d4e5f6g7h8i9' + }, + headers: { + 'Content-Type': 'application/json' + } + }); + }); + }); + + describe('Spotify.removeTracksFromPlaylistInPositions', function () { + it('should call with the correct params', function () { + spyOn(Spotify, 'api'); + + Spotify.setAccessToken('TESTING'); + + Spotify.removeTracksFromPlaylistInPositions('triple.j.abc', '73ppZmbaAS2aW9hmDTTDcb', [1,3,5,7,9], 'a1b2c3d4e5f6g7h8i9'); + + expect(Spotify.api).toHaveBeenCalled(); + expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb/tracks', { + method: 'DELETE', + data: { + positions: [1,3,5,7,9], + snapshot_id: 'a1b2c3d4e5f6g7h8i9' + }, + headers: { + 'Content-Type': 'application/json' + } + }); + }); + }); + + describe('Spotify.reorderTracksInPlaylist', function () { it('should call the correct url', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.reorderPlaylistTracks('triple.j.abc', '73ppZmbaAS2aW9hmDTTDcb', { + Spotify.reorderTracksInPlaylist('triple.j.abc', '73ppZmbaAS2aW9hmDTTDcb', { range_start: 2, range_length: 10, insert_before: 15 }); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb/tracks', 'PUT', null, { - range_start: 2, - range_length: 10, - insert_before: 15 - },{ - 'Authorization': 'Bearer TESTING', - 'Content-Type': 'application/json' + expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb/tracks', { + method: 'PUT', + data: { + range_start: 2, + range_length: 10, + insert_before: 15 + }, + headers: { + 'Content-Type': 'application/json' + } }); }); }); - describe('Spotify.replacePlaylistTracks', function() { + describe('Spotify.replaceTracksInPlaylist', function() { it('should call the correct url', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.replacePlaylistTracks('triple.j.abc', '73ppZmbaAS2aW9hmDTTDcb', [ + Spotify.replaceTracksInPlaylist('triple.j.abc', '73ppZmbaAS2aW9hmDTTDcb', [ 'spotify:track:5LwukQO2fCx35GUUN6d6NW', 'spotify:track:4w8CsAnzn0lXJxYlAuCtCW', 'spotify:track:2Foc5Q5nqNiosCNqttzHof' ]); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb/tracks', 'PUT', { - uris: 'spotify:track:5LwukQO2fCx35GUUN6d6NW,spotify:track:4w8CsAnzn0lXJxYlAuCtCW,spotify:track:2Foc5Q5nqNiosCNqttzHof' - }, null, { - 'Authorization': 'Bearer TESTING', - 'Content-Type': 'application/json' + expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb/tracks', { + method: 'PUT', + params: { + uris: 'spotify:track:5LwukQO2fCx35GUUN6d6NW,spotify:track:4w8CsAnzn0lXJxYlAuCtCW,spotify:track:2Foc5Q5nqNiosCNqttzHof' + }, + headers: { + 'Content-Type': 'application/json' + } }); }); it('should be able to pass track IDs', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.replacePlaylistTracks('triple.j.abc', '73ppZmbaAS2aW9hmDTTDcb', [ + Spotify.replaceTracksInPlaylist('triple.j.abc', '73ppZmbaAS2aW9hmDTTDcb', [ '5LwukQO2fCx35GUUN6d6NW', '4w8CsAnzn0lXJxYlAuCtCW', '2Foc5Q5nqNiosCNqttzHof' ]); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb/tracks', 'PUT', { - uris: 'spotify:track:5LwukQO2fCx35GUUN6d6NW,spotify:track:4w8CsAnzn0lXJxYlAuCtCW,spotify:track:2Foc5Q5nqNiosCNqttzHof' - }, null, { - 'Authorization': 'Bearer TESTING', - 'Content-Type': 'application/json' + expect(Spotify.api).toHaveBeenCalledWith('/users/triple.j.abc/playlists/73ppZmbaAS2aW9hmDTTDcb/tracks', { + method: 'PUT', + params: { + uris: 'spotify:track:5LwukQO2fCx35GUUN6d6NW,spotify:track:4w8CsAnzn0lXJxYlAuCtCW,spotify:track:2Foc5Q5nqNiosCNqttzHof' + }, + headers: { + 'Content-Type': 'application/json' + } }); }); }); - describe('Spotify.updatePlaylistDetails', function () { + describe('Spotify.changePlaylistDetails', function () { it('should call the correct URL', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.updatePlaylistDetails('1176458919', '3ygKiRcD8ed3i2g8P7jlXr', { + Spotify.changePlaylistDetails('1176458919', '3ygKiRcD8ed3i2g8P7jlXr', { name: 'Awesome Mix Vol. 2' }); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/users/1176458919/playlists/3ygKiRcD8ed3i2g8P7jlXr', 'PUT', null, { - name: 'Awesome Mix Vol. 2' - }, { - 'Authorization': 'Bearer TESTING', - 'Content-Type': 'application/json' + expect(Spotify.api).toHaveBeenCalledWith('/users/1176458919/playlists/3ygKiRcD8ed3i2g8P7jlXr', { + method: 'PUT', + data: { + name: 'Awesome Mix Vol. 2' + }, + headers: { + 'Content-Type': 'application/json' + } }); }); @@ -1418,19 +1465,17 @@ describe('angular-spotify', function () { }); }); - describe('Spotify.getCurrentUser', function () { + describe('Spotify.getMe', function () { it('should call the correct URL', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.getCurrentUser(); + Spotify.getMe(); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me', 'GET', null, null, { - 'Authorization': 'Bearer TESTING' - }); + expect(Spotify.api).toHaveBeenCalledWith('/me'); }); }); @@ -1439,243 +1484,255 @@ describe('angular-spotify', function () { describe('User Library', function () { - describe('Spotify.getSavedUserTracks', function () { + describe('Spotify.getMySavedTracks', function () { it('should call the correct URL', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.getSavedUserTracks(); + Spotify.getMySavedTracks(); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/tracks', 'GET', undefined, null, { - 'Authorization': 'Bearer TESTING' - }); + expect(Spotify.api).toHaveBeenCalledWith('/me/tracks', {}); }); }); - describe('Spotify.userTracksContains', function () { + describe('Spotify.containsMySavedTracks', function () { it('should call the correct URL', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.userTracksContains(['0udZHhCi7p1YzMlvI4fXoK','3SF5puV5eb6bgRSxBeMOk9']); + Spotify.containsMySavedTracks(['0udZHhCi7p1YzMlvI4fXoK','3SF5puV5eb6bgRSxBeMOk9']); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/tracks/contains', 'GET', { - ids: '0udZHhCi7p1YzMlvI4fXoK,3SF5puV5eb6bgRSxBeMOk9' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/me/tracks/contains', { + params: { + ids: '0udZHhCi7p1YzMlvI4fXoK,3SF5puV5eb6bgRSxBeMOk9' + } }); }); it('should be able to pass Spotify URIs', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.userTracksContains(['spotify:track:0udZHhCi7p1YzMlvI4fXoK','spotify:track:3SF5puV5eb6bgRSxBeMOk9']); + Spotify.containsMySavedTracks(['spotify:track:0udZHhCi7p1YzMlvI4fXoK','spotify:track:3SF5puV5eb6bgRSxBeMOk9']); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/tracks/contains', 'GET', { - ids: '0udZHhCi7p1YzMlvI4fXoK,3SF5puV5eb6bgRSxBeMOk9' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/me/tracks/contains', { + params: { + ids: '0udZHhCi7p1YzMlvI4fXoK,3SF5puV5eb6bgRSxBeMOk9' + } }); }); }); - describe('Spotify.saveUserTracks', function () { + describe('Spotify.addToMySavedTracks', function () { it('should call the correct URL', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.saveUserTracks(['4iV5W9uYEdYUVa79Axb7Rh','1301WleyT98MSxVHPZCA6M']); + Spotify.addToMySavedTracks(['4iV5W9uYEdYUVa79Axb7Rh','1301WleyT98MSxVHPZCA6M']); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/tracks', 'PUT', { - ids: '4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/me/tracks', { + method: 'PUT', + params: { + ids: '4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M' + } }); }); it('should be able to pass Spotify URIs', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.saveUserTracks(['spotify:track:0udZHhCi7p1YzMlvI4fXoK','spotify:track:3SF5puV5eb6bgRSxBeMOk9']); + Spotify.addToMySavedTracks(['spotify:track:0udZHhCi7p1YzMlvI4fXoK','spotify:track:3SF5puV5eb6bgRSxBeMOk9']); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/tracks', 'PUT', { - ids: '0udZHhCi7p1YzMlvI4fXoK,3SF5puV5eb6bgRSxBeMOk9' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/me/tracks', { + method: 'PUT', + params: { + ids: '0udZHhCi7p1YzMlvI4fXoK,3SF5puV5eb6bgRSxBeMOk9' + } }); }); }); - describe('Spotify.removeUserTracks', function () { + describe('Spotify.removeFromMySavedTracks', function () { it('should call the correct URL', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.removeUserTracks(['4iV5W9uYEdYUVa79Axb7Rh','1301WleyT98MSxVHPZCA6M']); + Spotify.removeFromMySavedTracks(['4iV5W9uYEdYUVa79Axb7Rh','1301WleyT98MSxVHPZCA6M']); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/tracks', 'DELETE', { - ids: '4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M' - }, null, { - 'Authorization': 'Bearer TESTING', - 'Content-Type': 'application/json' + expect(Spotify.api).toHaveBeenCalledWith('/me/tracks', { + method: 'DELETE', + params: { + ids: '4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M' + }, + headers: { + 'Content-Type': 'application/json' + } }); }); it('should be able to pass Spotify URIs', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.removeUserTracks(['spotify:track:0udZHhCi7p1YzMlvI4fXoK','spotify:track:3SF5puV5eb6bgRSxBeMOk9']); + Spotify.removeFromMySavedTracks(['spotify:track:0udZHhCi7p1YzMlvI4fXoK','spotify:track:3SF5puV5eb6bgRSxBeMOk9']); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/tracks', 'DELETE', { - ids: '0udZHhCi7p1YzMlvI4fXoK,3SF5puV5eb6bgRSxBeMOk9' - }, null, { - 'Authorization': 'Bearer TESTING', - 'Content-Type': 'application/json' + expect(Spotify.api).toHaveBeenCalledWith('/me/tracks', { + method: 'DELETE', + params: { + ids: '0udZHhCi7p1YzMlvI4fXoK,3SF5puV5eb6bgRSxBeMOk9' + }, + headers: { + 'Content-Type': 'application/json' + } }); }); }); - describe('Spotify.getSavedUserAlbums', function () { + describe('Spotify.getMySavedAlbums', function () { it('should call the correct URL', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.getSavedUserAlbums(); + Spotify.getMySavedAlbums(); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/albums', 'GET', undefined, null, { - 'Authorization': 'Bearer TESTING' - }); + expect(Spotify.api).toHaveBeenCalledWith('/me/albums', {}); }); }); - describe('Spotify.saveUserAlbums', function () { + describe('Spotify.addToMySavedAlbums', function () { it('should call the correct URL', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.saveUserAlbums(['4iV5W9uYEdYUVa79Axb7Rh','1301WleyT98MSxVHPZCA6M']); + Spotify.addToMySavedAlbums(['4iV5W9uYEdYUVa79Axb7Rh','1301WleyT98MSxVHPZCA6M']); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/albums', 'PUT', { - ids: '4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/me/albums', { + method: 'PUT', + params: { + ids: '4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M' + } }); }); it('should be able to pass Spotify URIs', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.saveUserAlbums(['spotify:album:4iV5W9uYEdYUVa79Axb7Rh','spotify:album:1301WleyT98MSxVHPZCA6M']); + Spotify.addToMySavedAlbums(['spotify:album:4iV5W9uYEdYUVa79Axb7Rh','spotify:album:1301WleyT98MSxVHPZCA6M']); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/albums', 'PUT', { - ids: '4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/me/albums', { + method: 'PUT', + params: { + ids: '4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M' + } }); }); }); - describe('Spotify.removeUserAlbums', function () { + describe('Spotify.removeFromMySavedAlbums', function () { it('should call the correct URL', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.removeUserAlbums(['4iV5W9uYEdYUVa79Axb7Rh','1301WleyT98MSxVHPZCA6M']); + Spotify.removeFromMySavedAlbums(['4iV5W9uYEdYUVa79Axb7Rh','1301WleyT98MSxVHPZCA6M']); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/albums', 'DELETE', { - ids: '4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M' - }, null, { - 'Authorization': 'Bearer TESTING', - 'Content-Type': 'application/json' + expect(Spotify.api).toHaveBeenCalledWith('/me/albums', { + method: 'DELETE', + params: { + ids: '4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M' + }, + headers: { + 'Content-Type': 'application/json' + } }); }); it('should be able to pass Spotify URIs', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.removeUserAlbums(['spotify:album:4iV5W9uYEdYUVa79Axb7Rh','spotify:album:1301WleyT98MSxVHPZCA6M']); + Spotify.removeFromMySavedAlbums(['spotify:album:4iV5W9uYEdYUVa79Axb7Rh','spotify:album:1301WleyT98MSxVHPZCA6M']); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/albums', 'DELETE', { - ids: '4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M' - }, null, { - 'Authorization': 'Bearer TESTING', - 'Content-Type': 'application/json' + expect(Spotify.api).toHaveBeenCalledWith('/me/albums', { + method: 'DELETE', + params: { + ids: '4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M' + }, + headers: { + 'Content-Type': 'application/json' + } }); }); }); - describe('Spotify.userAlbumsContains', function () { + describe('Spotify.containsMySavedAlbums', function () { it('should call the correct URL', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.userAlbumsContains(['4iV5W9uYEdYUVa79Axb7Rh','1301WleyT98MSxVHPZCA6M']); + Spotify.containsMySavedAlbums(['4iV5W9uYEdYUVa79Axb7Rh','1301WleyT98MSxVHPZCA6M']); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/albums/contains', 'GET', { - ids: '4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/me/albums/contains', { + params: { + ids: '4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M' + } }); }); it('should be able to pass Spotify URIs', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.userAlbumsContains(['spotify:album:4iV5W9uYEdYUVa79Axb7Rh','spotify:album:1301WleyT98MSxVHPZCA6M']); + Spotify.containsMySavedAlbums(['spotify:album:4iV5W9uYEdYUVa79Axb7Rh','spotify:album:1301WleyT98MSxVHPZCA6M']); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/albums/contains', 'GET', { - ids: '4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/me/albums/contains', { + params: { + ids: '4iV5W9uYEdYUVa79Axb7Rh,1301WleyT98MSxVHPZCA6M' + } }); }); @@ -1684,70 +1741,66 @@ describe('angular-spotify', function () { }); describe('Personalization', function () { - describe('Spotify.getUserTopArtists', function () { + describe('Spotify.getMyTopArtists', function () { it('should call the correct URL with authentication', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.getUserTopArtists(); + Spotify.getMyTopArtists(); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/top/artists', 'GET', {}, null, { - 'Authorization': 'Bearer TESTING' - }); + expect(Spotify.api).toHaveBeenCalledWith('/me/top/artists', {}); }); it('should call the correct URL with authentication and options', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.getUserTopArtists({ + Spotify.getMyTopArtists({ limit: 50, offset: 50 }); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/top/artists', 'GET', { - limit: 50, - offset: 50 - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/me/top/artists', { + params: { + limit: 50, + offset: 50 + } }); }); }); - describe('Spotify.getUserTopTracks', function () { + describe('Spotify.getMyTopTracks', function () { it('should call the correct URL with authentication', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.getUserTopTracks(); + Spotify.getMyTopTracks(); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/top/tracks', 'GET', {}, null, { - 'Authorization': 'Bearer TESTING' - }); + expect(Spotify.api).toHaveBeenCalledWith('/me/top/tracks', {}); }); it('should call the correct URL with authentication and options', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.getUserTopTracks({ + Spotify.getMyTopTracks({ limit: 50, offset: 50 }); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/top/tracks', 'GET', { - limit: 50, - offset: 50 - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/me/top/tracks', { + params: { + limit: 50, + offset: 50 + } }); }); }); @@ -1768,15 +1821,16 @@ describe('angular-spotify', function () { it('should call the correct URL with authentication and options', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.getFeaturedPlaylists({ country: 'NL', locale: 'nl_NL' }); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/browse/featured-playlists', 'GET', { - country: 'NL', locale: 'nl_NL' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/browse/featured-playlists', { + params: { + country: 'NL', + locale: 'nl_NL' + } }); }); @@ -1802,15 +1856,15 @@ describe('angular-spotify', function () { it('should call the correct URL with authentication and options', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.getNewReleases({ country: 'NL' }); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/browse/new-releases', 'GET', { - country: 'NL' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/browse/new-releases', { + params: { + country: 'NL' + } }); }); @@ -1834,20 +1888,18 @@ describe('angular-spotify', function () { it('should call the correct URL with authentication', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.getCategories(); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/browse/categories', 'GET', undefined, null, { - 'Authorization': 'Bearer TESTING' - }); + expect(Spotify.api).toHaveBeenCalledWith('/browse/categories', {}); }); it('should call the correct URL with authentication and options', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.getCategories({ country: 'SG', @@ -1855,11 +1907,11 @@ describe('angular-spotify', function () { }); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/browse/categories', 'GET', { - country: 'SG', - limit: 20 - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/browse/categories', { + params: { + country: 'SG', + limit: 20 + } }); }); }); @@ -1868,30 +1920,28 @@ describe('angular-spotify', function () { it('should call the correct URL with authentication', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.getCategory('party'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/browse/categories/party', 'GET', undefined, null, { - 'Authorization': 'Bearer TESTING' - }); + expect(Spotify.api).toHaveBeenCalledWith('/browse/categories/party', {}); }); it('should call the correct URL with authentication and options', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.getCategory('party', { country: 'SG' }); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/browse/categories/party', 'GET', { - country: 'SG' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/browse/categories/party', { + params: { + country: 'SG' + } }); }); }); @@ -1900,20 +1950,18 @@ describe('angular-spotify', function () { it('should call the correct URL with authentication', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.getCategoryPlaylists('party'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/browse/categories/party/playlists', 'GET', undefined, null, { - 'Authorization': 'Bearer TESTING' - }); + expect(Spotify.api).toHaveBeenCalledWith('/browse/categories/party/playlists', {}); }); it('should call the correct URL with authentication with options', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.getCategoryPlaylists('party', { country: 'SG', @@ -1921,11 +1969,11 @@ describe('angular-spotify', function () { }); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/browse/categories/party/playlists', 'GET', { - country: 'SG', - limit: 20 - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/browse/categories/party/playlists', { + params: { + country: 'SG', + limit: 20 + } }); }); }); @@ -1934,17 +1982,17 @@ describe('angular-spotify', function () { it('should call the correct URL with authentication', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.getRecommendations({ seed_artists: '4NHQUGzhtTLFvgF5SZesLK' }); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/recommendations', 'GET', { - seed_artists: '4NHQUGzhtTLFvgF5SZesLK' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/recommendations', { + params: { + seed_artists: '4NHQUGzhtTLFvgF5SZesLK' + } }); }); }); @@ -1953,14 +2001,12 @@ describe('angular-spotify', function () { it('should call the correct URL with authentication', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.getAvailableGenreSeeds(); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/recommendations/available-genre-seeds', 'GET', null, null, { - 'Authorization': 'Bearer TESTING' - }); + expect(Spotify.api).toHaveBeenCalledWith('/recommendations/available-genre-seeds'); }); }); }); @@ -1974,35 +2020,35 @@ describe('angular-spotify', function () { $httpBackend = _$httpBackend_; })); - describe('Spotify.following', function () { + describe('Spotify.getFollowed', function () { it('should call the correct URL', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.following('artist'); + Spotify.getFollowed('artist'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/following', 'GET', { - type: 'artist' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/me/following', { + params: { + type: 'artist' + } }); }); it('should call with options', function() { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.following('artist', { limit: 30 }); + Spotify.getFollowed('artist', { limit: 30 }); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/following', 'GET', { - type: 'artist', - limit: 30 - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/me/following', { + params: { + type: 'artist', + limit: 30 + } }); }); }); @@ -2011,32 +2057,106 @@ describe('angular-spotify', function () { it('should call the correct URL', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.follow('user', 'exampleuser01'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/following', 'PUT', { - type: 'user', - ids: 'exampleuser01' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/me/following', { + method: 'PUT', + params: { + type: 'user', + ids: 'exampleuser01' + } }); }); it('should call with multiple ids', function() { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.follow('artist', '74ASZWbe4lXaubB36ztrGX,08td7MxkoHQkXnWAYD8d6Q'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/following', 'PUT', { - type: 'artist', - ids: '74ASZWbe4lXaubB36ztrGX,08td7MxkoHQkXnWAYD8d6Q' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/me/following', { + method: 'PUT', + params: { + type: 'artist', + ids: '74ASZWbe4lXaubB36ztrGX,08td7MxkoHQkXnWAYD8d6Q' + } + }); + }); + }); + + describe('Spotify.followUsers', function () { + it('should call the correct URL', function () { + spyOn(Spotify, 'api'); + + Spotify.setAccessToken('TESTING'); + + Spotify.followUsers('exampleuser01'); + + expect(Spotify.api).toHaveBeenCalled(); + expect(Spotify.api).toHaveBeenCalledWith('/me/following', { + method: 'PUT', + params: { + type: 'user', + ids: 'exampleuser01' + } + }); + }); + + it('should call with multiple ids', function() { + spyOn(Spotify, 'api'); + + Spotify.setAccessToken('TESTING'); + + Spotify.followUsers(['74ASZWbe4lXaubB36ztrGX','08td7MxkoHQkXnWAYD8d6Q']); + + expect(Spotify.api).toHaveBeenCalled(); + expect(Spotify.api).toHaveBeenCalledWith('/me/following', { + method: 'PUT', + params: { + type: 'user', + ids: '74ASZWbe4lXaubB36ztrGX,08td7MxkoHQkXnWAYD8d6Q' + } + }); + }); + }); + + describe('Spotify.followArtists', function () { + it('should call the correct URL', function () { + spyOn(Spotify, 'api'); + + Spotify.setAccessToken('TESTING'); + + Spotify.followArtists('exampleartist01'); + + expect(Spotify.api).toHaveBeenCalled(); + expect(Spotify.api).toHaveBeenCalledWith('/me/following', { + method: 'PUT', + params: { + type: 'artist', + ids: 'exampleartist01' + } + }); + }); + + it('should call with multiple ids', function() { + spyOn(Spotify, 'api'); + + Spotify.setAccessToken('TESTING'); + + Spotify.followArtists('74ASZWbe4lXaubB36ztrGX,08td7MxkoHQkXnWAYD8d6Q'); + + expect(Spotify.api).toHaveBeenCalled(); + expect(Spotify.api).toHaveBeenCalledWith('/me/following', { + method: 'PUT', + params: { + type: 'artist', + ids: '74ASZWbe4lXaubB36ztrGX,08td7MxkoHQkXnWAYD8d6Q' + } }); }); }); @@ -2045,50 +2165,176 @@ describe('angular-spotify', function () { it('should call the correct URL', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.unfollow('user', 'exampleuser01'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/following', 'DELETE', { - type: 'user', - ids: 'exampleuser01' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/me/following', { + method: 'DELETE', + params: { + type: 'user', + ids: 'exampleuser01' + } }); }); it('should call with multiple ids', function() { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.unfollow('artist', '74ASZWbe4lXaubB36ztrGX,08td7MxkoHQkXnWAYD8d6Q'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/following', 'DELETE', { - type: 'artist', - ids: '74ASZWbe4lXaubB36ztrGX,08td7MxkoHQkXnWAYD8d6Q' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/me/following', { + method: 'DELETE', + params: { + type: 'artist', + ids: '74ASZWbe4lXaubB36ztrGX,08td7MxkoHQkXnWAYD8d6Q' + } + }); + }); + }); + + describe('Spotify.unfollowUsers', function () { + it('should call the correct URL', function () { + spyOn(Spotify, 'api'); + + Spotify.setAccessToken('TESTING'); + + Spotify.unfollowUsers('exampleuser01'); + + expect(Spotify.api).toHaveBeenCalled(); + expect(Spotify.api).toHaveBeenCalledWith('/me/following', { + method: 'DELETE', + params: { + type: 'user', + ids: 'exampleuser01' + } + }); + }); + + it('should call with multiple ids', function() { + spyOn(Spotify, 'api'); + + Spotify.setAccessToken('TESTING'); + + Spotify.unfollowUsers('74ASZWbe4lXaubB36ztrGX,08td7MxkoHQkXnWAYD8d6Q'); + + expect(Spotify.api).toHaveBeenCalled(); + expect(Spotify.api).toHaveBeenCalledWith('/me/following', { + method: 'DELETE', + params: { + type: 'user', + ids: '74ASZWbe4lXaubB36ztrGX,08td7MxkoHQkXnWAYD8d6Q' + } + }); + }); + }); + + describe('Spotify.unfollowArtists', function () { + it('should call the correct URL', function () { + spyOn(Spotify, 'api'); + + Spotify.setAccessToken('TESTING'); + + Spotify.unfollowArtists('exampleartist01'); + + expect(Spotify.api).toHaveBeenCalled(); + expect(Spotify.api).toHaveBeenCalledWith('/me/following', { + method: 'DELETE', + params: { + type: 'artist', + ids: 'exampleartist01' + } + }); + }); + + it('should call with multiple ids', function() { + spyOn(Spotify, 'api'); + + Spotify.setAccessToken('TESTING'); + + Spotify.unfollowArtists('74ASZWbe4lXaubB36ztrGX,08td7MxkoHQkXnWAYD8d6Q'); + + expect(Spotify.api).toHaveBeenCalled(); + expect(Spotify.api).toHaveBeenCalledWith('/me/following', { + method: 'DELETE', + params: { + type: 'artist', + ids: '74ASZWbe4lXaubB36ztrGX,08td7MxkoHQkXnWAYD8d6Q' + } + }); + }); + }); + + describe('Spotify.isFollowing', function() { + it('should call the correct URL', function () { + spyOn(Spotify, 'api'); + + Spotify.setAccessToken('TESTING'); + + Spotify.isFollowing('user', 'exampleuser01'); + + expect(Spotify.api).toHaveBeenCalled(); + expect(Spotify.api).toHaveBeenCalledWith('/me/following/contains', { + params: { + type: 'user', + ids: 'exampleuser01' + } + }); + }); + + it('should call with multiple ids', function () { + spyOn(Spotify, 'api'); + + Spotify.setAccessToken('TESTING'); + + Spotify.isFollowing('user', ['exampleuser01', 'exampleuser02']); + + expect(Spotify.api).toHaveBeenCalled(); + expect(Spotify.api).toHaveBeenCalledWith('/me/following/contains', { + params: { + type: 'user', + ids: 'exampleuser01,exampleuser02' + } + }); + }); + }); + + describe('Spotify.isFollowingUsers', function() { + it('should call the correct URL', function () { + spyOn(Spotify, 'api'); + + Spotify.setAccessToken('TESTING'); + + Spotify.isFollowingUsers('exampleuser01'); + + expect(Spotify.api).toHaveBeenCalled(); + expect(Spotify.api).toHaveBeenCalledWith('/me/following/contains', { + params: { + type: 'user', + ids: 'exampleuser01' + } }); }); }); - describe('Spotify.userFollowingContains', function() { + describe('Spotify.isFollowingArtists', function() { it('should call the correct URL', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.userFollowingContains('user', 'exampleuser01'); + Spotify.isFollowingArtists('exampleartist01'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/me/following/contains', 'GET', { - type: 'user', - ids: 'exampleuser01' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/me/following/contains', { + params: { + type: 'artist', + ids: 'exampleartist01' + } }); }); }); @@ -2097,32 +2343,38 @@ describe('angular-spotify', function () { it ('should call the correct URL', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.followPlaylist('jmperezperez', '2v3iNvBX8Ay1Gt2uXtUKUT'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/users/jmperezperez/playlists/2v3iNvBX8Ay1Gt2uXtUKUT/followers', 'PUT', null, { - public: null - }, { - 'Authorization': 'Bearer TESTING', - 'Content-Type': 'application/json' + expect(Spotify.api).toHaveBeenCalledWith('/users/jmperezperez/playlists/2v3iNvBX8Ay1Gt2uXtUKUT/followers', { + method: 'PUT', + data: { + public: null + }, + headers: { + 'Content-Type': 'application/json' + } }); }); it('should be able to follow and set to public', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.followPlaylist('jmperezperez', '2v3iNvBX8Ay1Gt2uXtUKUT', true); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/users/jmperezperez/playlists/2v3iNvBX8Ay1Gt2uXtUKUT/followers', 'PUT', null, { - public: true - }, { - 'Authorization': 'Bearer TESTING', - 'Content-Type': 'application/json' + expect(Spotify.api).toHaveBeenCalledWith('/users/jmperezperez/playlists/2v3iNvBX8Ay1Gt2uXtUKUT/followers', { + method: 'PUT', + data: { + public: true + }, + headers: { + 'Content-Type': 'application/json' + } }); }); }); @@ -2131,45 +2383,45 @@ describe('angular-spotify', function () { it ('should call the correct URL', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); Spotify.unfollowPlaylist('jmperezperez', '2v3iNvBX8Ay1Gt2uXtUKUT'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/users/jmperezperez/playlists/2v3iNvBX8Ay1Gt2uXtUKUT/followers', 'DELETE', null, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/users/jmperezperez/playlists/2v3iNvBX8Ay1Gt2uXtUKUT/followers', { + method: 'DELETE' }); }); }); - describe('Spotify.playlistFollowingContains', function () { + describe('Spotify.areFollowingPlaylist', function () { it('should call the correct URL', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.playlistFollowingContains('jmperezperez', '2v3iNvBX8Ay1Gt2uXtUKUT', 'possan,elogain'); + Spotify.areFollowingPlaylist('jmperezperez', '2v3iNvBX8Ay1Gt2uXtUKUT', 'possan,elogain'); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/users/jmperezperez/playlists/2v3iNvBX8Ay1Gt2uXtUKUT/followers/contains', 'GET', { - ids: 'possan,elogain' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/users/jmperezperez/playlists/2v3iNvBX8Ay1Gt2uXtUKUT/followers/contains', { + params: { + ids: 'possan,elogain' + } }); }); it('should be able to be called with an array of users', function () { spyOn(Spotify, 'api'); - Spotify.setAuthToken('TESTING'); + Spotify.setAccessToken('TESTING'); - Spotify.playlistFollowingContains('jmperezperez', '2v3iNvBX8Ay1Gt2uXtUKUT', ['possan','elogain']); + Spotify.areFollowingPlaylist('jmperezperez', '2v3iNvBX8Ay1Gt2uXtUKUT', ['possan','elogain']); expect(Spotify.api).toHaveBeenCalled(); - expect(Spotify.api).toHaveBeenCalledWith('/users/jmperezperez/playlists/2v3iNvBX8Ay1Gt2uXtUKUT/followers/contains', 'GET', { - ids: 'possan,elogain' - }, null, { - 'Authorization': 'Bearer TESTING' + expect(Spotify.api).toHaveBeenCalledWith('/users/jmperezperez/playlists/2v3iNvBX8Ay1Gt2uXtUKUT/followers/contains', { + params: { + ids: 'possan,elogain' + } }); }); }); @@ -2201,15 +2453,15 @@ describe('angular-spotify', function () { }); // it('should set the auth token', function (done) { - // spyOn(Spotify, 'setAuthToken'); + // spyOn(Spotify, 'setAccessToken'); // Spotify.login(); // setTimeout(function () { // localStorage.setItem('spotify-token', 'TESTINGTOKEN'); // }, 1000); // // console.log('spotify token: ', localStorage.getItem('spotify-token')); // setTimeout(function () { - // expect(Spotify.setAuthToken).toHaveBeenCalled(); - // expect(Spotify.setAuthToken).toHaveBeenCalledWith('TESTINGTOKEN'); + // expect(Spotify.setAccessToken).toHaveBeenCalled(); + // expect(Spotify.setAccessToken).toHaveBeenCalledWith('TESTINGTOKEN'); // done(); // }, 3500); // });