Skip to content

Commit

Permalink
Merge pull request #13 from mapup/refactor-scripts
Browse files Browse the repository at this point in the history
Refactor scripts to extract variables to global scope
  • Loading branch information
vishalbd authored Mar 11, 2024
2 parents 8d2c045 + 685febe commit 8d536b0
Show file tree
Hide file tree
Showing 7 changed files with 485 additions and 709 deletions.
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,4 @@ Support for barrier, ticket system and distance based tolling configurations
### Support for trucks based on [height, weight, harardous goods, etc.](https://github.com/mapup/toll-here-maps/wiki/4.-Truck-parameters-supported-by-TollGuru)
You can receive tolls based on vehicle height, weight etc., while calculating toll: "truckType","shippedHazardousGoods","tunnelCategory","truckRestrictionPenalty" and [more](https://github.com/mapup/toll-here-maps/wiki/4.-Truck-parameters-supported-by-TollGuru).








For more examples of the different ways in which the responses from this endpoint can be configured, you can refer to: [Our API parameter examples repository.](https://github.com/mapup/tollguru-api-parameter-examples/tree/main/request-bodies/02-Complete-Polyline-To-Toll)
58 changes: 33 additions & 25 deletions javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,33 @@ const request = require("request");
const polyline = require("polyline");
const flexPoly = require("./flex_poly");

// REST API key from Here Maps
const key = process.env.HEREMAP_KEY
const tollguruKey = process.env.TOLLGURU_KEY;

// Dallas, TX
const source = {
longitude: '-96.7970',
latitude: '32.7767',
const HERE_API_KEY = process.env.HERE_API_KEY;
const HERE_API_URL = "https://router.hereapi.com/v8/routes";

const TOLLGURU_API_KEY = process.env.TOLLGURU_API_KEY;
const TOLLGURU_API_URL = "https://apis.tollguru.com/toll/v2";
const POLYLINE_ENDPOINT = "complete-polyline-from-mapping-service";

const source = { latitude: -75.16218, longitude: 39.95222, }; // Philadelphia, PA
const destination = { latitude: -74.0060, longitude: 40.7128 }; // New York, NY

// Explore https://tollguru.com/toll-api-docs to get the best of all the parameters that tollguru has to offer
const requestParameters = {
"vehicle": {
"type": "2AxlesAuto",
},
// Visit https://en.wikipedia.org/wiki/Unix_time to know the time format
"departure_time": "2021-01-05T09:46:08Z",
}

// New York, NY
const destination = {
longitude: '-74.0060',
latitude: '40.7128'
};

const url = `https://router.hereapi.com/v8/routes?transportMode=car&origin=${source.latitude},${source.longitude}&destination=${destination.latitude},${destination.longitude}&apiKey=${key}&return=polyline`;
const url = `${HERE_API_URL}?${new URLSearchParams({
transportMode: 'car',
origin: `${source.longitude},${source.latitude}`,
destination: `${destination.longitude},${destination.latitude}`,
apiKey: HERE_API_KEY,
return: 'polyline',
}).toString()}`;


const head = arr => arr[0];
const flatten = (arr, x) => arr.concat(x);

// JSON path "$..points"
Expand All @@ -38,23 +45,24 @@ const getPolyline = body => polyline.encode(getPoints(JSON.parse(body)));

const getRoute = (cb) => request.get(url, cb);

//const handleRoute = (e, r, body) => console.log(getPolyline(body));

const tollguruUrl = 'https://dev.tollguru.com/v1/calc/route';

const handleRoute = (e, r, body) => {
const handleRoute = (e, r, body) => {
console.log(body)

const _polyline = getPolyline(body);
console.log(_polyline);

request.post(
{
url: tollguruUrl,
url: `${TOLLGURU_API_URL}/${POLYLINE_ENDPOINT}`,
headers: {
'content-type': 'application/json',
'x-api-key': tollguruKey
'x-api-key': TOLLGURU_API_KEY
},
body: JSON.stringify({ source: "here", polyline: _polyline })
body: JSON.stringify({
source: "here",
polyline: _polyline,
...requestParameters,
})
},
(e, r, body) => {
console.log(e);
Expand Down
Loading

0 comments on commit 8d536b0

Please sign in to comment.