Socket
Socket
Sign inDemoInstall

spotify-client

Package Overview
Dependencies
0
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    spotify-client

SDK written in ECMAScript 6. Allows you to use (almost) all [Spotify Web API](https://developer.spotify.com/web-api/) endpoints.


Version published
Maintainers
1
Created

Readme

Source

Spotify Web API SDK | ES6

SDK written in ECMAScript 6. Allows you to use (almost) all Spotify Web API endpoints.

###Diagram alt tag

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

##Instalation add package.json dependency "spotify-client": "latest"

run npm install

import {Artist,Album,Track,User,Playlist,Session} from 'spotify-client';

Simple usage

Find (by id)

Artist.find( '7Ey4PD4MYsKc5I2dolUwbH' )
	.then( ... );

Search all results

Artist.where( 'aerosmith' ).all()
	.then( ... );

I'm feeling lucky

Artist.where( 'aerosmith' ).first()
	.then( ... )

Methods from above are also available for Album, Track, Playlist and User entities.

OAuth

import {User,Session} from 'spotify-client';

Session.config({
    clientId: '1dd4ae27b3fc480ebf627679e5bb0e17', 
    secretId: '31e8696e70574648b55b6fcc7c5b1135',
    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 => {
	//get top tracks for this artist in the US
	artist.getTopTracks( 'US' )
	.then( trackList => {
		//each element is an object of class Track
		//so you can get human-readable duration for the current track
		for( let track of trackList ){
			console.log(
				`${ track.name } (${ track.duration })`
			);
		}
	});
});

Reference

###All entities find

/**
* Finds an entity by its Spotify ID.
* @param {string} id Spotify ID.
* @return {Promise}
*/
Artist.find('Spotify ID')
    .then(success, fail);

where

/**
* Initializes a conditional query with the given parameter.
* @param {string|object} condition A string to find by q parameter, or an object with search config.
* @return {Browser}
*/
Artist.where('string to search');

get

/**
* Obtains a full (instead of simplified) object from source.
*/
Track.find('Spotify ID')
    .then( track => {
        track.get();//loads full object
    });

###Artist getTopTracks

/**
* Retrieves the top-tracks for the artist. 
* @param {string} country The country for the search (ISO 3166-1 alpha-2 country code)
* @return {Promise}
*/
artist.getTopTracks( 'BR' )
    .then(success, fail);

albums

/**
* Initializes a conditional query for the artist's albums.
* @return {Browser}
*/
artist.albums()
    .all().then(success, fail);

Keywords

FAQs

Last updated on 10 Nov 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc