UNPKG

fitbit-api-client

Version:
38 lines 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseApi = void 0; const constants_1 = require("../constants"); const models_1 = require("../models"); class BaseApi { async fetchAPI(path, options) { const { accessToken, headers = {}, ...fetchOptions } = options; const { Authorization, ['Content-Type']: contentType = 'application/json', ...fetchHeaders } = headers; const response = await fetch(`${constants_1.FITBIT_API_BASE_URL}${path}`, { ...fetchOptions, headers: { ...fetchHeaders, Authorization: Authorization ?? `Bearer ${accessToken}`, 'Content-Type': contentType, }, }); if (response.ok) { return await response.json(); } throw new models_1.ResponseError(response, `${response.status} ${response.statusText}`); } async get(path, options) { return this.fetchAPI(path, { method: 'GET', ...options, }); } async post(path, body, options) { return this.fetchAPI(path, { method: 'POST', body, ...options, }); } } exports.BaseApi = BaseApi; //# sourceMappingURL=base.api.js.map