Skip to content

mateussmohamed/spotifood-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

91 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Spotifood Wrapper [WIP 🚧]

Build Status Coverage Status

A wrapper for consume the Spotify Web API.

⚠️ Disclaimer ⚠️

The authentication method should be refactored. The api used in the authorization is only for server-side request, and ajax requests do not work

For correct operation, I recommend using CORS Domain extensions.

CORS Everywhere for Firefox

Allow-Control-Allow-Origin: * for Chrome

Browser Support

This library relies on Fetch API. And this API is supported in the following browsers.

Chrome Firefox Opera Safari IE
39+ βœ” 42+ βœ” 29+ βœ” 10.1+ βœ” Nope ✘

Dependencies

  • js-cookie A simple, lightweight JavaScript API for handling browser cookies

This library depends on fetch to make requests to the Spotify Web API. For environments that don't support fetch, you'll need to provide a polyfill to browser or polyfill to Node.

Installation

$ npm install spotifood-wrapper --save

or

$ yarn add spotifood-wrapper

How to use

ES6

// to import a specific method
import Spotifood from 'spotifood-wrapper';

const spotify = new Spotifood({
  clientID: 'YOUR_CLIENT_ID_HERE',
  clientSecret: 'YOUR_CLIENT_SECRET_HERE'
});

// using  method
spotifood.search.artists('Incubus');

CommonJS

const Spotifood = require('spotifood-wrapper');

const spotify = new Spotifood({
  clientID: 'YOUR_CLIENT_ID_HERE',
  clientSecret: 'YOUR_CLIENT_SECRET_HERE'
});

UMD in Browser

<!-- to import non-minified version -->
<script src="spotifood-wrapper.umd.js"></script>

<!-- to import minified version -->
<script src="spotifood-wrapper.umd.min.js"></script>

After that the library will be available to the Global as Spotifood. Follow an example:

const spotify = new Spotifood({
  clientID: 'YOUR_CLIENT_ID_HERE',
  clientSecret: 'YOUR_CLIENT_SECRET_HERE'
});

const albums = spotifood.search.albums('Choosen Artist');

Methods

Follow the methods that the library provides.

browse.featuredPlaylists(params)

Search for informations about Albums with provided query. Test in Spotify Web Console with type defined as album.

Arguments

Argument Type Options
filters Object An object filters
locale String A locale code
country String A country code
timestamp String A timestamp
offset String Limit of items
  • All params is optionals

Example

const filters = { 
  locale: 'pt_BR',
  country: 'BR',
  timestamp: '',
  offset: 2
};

spotifood.browse.featuredPlaylists(filters)
  .then(data => {
    // do what you want with the data
  })

search.albums(query)

Arguments

Argument Type Options
query string 'Any search query'

Example

spotifood.search.albums('Incubus')
  .then(data => {
    // do what you want with the data
  })

search.artists(query)

Arguments

Argument Type Options
query string 'Any search query'

Example

spotifood.search.artists('Incubus')
  .then(data => {
    // do what you want with the data
  })

search.tracks(query)

Arguments

Argument Type Options
query string 'Any search query'

Example

spotifood.search.tracks('Drive')
  .then(data => {
    // do what you want with the data
  })

search.playlists(query)

Arguments

Argument Type Options
query string 'Any search query'

Example

spotifood.search.playlists('Happy Day')
  .then(data => {
    // do what you want with the data
  })

album.getAlbum(id)

Arguments

Argument Type Options
id string 'Specific id'

Example

spotifood.album.getAlbum('4aawyAB9vmqN3uQ7FjRGTy')
  .then(data => {
    // do what you want with the data
  })

album.getAlbums(ids)

Arguments

Argument Type Options
ids Array of strings ['id1', 'id2']

Example

spotifood.album.getAlbums(['4aawyAB9vmqN3uQ7FjRGTy', '1A2GTWGtFfWp7KSQTwWOyo'])
  .then(data => {
    // do what you want with the data
  })

album.getTracks(id)

Arguments

Argument Type Options
id string 'Specific id'

Example

spotifood.album.getTracks('4aawyAB9vmqN3uQ7FjRGTy')
  .then(data => {
    // do what you want with the data
  })

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Author

Mateus Santana
Mateus Santana

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

A wrapper for consume the Spotify Web API

Resources

License

Stars

Watchers

Forks

Packages

No packages published