Skip to content

Commit e12cdd3

Browse files
added "add song to queue" method (#302)
* added add song to queue * updated readme with new feature * Minor changes Make minor changes in method and argument names. Co-authored-by: thelinmichael <[email protected]>
1 parent d1fa31a commit e12cdd3

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

__tests__/spotify-web-api.js

+25
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,31 @@ describe('Spotify Web API', () => {
17881788
});
17891789
});
17901790

1791+
test("should add songs to the user's queue:", done => {
1792+
sinon.stub(HttpManager, '_makeRequest', function(
1793+
method,
1794+
options,
1795+
uri,
1796+
callback
1797+
) {
1798+
expect(method).toBe(superagent.post);
1799+
expect(uri).toBe('https://api.spotify.com/v1/me/player/queue');
1800+
expect(options.query).toEqual({
1801+
uri: 'spotify:track:2jpDioAB9tlYXMdXDK3BGl'
1802+
});
1803+
expect(options.headers).toEqual({
1804+
Authorization: 'Bearer someAccessToken'
1805+
});
1806+
callback(null, null);
1807+
});
1808+
1809+
var api = new SpotifyWebApi({
1810+
accessToken: 'someAccessToken'
1811+
});
1812+
1813+
api.addToQueue('spotify:track:2jpDioAB9tlYXMdXDK3BGl').then(done);
1814+
});
1815+
17911816
test("should get user's devices:", done => {
17921817
sinon.stub(HttpManager, '_makeRequest').callsFake(function(
17931818
method,

src/spotify-web-api.js

+22
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,28 @@ SpotifyWebApi.prototype = {
10291029
},
10301030

10311031
/**
1032+
1033+
* Add track or episode to device queue
1034+
* @param {string} [uri] uri of the track or episode to add
1035+
* @param {Object} [options] Options, being device_id.
1036+
* @param {requestCallback} [callback] Optional callback method to be called instead of the promise.
1037+
* @returns {Promise|undefined} A promise that if successful, resolves into a paging object of tracks,
1038+
* otherwise an error. Not returned if a callback is given.
1039+
*/
1040+
addToQueue: function(uri, options, callback) {
1041+
return WebApiRequest.builder(this.getAccessToken())
1042+
.withPath('/v1/me/player/queue')
1043+
.withQueryParameters(
1044+
{
1045+
uri: uri
1046+
},
1047+
options
1048+
)
1049+
.build()
1050+
.execute(HttpManager.post, callback);
1051+
},
1052+
1053+
10321054
* Get the Current User's Available Devices
10331055
* @param {requestCallback} [callback] Optional callback method to be called instead of the promise.
10341056
* @returns {Promise|undefined} A promise that if successful, resolves into an array of device objects,

0 commit comments

Comments
 (0)