spotify-finder
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -167,8 +167,19 @@ 'use strict' | ||
getArtist (id, opts, callback) { | ||
let params | ||
let url = `${this.endpoints.artists}/${id}` | ||
const country = opts && opts.country ? opts.country : 'SE' | ||
if (opts && opts.albums) url += '/albums' | ||
else if (opts && opts.topTracks) url += '/top-tracks' | ||
else if (opts && opts.relatedArtists) url += '/related-artists' | ||
if (opts) { | ||
if (opts.albums) { | ||
url += '/albums' | ||
delete opts.albums | ||
} else if (opts.topTracks) { | ||
url += '/top-tracks' | ||
delete opts.topTracks | ||
} else if (opts.relatedArtists) { | ||
url += '/related-artists' | ||
delete opts.relatedArtists | ||
} | ||
params = Object.assign(opts, { country }) | ||
} | ||
@@ -178,7 +189,7 @@ /* istanbul ignore else */ | ||
return Promise | ||
.resolve(this.fetch(url, { country })) | ||
.resolve(this.fetch(url, params)) | ||
.asCallback(callback) | ||
} | ||
return Promise.resolve(this.fetch(url, { country })) | ||
return Promise.resolve(this.fetch(url, params)) | ||
} | ||
@@ -274,9 +285,14 @@ | ||
/* istanbul ignore else */ | ||
if (opts && opts.hasOwnProperty('playlists')) { | ||
delete opts.playlists | ||
} | ||
/* istanbul ignore else */ | ||
if (callback) { | ||
return Promise | ||
.resolve(this.fetchOAuth(url)) | ||
.resolve(this.fetchOAuth(url, opts)) | ||
.asCallback(callback) | ||
} | ||
return Promise.resolve(this.fetchOAuth(url)) | ||
return Promise.resolve(this.fetchOAuth(url, opts)) | ||
} | ||
@@ -283,0 +299,0 @@ } |
{ | ||
"name": "spotify-finder", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "A isomorphic Spotify API client", | ||
@@ -5,0 +5,0 @@ "main": "lib/client.js", |
@@ -49,3 +49,8 @@ # spotify-finder | ||
```js | ||
client.browse({ to: 'new-releases' }) | ||
const params = { | ||
to: 'new-releases', // required | ||
limit: 5, // optional for default 20 | ||
offset: 5 // optional for default 0 | ||
} | ||
client.browse(params) | ||
.then(albums => { | ||
@@ -64,3 +69,3 @@ // do something with album's | ||
```js | ||
client.browse({ to: 'categories' } | ||
client.browse({ to: 'categories' }) | ||
.then(categories => { | ||
@@ -70,3 +75,22 @@ // do something with categories | ||
``` | ||
#### Get a Category by id | ||
```js | ||
client.getCategory('toptrack') | ||
.then(category => { | ||
// do something with category | ||
}) | ||
``` | ||
#### Get a Category’s Playlists | ||
```js | ||
const params = { | ||
playlists: true, // required | ||
limit: 5, // optional for default 20 | ||
offset: 5, // optional for default 0 | ||
country: 'BR' // optional for default 'SE' | ||
} | ||
client.getCategory('toptrack', params) | ||
.then(playlists => { | ||
// do something with playlists | ||
}) | ||
``` | ||
#### Get album by id | ||
@@ -106,3 +130,9 @@ ```js | ||
```js | ||
client.getArtist('6S2OmqARrzebs0tKUEyXyp', { albums: true }) | ||
const params = { | ||
albums: true, // required | ||
album_type: 'album,single', // optional for default all types | ||
limit: 5, // optional for default 20 | ||
offset: 5 // optional for default 0 | ||
} | ||
client.getArtist('6S2OmqARrzebs0tKUEyXyp', params) | ||
.then(albums => { | ||
@@ -109,0 +139,0 @@ // do something with albums |
@@ -28,3 +28,3 @@ 'use strict' | ||
client.getCategory(catId, { playlists: false }).then((category) => { | ||
client.getCategory(catId).then((category) => { | ||
t.equals(typeof category, 'object', 'should be a object') | ||
@@ -41,3 +41,3 @@ t.equals(category.id, catId, 'should retrive a category id') | ||
nock(config.url, { reqheaders: headers }) | ||
.get(`/browse/categories/${catId}/playlists`) | ||
.get(`/browse/categories/${catId}/playlists?`) | ||
.reply(200, response) | ||
@@ -61,3 +61,3 @@ | ||
nock(config.url, { reqheaders: headers }) | ||
.get(`/browse/categories/${catId}`) | ||
.get(`/browse/categories/${catId}?`) | ||
.reply(200, response) | ||
@@ -64,0 +64,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31289
741
180