spotify-ts-wrapper
Version:
Spotify TypeScript wrapper.
35 lines (34 loc) • 2.36 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.search = search;
const RequestClient_1 = require("../Structure/RequestClient");
const url_modifiers_1 = require("../Modifiers/url+modifiers");
const url_modifiers_2 = require("../Modifiers/url+modifiers");
const Context_1 = require("../Structure/Context");
const search_parser_1 = require("../Parser/search.parser");
function search(options) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e;
const token = yield RequestClient_1.client.getAccessToken();
const context = (0, Context_1.createSpotifyAuthorizationContext)(token);
const params = (0, url_modifiers_2.createSpotifySearchAllParams)({
query: options.query,
offSet: (_b = (_a = options === null || options === void 0 ? void 0 : options.pagePagination) === null || _a === void 0 ? void 0 : _a.offSet) !== null && _b !== void 0 ? _b : 0,
limit: (_d = (_c = options === null || options === void 0 ? void 0 : options.pagePagination) === null || _c === void 0 ? void 0 : _c.limit) !== null && _d !== void 0 ? _d : 10,
topResults: (_e = options === null || options === void 0 ? void 0 : options.topResults) !== null && _e !== void 0 ? _e : 5,
});
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, search_parser_1.searchParser)(fetchRequest);
});
}