uber-ride-request

1.0.1 • Public • Published

Uber Ride Request

Request an UberX ride by only setting the starting and ending GPS coordinates.

Installing

Using npm:

$ npm install --save uber-ride-request

Usage

Create a new application on the Uber developer web platform.

Under the "AUTHORIZATION" tab:

  • Initially, you need to get a Bearer access token (used to authenticate the requests we make to the Uber API). The easiest way I found was to generate it on the Uber developer web platform. This token will be valid for 30 days, but a refresh token can be used to extend its validity. You can also generate it with the oAuth2 authentication provided.
  • Make sure to enable (at least) the request scope .

Have a look at the API docs for more detailed information on how to authenticate, make API calls, etc...

Example

Every method on the client returns a promise, so they can be chained together. You can order a ride as following:

const Client = require('uber-ride-request').Uber;

const access_token = "YOUR_ACCESS_TOKEN"; // Retrieve it by generating a token under the "authorization" tab in https://developer.uber.com/dashboard/
const isSandbox = true; // Set to 'false' if you wish to order a real UberX

const uber = new Client(access_token, isSandbox);

uber.start_lat = 48.870694;
uber.start_lng = 2.317030;
uber.end_lat = 48.871405;
uber.end_lng = 2.301235;
uber.seats = 2;

uber.getUberXEstimate().then(result => {
    if(result != null){
        let distance_estimate = (result.trip.distance_estimate * 1.60934).toFixed(2);
        console.log("Estimated distance: " + distance_estimate + " km");
        uber.getRequest().then(result => {
            console.log("Ordered Uber successfully!");
            // Notify user about the ride process after one minute
            setTimeout(function(){
                getCurrentRide();
            }, 60000);
        });
    } else {
        console.warn("No UberX arround you.");
    }
});

function getCurrentRide(){
    uber.getCurrent().then(result =>{
        let status = result.status;
        let eta = result.pickup.eta;
        console.log("Current status: " + status + ". Driver arrives in: " + eta + " minutes.");
    });
}

You can also cancel an Uber ride requested by using:

uber.cancelCurrent().then(result => {
    if(result == 204){
        console.log("Canceled order successfully!");
    } else {
        res.send("No ride to cancel.");
    }
});

License

MIT

Antoine de Chassey

Readme

Keywords

Package Sidebar

Install

npm i uber-ride-request

Weekly Downloads

3

Version

1.0.1

License

ISC

Last publish

Collaborators

  • adechassey