UNPKG

@remcostoeten/fync

Version:

A unified TypeScript library for easy access to popular APIs (GitHub, Spotify, GitLab, etc.)

73 lines (72 loc) 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createSpotifyClient = createSpotifyClient; var _chainable = require("../../core/chainable"); var _http = require("../utils/http"); function createSpotifyChainableClient(config) { const spotifyHttpClient = (0, _http.createHttpClient)({ clientId: "", clientSecret: "", accessToken: config.token, baseUrl: config.baseUrl || "https://api.spotify.com/v1", cache: config.cache, cacheTTL: config.cacheTTL }); async function getMethod(path, params) { return { data: await spotifyHttpClient.get(path) }; } async function postMethod(path, data) { return { data: await spotifyHttpClient.post(path, data) }; } async function putMethod(path, data) { return { data: await spotifyHttpClient.put(path, data) }; } async function patchMethod(path, data) { return { data: await spotifyHttpClient.put(path, data) }; } async function deleteMethod(path, data) { return { data: await spotifyHttpClient.delete(path, data) }; } const adaptedHttpClient = { get: getMethod, post: postMethod, put: putMethod, patch: patchMethod, delete: deleteMethod }; return (0, _chainable.createChainableClient)(config, adaptedHttpClient, { cacheKeyPrefix: "spotify", supportsPagination: false, defaultOptions: { params: { ...(config.limit && { limit: config.limit }), ...(config.after && { after: config.after }), ...(config.before && { before: config.before }), ...(config.immediate && { immediate: config.immediate }) } } }); } function createSpotifyClient(config = {}) { return createSpotifyChainableClient(config); }