Spotify Web API SDK | ES6
SDK written in ECMAScript 6. Allows you to use (almost) all Spotify Web API endpoints.
###Diagram
Simple usage
Find (by id)
Artist.find( '7Ey4PD4MYsKc5I2dolUwbH' )
.then( ... );
Search all results
Artist.where( 'aerosmith' )
.then( ... );
Get several items by id
Album.several(['41MnTivkwTO3UUJ8DrqEJJ','6JWc4iAiJ9FjyK0B59ABb4','6UXCm6bOO4gFlDQZV5yL37'])
.then( ... );
Set search parameters
let config = {
limit: 2,
offset: 0,
or: 'Rolling Stones',
market: 'US'
};
Artist.where('aerosmith',config)
.then( ... );
OAuth
import {User,Session} from 'spotify-client';
Session.config({
clientId: 'your client ID',
secretId: 'your secret ID',
scopes: ['playlist-modify-public'],
redirect_uri: 'http://localhost:3000/demo/'
});
let token = window.location.hash.split('&')[0].split('=')[1];
if( token ){
Session.token = token;
} else {
Session.login().then( url => {
window.location.href = url;
});
}
User.findMe().then( me => {
console.log(`I am: ${me.display_name}`);
});
Entity relationship
Get proper entity, not json
Artist.find( '7Ey4PD4MYsKc5I2dolUwbH' )
.then( artist => {
artist.getTopTracks( 'US' )
.then( trackList => {
for( let track of trackList ){
console.log(
`${ track.name } (${ track.duration })`
);
}
});
});
Reference
###All entities
find
Artist.find('Spotify ID')
.then(success, fail);
where
Artist.where('string to search', { exactMatch: true })
.then(success, fail);
get
Track.find('Spotify ID')
.then( track => {
track.get();
});
###Artist
getTopTracks
artist.getTopTracks( 'BR' )
.then(success, fail);
albums
artist.albums()
.all().then(success, fail);
Development
git clone git@github.com:Cosmitar/spotify-client.git
npm install
gulp watch
Open the localhost:3000/demo/index.html and look for console.logs
##Installation
add package.json
dependency "spotify-client": "latest"
run
npm install
import {Artist,Album,Track,User,Playlist,Session} from 'spotify-client';