diff --git a/bower.json b/bower.json index 02f2b3a..c69ab54 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-spotify", - "version": "0.12.0", + "version": "0.13.0", "authors": [ "Ed Moore " ], diff --git a/dist/angular-spotify.min.js b/dist/angular-spotify.min.js index 83e63b8..c33275a 100644 --- a/dist/angular-spotify.min.js +++ b/dist/angular-spotify.min.js @@ -1,2 +1,2 @@ -/*! angular-spotify 2015-03-19 */ -!function(a,b){"use strict";b.module("spotify",[]).provider("Spotify",function(){var c={};c.clientId=null,c.redirectUri=null,c.scope=null,c.accessToken=null,this.setClientId=function(a){return c.clientId=a,c.clientId},this.getClientId=function(){return c.clientId},this.setAuthToken=function(a){return c.accessToken=a,c.accessToken},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.accessToken=null,this.toQueryString=d.toQueryString}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}).success(function(a){h.resolve(a)}).error(function(a){h.reject(a)}),h.promise},h.prototype.search=function(a,b,c){return c=c||{},c.q=a,c.type=b,this.api("/search","GET",c)},h.prototype.getAlbum=function(a){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/albums/"+a)},h.prototype.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():""})},h.prototype.getAlbumTracks=function(a,b){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/albums/"+a+"/tracks","GET",b)},h.prototype.getArtist=function(a){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/artists/"+a)},h.prototype.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():""})},h.prototype.getArtistAlbums=function(a,b){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/artists/"+a+"/albums","GET",b)},h.prototype.getArtistTopTracks=function(a,b){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/artists/"+a+"/top-tracks","GET",{country:b})},h.prototype.getRelatedArtists=function(a){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/artists/"+a+"/related-artists")},h.prototype.getTrack=function(a){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/tracks/"+a)},h.prototype.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():""})},h.prototype.getUserPlaylists=function(a,b){return this.api("/users/"+a+"/playlists","GET",b,null,{Authorization:"Bearer "+this.authToken})},h.prototype.getPlaylist=function(a,b,c){return this.api("/users/"+a+"/playlists/"+b,"GET",c,null,{Authorization:"Bearer "+this.authToken})},h.prototype.getPlaylistTracks=function(a,b,c){return this.api("/users/"+a+"/playlists/"+b+"/tracks","GET",c,null,{Authorization:"Bearer "+this.authToken})},h.prototype.createPlaylist=function(a,b){return this.api("/users/"+a+"/playlists","POST",null,b,{Authorization:"Bearer "+this.authToken,"Content-Type":"application/json"})},h.prototype.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,{Authorization:"Bearer "+this.authToken,"Content-Type":"application/json"})},h.prototype.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},{Authorization:"Bearer "+this.authToken,"Content-Type":"application/json"})},h.prototype.reorderPlaylistTracks=function(a,b,c){return this.api("/users/"+a+"/playlists/"+b+"/tracks","PUT",null,c,{Authorization:"Bearer "+this.authToken,"Content-Type":"application/json"})},h.prototype.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,{Authorization:"Bearer "+this.authToken,"Content-Type":"application/json"})},h.prototype.updatePlaylistDetails=function(a,b,c){return this.api("/users/"+a+"/playlists/"+b,"PUT",null,c,{Authorization:"Bearer "+this.authToken,"Content-Type":"application/json"})},h.prototype.getUser=function(a){return this.api("/users/"+a)},h.prototype.getCurrentUser=function(){return this.api("/me","GET",null,null,{Authorization:"Bearer "+this.authToken})},h.prototype.getSavedUserTracks=function(a){return this.api("/me/tracks","GET",a,null,{Authorization:"Bearer "+this.authToken})},h.prototype.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,{Authorization:"Bearer "+this.authToken})},h.prototype.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,{Authorization:"Bearer "+this.authToken})},h.prototype.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,{Authorization:"Bearer "+this.authToken,"Content-Type":"application/json"})},h.prototype.getFeaturedPlaylists=function(a){return this.api("/browse/featured-playlists","GET",a,null,{Authorization:"Bearer "+this.authToken})},h.prototype.getNewReleases=function(a){return this.api("/browse/new-releases","GET",a,null,{Authorization:"Bearer "+this.authToken})},h.prototype.follow=function(a,b){return this.api("/me/following","PUT",{type:a,ids:b},null,{Authorization:"Bearer "+this.authToken})},h.prototype.unfollow=function(a,b){return this.api("/me/following","DELETE",{type:a,ids:b},null,{Authorization:"Bearer "+this.authToken})},h.prototype.userFollowingContains=function(a,b){return this.api("/me/following/contains","GET",{type:a,ids:b},null,{Authorization:"Bearer "+this.authToken})},h.prototype.followPlaylist=function(a,b,c){return this.api("/users/"+a+"/playlists/"+b+"/followers","PUT",null,{"public":c||null},{Authorization:"Bearer "+this.authToken,"Content-Type":"application/json"})},h.prototype.unfollowPlaylist=function(a,b){return this.api("/users/"+a+"/playlists/"+b+"/followers","DELETE",null,null,{Authorization:"Bearer "+this.authToken})},h.prototype.playlistFollowingContains=function(a,b,c){return this.api("/users/"+a+"/playlists/"+b+"/followers/contains","GET",{ids:c.toString()},null,{Authorization:"Bearer "+this.authToken})},h.prototype.setAuthToken=function(a){return this.authToken=a,this.authToken},h.prototype.login=function(){function b(a){"spotify-token"===a.key&&(l&&l.close(),d.setAuthToken(a.newValue),g.removeEventListener("storage",b,!1),c.resolve(a.newValue))}var c=e.defer(),d=this,f=400,h=500,i=screen.width/2-f/2,j=screen.height/2-h/2,k={client_id:this.clientId,redirect_uri:this.redirectUri,scope:this.scope||"",response_type:"token"},l=a.open("https://accounts.spotify.com/authorize?"+this.toQueryString(k),"Spotify","menubar=no,location=no,resizable=yes,scrollbars=yes,status=no,width="+f+",height="+h+",top="+j+",left="+i);return g.addEventListener("storage",b,!1),c.promise},new h}]})}(window,angular); \ No newline at end of file +/*! angular-spotify 2015-05-10 */ +!function(a,b){"use strict";b.module("spotify",[]).provider("Spotify",function(){var c={};c.clientId=null,c.redirectUri=null,c.scope=null,c.accessToken=null,this.setClientId=function(a){return c.clientId=a,c.clientId},this.getClientId=function(){return c.clientId},this.setAuthToken=function(a){return c.accessToken=a,c.accessToken},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.accessToken=c.accessToken,this.toQueryString=d.toQueryString}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}).success(function(a){h.resolve(a)}).error(function(a){h.reject(a)}),h.promise},h.prototype.search=function(a,b,c){return c=c||{},c.q=a,c.type=b,this.api("/search","GET",c)},h.prototype.getAlbum=function(a){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/albums/"+a)},h.prototype.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():""})},h.prototype.getAlbumTracks=function(a,b){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/albums/"+a+"/tracks","GET",b)},h.prototype.getArtist=function(a){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/artists/"+a)},h.prototype.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():""})},h.prototype.getArtistAlbums=function(a,b){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/artists/"+a+"/albums","GET",b)},h.prototype.getArtistTopTracks=function(a,b){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/artists/"+a+"/top-tracks","GET",{country:b})},h.prototype.getRelatedArtists=function(a){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/artists/"+a+"/related-artists")},h.prototype.getTrack=function(a){return a=-1===a.indexOf("spotify:")?a:a.split(":")[2],this.api("/tracks/"+a)},h.prototype.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():""})},h.prototype.getUserPlaylists=function(a,b){return this.api("/users/"+a+"/playlists","GET",b,null,{Authorization:"Bearer "+this.authToken})},h.prototype.getPlaylist=function(a,b,c){return this.api("/users/"+a+"/playlists/"+b,"GET",c,null,{Authorization:"Bearer "+this.authToken})},h.prototype.getPlaylistTracks=function(a,b,c){return this.api("/users/"+a+"/playlists/"+b+"/tracks","GET",c,null,{Authorization:"Bearer "+this.authToken})},h.prototype.createPlaylist=function(a,b){return this.api("/users/"+a+"/playlists","POST",null,b,{Authorization:"Bearer "+this.authToken,"Content-Type":"application/json"})},h.prototype.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,{Authorization:"Bearer "+this.authToken,"Content-Type":"application/json"})},h.prototype.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},{Authorization:"Bearer "+this.authToken,"Content-Type":"application/json"})},h.prototype.reorderPlaylistTracks=function(a,b,c){return this.api("/users/"+a+"/playlists/"+b+"/tracks","PUT",null,c,{Authorization:"Bearer "+this.authToken,"Content-Type":"application/json"})},h.prototype.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,{Authorization:"Bearer "+this.authToken,"Content-Type":"application/json"})},h.prototype.updatePlaylistDetails=function(a,b,c){return this.api("/users/"+a+"/playlists/"+b,"PUT",null,c,{Authorization:"Bearer "+this.authToken,"Content-Type":"application/json"})},h.prototype.getUser=function(a){return this.api("/users/"+a)},h.prototype.getCurrentUser=function(){return this.api("/me","GET",null,null,{Authorization:"Bearer "+this.authToken})},h.prototype.getSavedUserTracks=function(a){return this.api("/me/tracks","GET",a,null,{Authorization:"Bearer "+this.authToken})},h.prototype.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,{Authorization:"Bearer "+this.authToken})},h.prototype.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,{Authorization:"Bearer "+this.authToken})},h.prototype.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,{Authorization:"Bearer "+this.authToken,"Content-Type":"application/json"})},h.prototype.getFeaturedPlaylists=function(a){return this.api("/browse/featured-playlists","GET",a,null,{Authorization:"Bearer "+this.authToken})},h.prototype.getNewReleases=function(a){return this.api("/browse/new-releases","GET",a,null,{Authorization:"Bearer "+this.authToken})},h.prototype.follow=function(a,b){return this.api("/me/following","PUT",{type:a,ids:b},null,{Authorization:"Bearer "+this.authToken})},h.prototype.unfollow=function(a,b){return this.api("/me/following","DELETE",{type:a,ids:b},null,{Authorization:"Bearer "+this.authToken})},h.prototype.userFollowingContains=function(a,b){return this.api("/me/following/contains","GET",{type:a,ids:b},null,{Authorization:"Bearer "+this.authToken})},h.prototype.followPlaylist=function(a,b,c){return this.api("/users/"+a+"/playlists/"+b+"/followers","PUT",null,{"public":c||null},{Authorization:"Bearer "+this.authToken,"Content-Type":"application/json"})},h.prototype.unfollowPlaylist=function(a,b){return this.api("/users/"+a+"/playlists/"+b+"/followers","DELETE",null,null,{Authorization:"Bearer "+this.authToken})},h.prototype.playlistFollowingContains=function(a,b,c){return this.api("/users/"+a+"/playlists/"+b+"/followers/contains","GET",{ids:c.toString()},null,{Authorization:"Bearer "+this.authToken})},h.prototype.setAuthToken=function(a){return this.authToken=a,this.authToken},h.prototype.login=function(){function b(a){"spotify-token"===a.key&&(l&&l.close(),d.setAuthToken(a.newValue),g.removeEventListener("storage",b,!1),c.resolve(a.newValue))}var c=e.defer(),d=this,f=400,h=500,i=screen.width/2-f/2,j=screen.height/2-h/2,k={client_id:this.clientId,redirect_uri:this.redirectUri,scope:this.scope||"",response_type:"token"},l=a.open("https://accounts.spotify.com/authorize?"+this.toQueryString(k),"Spotify","menubar=no,location=no,resizable=yes,scrollbars=yes,status=no,width="+f+",height="+h+",top="+j+",left="+i);return g.addEventListener("storage",b,!1),c.promise},new h}]})}(window,angular); \ No newline at end of file diff --git a/package.json b/package.json index e5a83cd..c44006d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-spotify", - "version": "0.12.0", + "version": "0.13.0", "description": "Angular Service to connect to Spotify Web API", "main": "Gruntfile.js", "devDependencies": { diff --git a/src/angular-spotify.js b/src/angular-spotify.js index 01ccf0d..76bbc55 100644 --- a/src/angular-spotify.js +++ b/src/angular-spotify.js @@ -61,7 +61,7 @@ this.redirectUri = settings.redirectUri; this.apiBase = settings.apiBase; this.scope = settings.scope; - this.accessToken = null; + this.accessToken = settings.accessToken; this.toQueryString = utils.toQueryString; }