All Projects → JBezerra → node-uber-rider

JBezerra / node-uber-rider

Licence: MIT License
A library that helps who wants to use Uber API with fast and easy methods ✨

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to node-uber-rider

uber
Uber API client
Stars: ✭ 18 (+5.88%)
Mutual labels:  uber, uber-api
IOSIphoneHttps
ios超级签-ipa-新版IOS苹果企业签,直接签名直接下载安装,无需进入appstore商城——不需要经过App Store直接下载游戏吗?下载完不知道怎么安装?需要通过第三方软件来安装?绕过苹果检测,测试可以使用HTTPD或者Tomcat构建,使用plist文件
Stars: ✭ 61 (+258.82%)
Mutual labels:  uber
uberscriptquery
UberScriptQuery, a SQL-like DSL to make writing Spark jobs super easy
Stars: ✭ 54 (+217.65%)
Mutual labels:  uber
go-schemaless
An open-source sharded database framework based on Uber's Schemaless
Stars: ✭ 79 (+364.71%)
Mutual labels:  uber
makisu
Fast and flexible Docker image building tool, works in unprivileged containerized environments like Mesos and Kubernetes.
Stars: ✭ 2,414 (+14100%)
Mutual labels:  uber
uber-cli
Beeps when surge is gone
Stars: ✭ 29 (+70.59%)
Mutual labels:  uber
deck.gl-time-series-widget
A React Time Slider implementation for DECK.GL - (non)temporal data - by CPU filtering ⌛
Stars: ✭ 19 (+11.76%)
Mutual labels:  uber
Uber
iOS Ride-Sharing App written in Swift 4 Using Map Kit and Core Data
Stars: ✭ 30 (+76.47%)
Mutual labels:  uber
Dual-color-Polyline-Animation
This library will help to show the polyline in dual color similar as Uber.
Stars: ✭ 73 (+329.41%)
Mutual labels:  uber
surger
⚡ Is there surge pricing around me right now?
Stars: ✭ 20 (+17.65%)
Mutual labels:  uber
RideShare-Trip-Stats
Chrome Extension to visualize your uber trip statistics
Stars: ✭ 61 (+258.82%)
Mutual labels:  uber
shared-docs
Shared Markdown Documents from Uber Engineering
Stars: ✭ 12 (-29.41%)
Mutual labels:  uber
data-visualization-deck-gl
A experiment to visualize Tree in NewYork and Flight record data. Using Deck.gl and Kaggle
Stars: ✭ 54 (+217.65%)
Mutual labels:  uber
athenadriver
A fully-featured AWS Athena database driver (+ athenareader https://github.com/uber/athenadriver/tree/master/athenareader)
Stars: ✭ 116 (+582.35%)
Mutual labels:  uber
deck.gl-data
Data for the data visualization library deck.gl examples (https://uber.github.io/deck.gl/#/)
Stars: ✭ 57 (+235.29%)
Mutual labels:  uber
libretaxi2
Open source Uber PoC #deleteuber
Stars: ✭ 90 (+429.41%)
Mutual labels:  uber
uber-sdk
A Ruby SDK for the Uber API
Stars: ✭ 32 (+88.24%)
Mutual labels:  uber
EasyWayLocation
This library contain all utils related to google location. like, getting lat or long, Address and Location Setting dialog, many more...
Stars: ✭ 142 (+735.29%)
Mutual labels:  uber
uber-clone-react-native
Uber UI/UX Clone in React Native
Stars: ✭ 68 (+300%)
Mutual labels:  uber
DLUberLogin
Imitate Uber LoginView
Stars: ✭ 19 (+11.76%)
Mutual labels:  uber

License build status semantic-release

A library to use Uber Riders' API faster and easily for Node.js

This project contains all endpoints you need to integrate Uber's API in your application

Installation

Before begin, you need to register your app in the Uber developer dashboard. Notice that the app gets a client ID, Client Secret, and Server Token required for authenticating with the API. After registering your application, you need to install this module in your Node.js project:

npm install node-uber-rider

Initialization

So as to use this module, you have to import it in your application first:

var Uber = require('node-uber-rider');

Next, initialize the Uber object with the keys you obtained from the Uber developer dashboard:

var uber = new Uber({
  clientID: 'CLIENT_ID',
  clientSecret: 'CLIENT_SECRET',
  redirectURI: 'REDIRECT_URI',
  
  //If you already have the authentication infos (they are all optional)
  access_token: 'SERVER_TOKEN',
  refresh_token: 'REFRESH_TOKEN',
  selfScopes:[scopes]
});

Authenticating

To make calls in the API, you need to create an authenticated session with the API. User-specific operations require you to use a OAuth 2 bearer token with specific scopes. General operations can use a simple server-token authentication. You do it in two steps. Step One, request the User's Code uber.getAuthorizeUrl([scopes]) with the scopes you need, step two, request the User's Bearer Token uber.getUserToken(UserCode,[scopes],callback) using the User's Code.

Step one: Authorize to get the Code

To obtain a bearer token, you have to authorize your application with the required scope. Available scopes are: history, history_lite, profile, request, all_trips, and places.

To do so, you are initially required to redirect your user to an authorization URL. You can generate the authorization URL using uber.getAuthorizeUrl([scopes]). In case you are using Express, your route definition could look as follows:

app.get('/getAuth', function(req,res){
    var url = uber.getAuthorizeUrl(['history','profile','all_trips']);
    res.redirect(url);
});

The URL will lead to a page where your user will be required to login and approve access to his/her Uber account. In case that step was successful, Uber will issue an HTTP 302 redirect to the redirect_uri defined in the Uber developer dashboard. On that redirect, you will receive an authorization code, which is single use and expires in 10 minutes.

Step two: Receive redirect and get an access token

To complete the authorization you now need to receive the callback and convert the given authorization code into an OAuth access token. You can accomplish that using uber.getUserToken(UserCode,[scopes],callback). This method will retrieve and store the access_token, refresh_token and authorized scopes with the uber object for consecutive requests.

Using Express, you could achieve that as follows:

app.get('/getCode', function(req, res){
    code = req.query.code;
    var token = uber.getUserToken(code,['history','profile','all_trips'],function(err,data){
        if(err)
        {
            console.log(err);
        }
        res.send("token: "+ data);
    }); 
});

Endpoints

Authentication

Generate Authorize URL

After getting the authorize url, the user will be redirected to the redirect url with authorization code used in the next function.

uber.getAuthorizeUrl([scopes]);
Example
uber.getAuthorizeUrl(['history','profile', 'request', 'places']);

Get Bearer Token

It gets the authorization you need (Access Token, Refresh Token, Scopes)

uber.getUserToken(UserCode,[scopes],callback);
Example: Just getting access_token
uber.getUserToken(code,['history','profile','all_trips'],function(err,token){
  if(err){
    console.log(err);
   }
   console.log("token: "+ token);
}); 
Example 2: Getting refresh_token
uber.getUserToken(code,['history','profile','all_trips'],function(err,token){
  if(err){
    console.log(err);
   }
   var refresh_token = uber.refresh_token;
   console.log("refresh_token: "+ refresh_token);
}); 

Riders

GET /me:

Gets User's Informations
uber.me(callback);
Example
uber.me(function(err,data){
  if(err){
    console.log(err);
   }
   console.log(data);
}); 

GET /history:

Gets User's Trips
uber.history(limit,offset,callback);
Example
uber.history(5,0,function(err,data){
  if(err){
    console.log(err);
   }
   console.log(data);
}); 

GET /payment-methods:

Gets User's Payment Methods
uber.paymentMethods(callback);
Example
uber.paymentMethods(function(err,data){
  if(err){
    console.log(err);
   }
   console.log(data);
}); 

GET /places/{place_id}

Gets user's address for home/work
uber.getPlaceByPlaceId(palceId,callback);
Example
uber.getPlaceByPlaceId('home',function(err,data){
  if(err){
    console.log(err);
   }
   console.log(data);
}); 

PATCH /me

It Applys Promotion
uber.applyPromotion(promotionCode,callback);
Example
uber.applyPromotion('FREE_RIDEZ',function(err,data){
  if(err){
    console.log(err);
   }
   console.log(data);
}); 

PUT /places/{place_id}

Updates User Address for an ID
uber.updateHomeOrWork(placeId,newAddress,callback);
Example
uber.updateHomeOrWork('home','New Street St',function(err,data){
  if(err){
    console.log(err);
   }
   console.log(data);
}); 

Ride Products

GET /products

Gets Uber's Products availabe near by
uber.products([coordinates],callback);
Example
uber.products(['lat','long'],function(err,data){
  if(err){
    console.log(err);
   }
   console.log(data);
}); 

GET /products/{product_id}

Gets Information about a Specific Product
uber.getProductByProductId(productID,callback);
Example
uber.getProductByProductId('a1111c8c-c720-46c3-8534-2fcdd730040d',function(err,data){
  if(err){
    console.log(err);
   }
   console.log(data);
}); 

Ride Estimates

GET /estimates/price

It Estimates Price between Start Location and End Location
uber.estimatePrice([startAndEndCoordinates],callback);
Example
uber.estimatePrice(['startLat','startLon','endLat','endLon'],function(err,data){
  if(err){
    console.log(err);
   }
   console.log(data);
}); 

GET /estimates/time

It Estimates Time between Start Location and End Location
uber.estimateTime([startAndEndCoordinates],callback);
Example
uber.estimateTime(['startLat','startLon','endLat','endLon'],function(err,data){
  if(err){
    console.log(err);
   }
   console.log(data);
}); 

Ride Requests

POST /requests/estimate

The Request Estimate endpoint allows a ride to be estimated given the desired product
var infos = {
  'start_latitude':'start_latitude',
  'start_longitude':'start_longitude',
  'end_latitude':'end_latitude',
  'end_longitude':'end_longitude',
  'product_id':'product_id'
};
uber.requestEstimate(infos,callback);
Example
var infos = {
  'start_latitude':'start_latitude',
  'start_longitude':'start_longitude',
  'end_latitude':'end_latitude',
  'end_longitude':'end_longitude',
  'product_id':'product_id'
};

uber.requestEstimate(infos,function(err,data){
  if(err){
    console.log(err);
   }
   console.log(data);
}); 

POST /requests

The Ride Request endpoint allows a ride to be requested on behalf of an Uber user
var infos = {
  'start_latitude':'start_latitude',
  'start_longitude':'start_longitude',
  'end_latitude':'end_latitude',
  'end_longitude':'end_longitude',
  'product_id':'product_id',
  'fare_id':'fare_id'
};
uber.createRequest(infos,callback);
Example
var infos = {
  'start_latitude':'start_latitude',
  'start_longitude':'start_longitude',
  'end_latitude':'end_latitude',
  'end_longitude':'end_longitude',
  'product_id':'product_id',
  'fare_id':'fare_id'
};

uber.createRequest(infos,function(err,data){
  if(err){
    console.log(err);
   }
   console.log(data);
}); 

GET /requests/current

It Returns Real Time Information about the Ongoing Trip
uber.currentRequest(callback);
Example
uber.currentRequest(function(err,data){
  if(err){
    console.log(err);
   }
   console.log(data);
}); 

GET /requests/{request_id}

The Ride Request endpoint allows retrieving the status of an ongoing or completed trip that was created by your app.
uber.getRequestDetails(requestId,callback);
Example
uber.getRequestDetails(requestId,function(err,data){
  if(err){
    console.log(err);
   }
   console.log(data);
}); 

GET /requests/{request_id}/map

It Returns a Map Link for a Request Id
uber.getRequestMap(requestId,callback);
Example
uber.getRequestMap(requestId,function(err,data){
  if(err){
    console.log(err);
   }
   console.log(data);
}); 

GET /requests/{request_id}/receipt

It Returns the Receipt of a Trip
uber.getRequestReceipt(requestId,callback);
Example
uber.getRequestReceipt(requestId,function(err,data){
  if(err){
    console.log(err);
   }
   console.log(data);
}); 

PATCH /requests/current

It Updates Ongoing Trip's Destiny
uber.updateOngoingDestination([endCoordinates],callback);
Example
uber.updateOngoingDestination(['endLat','endLon'],function(err,data){
  if(err){
    console.log(err);
   }
   console.log(data);
}); 

DELETE /requests/current

It Cancels the Current Trip
uber.cancelCurrentRequest(callback);
Example
uber.updateOngoingDestination(function(err,data){
  if(err){
    console.log(err);
   }
   console.log(data);
}); 

In case you want to contribute to the project, feel free! 😁

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].