"use strict"; 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HereClient = void 0; const node_fetch_1 = __importDefault(require("node-fetch")); const BASE_URL = "https://traffic.ls.hereapi.com"; const TRAFFIC_PATH = "traffic/6.1"; class HereClient { constructor(apiKey) { this.apiKey = apiKey; } flow(position, units = "metric") { return __awaiter(this, void 0, void 0, function* () { const prox = `${position.latitude},${position.longitude},${position.distance}`; const urlPath = `${TRAFFIC_PATH}/flow.json`; return this.get(urlPath, { prox, units }); }); } get(urlPath, params) { return __awaiter(this, void 0, void 0, function* () { let url = `${BASE_URL}/${urlPath}`; if (!params) params = {}; params.apiKey = this.apiKey; params.responseattributes = "shape"; url += "?"; url += Object.entries(params) .map(([key, value]) => `${key}=${value}`) .join("&"); return node_fetch_1.default(url).then(res => res.json()); }); } } exports.HereClient = HereClient; //# sourceMappingURL=HereClient.js.map