UNPKG

n8n-nodes-base

Version:

Base nodes of n8n

46 lines 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.coinGeckoApiRequest = coinGeckoApiRequest; exports.coinGeckoRequestAllItems = coinGeckoRequestAllItems; const n8n_workflow_1 = require("n8n-workflow"); async function coinGeckoApiRequest(method, endpoint, body = {}, qs = {}, uri, option = {}) { let options = { headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, method, body, qs, uri: uri || `https://api.coingecko.com/api/v3${endpoint}`, json: true, }; options = Object.assign({}, options, option); try { if (Object.keys(body).length === 0) { delete options.body; } return await this.helpers.request.call(this, options); } catch (error) { throw new n8n_workflow_1.NodeApiError(this.getNode(), error); } } async function coinGeckoRequestAllItems(propertyName, method, endpoint, body = {}, query = {}) { const returnData = []; let responseData; let respData; query.per_page = 250; query.page = 1; do { responseData = await coinGeckoApiRequest.call(this, method, endpoint, body, query); query.page++; respData = responseData; if (propertyName !== '') { respData = responseData[propertyName]; } returnData.push.apply(returnData, respData); } while (respData.length !== 0); return returnData; } //# sourceMappingURL=GenericFunctions.js.map