@jjdenhertog/open-spotify-sdk
Advanced tools
Comparing version 1.0.1 to 1.0.2
import { MaxInt, Playlist, Track } from './../types'; | ||
import EndpointsBase from './EndpointsBase.js'; | ||
export default class PlaylistsEndpoints extends EndpointsBase { | ||
getPlaylist(uri: string, offset?: number, limit?: MaxInt<100>): Promise<Playlist<Track>>; | ||
getFull(uri: string): Promise<Playlist<Track>>; | ||
get(uri: string, offset?: number, limit?: MaxInt<100>): Promise<Playlist<Track>>; | ||
} |
@@ -64,3 +64,34 @@ "use strict"; | ||
} | ||
PlaylistsEndpoints.prototype.getPlaylist = function (uri_1) { | ||
PlaylistsEndpoints.prototype.getFull = function (uri) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var offset, playlist, hasMoreResults, result; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
offset = 0; | ||
return [4 /*yield*/, this.get(uri, offset, 100) | ||
// Check if more tracks can be loaded | ||
]; | ||
case 1: | ||
playlist = _a.sent(); | ||
hasMoreResults = playlist.tracks.offset + playlist.tracks.limit < playlist.tracks.total; | ||
_a.label = 2; | ||
case 2: | ||
if (!hasMoreResults) return [3 /*break*/, 4]; | ||
offset += 100; | ||
return [4 /*yield*/, this.get('spotify:playlist:37i9dQZF1EIhoSaISLaaJc', offset, 100) | ||
// Append tracks | ||
]; | ||
case 3: | ||
result = _a.sent(); | ||
// Append tracks | ||
playlist.tracks.items = playlist.tracks.items.concat(result.tracks.items); | ||
hasMoreResults = result.tracks.offset + result.tracks.limit < result.tracks.total; | ||
return [3 /*break*/, 2]; | ||
case 4: return [2 /*return*/, playlist]; | ||
} | ||
}); | ||
}); | ||
}; | ||
PlaylistsEndpoints.prototype.get = function (uri_1) { | ||
return __awaiter(this, arguments, void 0, function (uri, offset, limit) { | ||
@@ -67,0 +98,0 @@ var url, data, playlistV2, images, content, pagingInfo, totalCount, result; |
@@ -6,3 +6,1 @@ "use strict"; | ||
Object.defineProperty(exports, "OpenSpotifyApi", { enumerable: true, get: function () { return OpenSpotifyApi_js_1.OpenSpotifyApi; } }); | ||
var test = new OpenSpotifyApi_js_1.OpenSpotifyApi(); | ||
test.playlists.getPlaylist('spotify:playlist:37i9dQZF1EIhoSaISLaaJc'); |
{ | ||
"name": "@jjdenhertog/open-spotify-sdk", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A typescript SDK for the Open Spotify Web API", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -33,3 +33,9 @@ # Spotify Open Web API SDK - TypeScript | ||
```typescript | ||
const playlist = await sdk.playlists.getFull('spotify:playlist:37i9dQZF1EIhoSaISLaaJc') | ||
``` | ||
Or if you prefer to do the operation manually it would look like this. | ||
```typescript | ||
let offset = 0; | ||
@@ -47,3 +53,3 @@ const limit = 50; | ||
// Append tracks | ||
playlist.tracks = playlist.tracks.concat(result.tracks) | ||
playlist.tracks.items = playlist.tracks.items.concat(result.tracks.items) | ||
hasMoreResults = result.tracks.offset + result.tracks.limit < result.tracks.total; | ||
@@ -50,0 +56,0 @@ } |
42623
795
67