Skip to content

Commit 3dfb135

Browse files
authored
Add support for "Get a Playlist Cover Image" endpoint - Fixes #162 (#163)
1 parent e31d735 commit 3dfb135

File tree

6 files changed

+68
-0
lines changed

6 files changed

+68
-0
lines changed

__test__/fixtures.js

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module.exports = {
4444
user_top_tracks: loadFixture('user_top_tracks'),
4545
playlist: loadFixture('playlist'),
4646
playlist_tracks: loadFixture('playlist_tracks'),
47+
playlist_cover_image: loadFixture('playlist_cover_image'),
4748
featured_playlists: loadFixture('featured_playlists'),
4849
browse_categories: loadFixture('browse_categories'),
4950
category: loadFixture('category'),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"height": 640,
4+
"url": "https://u.scdn.co/images/pl/default/438f9b65ac4eb48681351593142daeb070986293",
5+
"width": 640
6+
}
7+
]

__test__/spotify-web-api.spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,25 @@ describe('Basic tests', function () {
873873
);
874874
});
875875

876+
it('should get cover image of a playlist', function () {
877+
var callback = sinon.spy();
878+
var api = new SpotifyWebApi();
879+
api.setAccessToken('<example_access_token>');
880+
api.getPlaylistCoverImage('3cEYpjA9oz9GiPac4AsH4n', callback);
881+
that.requests[0].respond(
882+
200,
883+
{ 'Content-Type': 'application/json' },
884+
JSON.stringify(fixtures.playlist_cover_image)
885+
);
886+
expect(
887+
callback.calledWith(null, fixtures.playlist_cover_image)
888+
).toBeTruthy();
889+
expect(that.requests.length).toBe(1);
890+
expect(that.requests[0].url).toBe(
891+
'https://api.spotify.com/v1/playlists/3cEYpjA9oz9GiPac4AsH4n/images'
892+
);
893+
});
894+
876895
it('should create a playlist', function () {
877896
var callback = sinon.spy();
878897
var api = new SpotifyWebApi();

src/spotify-web-api.js

+18
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,24 @@ var SpotifyWebApi = (function () {
759759
return _checkParamsAndPerformRequest(requestData, options, callback);
760760
};
761761

762+
/**
763+
* Gets the current image associated with a specific playlist.
764+
* See [Get a Playlist Cover Image](https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist-cover/) on
765+
* the Spotify Developer site for more information about the endpoint.
766+
*
767+
* @param {string} playlistId The id of the playlist. If you know the Spotify URI it is easy
768+
* to find the playlist id (e.g. spotify:playlist:<here_is_the_playlist_id>)
769+
* @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first
770+
* one is the error object (null if no error), and the second is the value if the request succeeded.
771+
* @return {Object} Null if a callback is provided, a `Promise` object otherwise
772+
*/
773+
Constr.prototype.getPlaylistCoverImage = function (playlistId, callback) {
774+
var requestData = {
775+
url: _baseUri + '/playlists/' + playlistId + '/images'
776+
};
777+
return _checkParamsAndPerformRequest(requestData, callback);
778+
};
779+
762780
/**
763781
* Creates a playlist and stores it in the current user's library.
764782
* See [Create a Playlist](https://developer.spotify.com/web-api/create-playlist/) on

src/typings/spotify-api.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,13 @@ declare namespace SpotifyApi {
706706
*/
707707
interface UploadCustomPlaylistCoverImageResponse extends VoidResponse {}
708708

709+
/**
710+
* Get a Playlist Cover Image
711+
* GET /v1/playlists/{playlist_id}/images
712+
* https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist-cover/
713+
*/
714+
interface PlaylistCoverImageResponse extends Array<ImageObject> {}
715+
709716
/**
710717
* Check if Users Follow a Playlist
711718
*

src/typings/spotify-web-api.d.ts

+16
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,22 @@ declare namespace SpotifyWebApi {
502502
callback?: ResultsCallback<SpotifyApi.PlaylistTrackResponse>
503503
): Promise<SpotifyApi.PlaylistTrackResponse>;
504504

505+
/**
506+
* Gets the current image associated with a specific playlist.
507+
* See [Get a Playlist Cover Image](https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist-cover/) on
508+
* the Spotify Developer site for more information about the endpoint.
509+
*
510+
* @param {string} playlistId The id of the playlist. If you know the Spotify URI it is easy
511+
* to find the playlist id (e.g. spotify:playlist:<here_is_the_playlist_id>)
512+
* @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first
513+
* one is the error object (null if no error), and the second is the value if the request succeeded.
514+
* @return {Object} Null if a callback is provided, a `Promise` object otherwise
515+
*/
516+
getPlaylistCoverImage(
517+
playlistId: string,
518+
callback?: ResultsCallback<SpotifyApi.PlaylistCoverImageResponse>
519+
): Promise<SpotifyApi.PlaylistCoverImageResponse>;
520+
505521
/**
506522
* Creates a playlist and stores it in the current user's library.
507523
* See [Create a Playlist](https://developer.spotify.com/web-api/create-playlist/) on

0 commit comments

Comments
 (0)