UNPKG

google-trends-api-client

Version:

An fully typed and easy to use client for the google trends api.

40 lines 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getInterestOverTime = void 0; const UnexpectedCodePathError_1 = require("../utils/errors/UnexpectedCodePathError"); const defineCommonGoogleTrendsApiParametersValue_1 = require("../assertions/defineCommonGoogleTrendsApiParametersValue"); const getExplorationWidgets_1 = require("./getExplorationWidgets"); const getFromApiCall_1 = require("./getFromApiCall"); /** * per google * > Numbers represent search interest relative to the highest point on the chart for the given region and time. * > - A value of 100 is the peak popularity for the term. * > - A value of 50 means that the term is half as popular. * > - A score of 0 means there was not enough data for this term. */ const getInterestOverTime = async (...args) => { // get the exploration widgets for this request, which give us the request token and params to get the related queries data const { widgets } = await (0, getExplorationWidgets_1.getExplorationWidgets)(...args); // find the relevant widget const relevantWidget = widgets.find((widget) => widget.id === 'TIMESERIES'); if (!relevantWidget) throw new UnexpectedCodePathError_1.UnexpectedCodePathError('could not find widget with id TIMESERIES'); // make the the request for the widgets data const response = await (0, getFromApiCall_1.getFromApiCall)({ path: 'trends/api/widgetdata/multiline', agentOptions: args[1], queryParams: { ...(0, defineCommonGoogleTrendsApiParametersValue_1.defineCommonGoogleTrendsApiParametersValue)({ hl: args[0].hl, tz: args[0].tz, }), req: JSON.stringify(relevantWidget.request), token: relevantWidget.token, }, }); const result = JSON.parse(response); return result.default .timelineData; }; exports.getInterestOverTime = getInterestOverTime; //# sourceMappingURL=getInterestOverTime.js.map