Skip to content

routific/routific-node-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License: MIT

Routific npm module

This node library is a client to interact with the Routific API

Usage

Install the npm module:

npm install routific

A simple login example:

Routific = require('routific');

client = new Routific.Client();

client.login("test@test.com", "123456", function(err, response){
    // ...
});

Initialization

The Routific Client constructor accepts an optional configuration object as a first argument.

client = new Routific.Client(options);

Valid options:

  • url: Routific API url. This is for internal use only. Default "https://api.routific.com".
  • version: Version of the API to use. Default 1.
  • token: User token to use for authenticated operations. This is optional, performing a login will set it too. Default null.
  • pollDelay: Milliseconds between attempts to check if jobs are finished when processing routes. Default 1000.

Operations

Login

It calls the Login endpoint and keeps the received token for the following authenticated calls.

client.login(email, password, function(error, response){
    //...
})

VRP route

It calls the VRP endpoint (long version) and waits until the job is processed. It returns the job output, as it would do calling the short VRP endpoint.

vrp = new Routific.Vrp();
vrp.addVisit("visitID1", {
    location: {
        name: "Visit1 name",
        lat: 49.227607,
        lng: -123.1363085
    },
    start: "8:00",
    end: "16:00",
    duration: 10
});
vrp.addVehicle("vehicleID1", {
    start_location: {
        id: "depot",
        lat: 49.2553636,
        lng: -123.0873365
    },
    end_location: {
        id: "depot",
        lat: 49.2553636,
        lng: -123.0873365
    }
});
vrp.addOption("traffic", "slow");
client.route(vrp, function(err, solution, jobId){
    //...
})

PDP route

It calls the PDP endpoint (long version) and waits until the job is processed. It returns the job output, as it would do calling the short PDP endpoint.

pdp = new Routific.Pdp();
pdp.addVisit("visitID1", {
    pickup: {
        location: {
            name: "Visit1 pickup name",
            lat: 49.227607,
            lng: -123.1363085
        },
        start: "8:00",
        end: "16:00",
        duration: 10
    },
    dropoff: {
        location: {
            name: "Visit1 dropoff name",
            lat: 48.227607,
            lng: -122.1363085
        },
        start: "8:00",
        end: "16:00",
        duration: 10
    }
});
pdp.addVehicle("vehicleID1", {
    start_location: {
        id: "depot",
        lat: 49.2553636,
        lng: -123.0873365
    },
    end_location: {
        id: "depot",
        lat: 49.2553636,
        lng: -123.0873365
    }
});
pdp.addOption("traffic", "slow");
client.route(pdp, function(err, solution, jobId){
    //...
})

About

npm install routific

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published