spotify-ts-wrapper
Version:
Spotify TypeScript wrapper.
39 lines (38 loc) • 2.46 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getGenre = getGenre;
const Context_1 = require("../Structure/Context");
const RequestClient_1 = require("../Structure/RequestClient");
const url_modifiers_1 = require("../Modifiers/url+modifiers");
const genre_parser_1 = require("../Parser/genre.parser");
function getGenre(options) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h;
const token = yield RequestClient_1.client.getAccessToken();
const context = (0, Context_1.createSpotifyAuthorizationContext)(token);
const params = (0, url_modifiers_1.createSpotifyParams)({
id: options.pageId,
pagePagination: {
limit: (_b = (_a = options.pagePagination) === null || _a === void 0 ? void 0 : _a.limit) !== null && _b !== void 0 ? _b : 10,
offset: (_d = (_c = options.pagePagination) === null || _c === void 0 ? void 0 : _c.offSet) !== null && _d !== void 0 ? _d : 0,
},
sectionPagination: {
limit: (_f = (_e = options.sectionPagination) === null || _e === void 0 ? void 0 : _e.limit) !== null && _f !== void 0 ? _f : 10,
offset: (_h = (_g = options.sectionPagination) === null || _g === void 0 ? void 0 : _g.offSet) !== null && _h !== void 0 ? _h : 0,
},
});
const spotifyResolvedObjectURL = (0, url_modifiers_1.getSpotifyURL)(params);
const doubleEncodedURL = (0, url_modifiers_1.fixDoubleEncodedUrl)(spotifyResolvedObjectURL);
const fetchRequest = yield RequestClient_1.client.request(doubleEncodedURL, Object.assign({}, context));
return (0, genre_parser_1.genreParser)(fetchRequest);
});
}