spotify-service-rg
Version:
This is a Angular service for connecting to and using Spotify API.
2 lines • 4.91 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common/http")):"function"==typeof define&&define.amd?define("spotify-service-rg",["exports","@angular/core","@angular/common/http"],e):e(t["spotify-service-rg"]={},t.ng.core,t.ng.common.http)}(this,function(t,e,r){"use strict";var n=function(){function t(t){this.http=t,this.baseUrl="https://api.spotify.com/v1"}return t.prototype.login=function(){window.location.href="https://accounts.spotify.com/authorize?response_type=token&client_id="+this.clientId+(this.scopes?"&scope="+encodeURIComponent(this.scopes):"")+"&redirect_uri="+encodeURIComponent(this.callBackUrl)},t.prototype.setClientId=function(t){this.clientId=t},t.prototype.setCallBackUrl=function(t){this.callBackUrl=t},t.prototype.setScopes=function(t){this.scopes=t},t.prototype.setToken=function(t){this.token=t},t.prototype.getTrack=function(t){return this.apiGet("/tracks/"+t,null,this.getHeaders())},t.prototype.getTracks=function(t){var e=encodeURIComponent(t);return this.apiGet("/tracks/?ids="+e,null,this.getHeaders())},t.prototype.getAlbum=function(t){return this.apiGet("/albums/"+t,null,this.getHeaders())},t.prototype.getAlbums=function(t){var e=encodeURIComponent(t);return this.apiGet("/albums/?ids="+e,null,this.getHeaders())},t.prototype.getAlbumsTracks=function(t){return this.apiGet("/albums/"+t+"/tracks",null,this.getHeaders())},t.prototype.getArtist=function(t){return this.apiGet("/artists/"+t,null,this.getHeaders())},t.prototype.getArtists=function(t){var e=encodeURIComponent(t);return this.apiGet("/artists/?ids="+e,null,this.getHeaders())},t.prototype.getArtistsAlbums=function(t){return this.apiGet("/artists/"+t+"/albums",null,this.getHeaders())},t.prototype.getArtistsTopTracks=function(t,e){e=null!=e&&2==e.length?e:"from_token";return this.apiGet("/artists/"+t+"/top-tracks?country="+e,null,this.getHeaders())},t.prototype.getUserById=function(t){return this.apiGet("/users/"+t,null,this.getHeaders())},t.prototype.getUser=function(){return this.apiGet("/me",null,this.getHeaders())},t.prototype.getUsersTopTracks=function(t,e){var r={time_range:null==t?"long_term":t,limit:null==e?"50":e};return this.apiGet("/me/top/tracks",r,this.getHeaders())},t.prototype.getUsersPlaylists=function(t){return this.apiGet("/users/"+t+"/playlists",null,this.getHeaders())},t.prototype.getRecommendedTracks=function(t,e){var r=encodeURIComponent(t),n=encodeURIComponent(e);return this.apiGet("/recommendations?limit=50&seed_artists="+r+"&seed_tracks="+n,null,this.getHeaders())},t.prototype.getNewReleases=function(t,e){var r="";return null!=t&&""!=t&&(r+="?country="+t),null!=e&&""!=e&&(r+=0==r.length?"?":"&",r+="limit="+e),this.apiGet("/browse/new-releases"+r,null,this.getHeaders())},t.prototype.getFeaturedPlaylists=function(t,e){var r="";return null!=t&&""!=t&&(r+="?country="+t),null!=e&&""!=e&&(r+=0==r.length?"?":"&",r+="limit="+e),this.apiGet("/browse/featured-playlists"+r,null,this.getHeaders())},t.prototype.getCategory=function(t){return this.apiGet("/browse/categories/"+t,null,this.getHeaders())},t.prototype.getCategories=function(t,e){var r="";return null!=t&&""!=t&&(r+="?country="+t),null!=e&&""!=e&&(r+=0==r.length?"?":"&",r+="limit="+e),this.apiGet("/browse/categories"+r,null,this.getHeaders())},t.prototype.getCategorysPlaylists=function(t,e,r){var n="";return null!=e&&""!=e&&(n+="?country="+e),null!=r&&""!=r&&(n+=0==n.length?"?":"&",n+="limit="+r),this.apiGet("/browse/categories/"+t+"/playlists"+n,null,this.getHeaders())},t.prototype.createPlayList=function(t,e,r,n){var o={name:e,description:r,"public":n};return this.apiPost("/me/playlists?user_id="+t,o,this.getHeaders())},t.prototype.addTracksToPlaylist=function(t,e){var r={uris:e};return this.apiPost("/playlists/"+t+"/tracks",r,this.getHeaders())},t.prototype.search=function(t,e,r){var n=encodeURIComponent(t),o=encodeURIComponent(e);return this.apiGet("/search?q="+n+"&type="+o+"&limit="+r,null,this.getHeaders())},t.prototype.apiGet=function(t,e,r){return this.http.get(this.baseUrl+t,{params:e,headers:r,withCredentials:!1}).toPromise()},t.prototype.apiPost=function(t,e,r){return this.http.post(this.baseUrl+t,e,{headers:r}).toPromise()},t.prototype.getHeaders=function(){return{Authorization:"Bearer "+this.token,Accept:"application/json","Content-Type":"application/json"}},t.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}],t.ctorParameters=function(){return[{type:r.HttpClient}]},t.ngInjectableDef=e.defineInjectable({factory:function(){return new t(e.inject(r.HttpClient))},token:t,providedIn:"root"}),t}(),o=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{declarations:[],imports:[r.HttpClientModule],exports:[]}]}],t}();t.SpotifyRgService=n,t.SpotifyServiceRgModule=o,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=spotify-service-rg.umd.min.js.map