Git Product home page Git Product logo

routific-node-client's Introduction

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("[email protected]", "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){
    //...
})

routific-node-client's People

Contributors

acroca avatar asoesilo avatar dobobaie avatar kvvok avatar mck- avatar renniehaylock avatar asafdav2 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.