Skip to content

Instantly share code, notes, and snippets.

@andywarr
Last active May 30, 2016 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andywarr/7f18f95c4654ef7083edb58e09c8f8b6 to your computer and use it in GitHub Desktop.
Save andywarr/7f18f95c4654ef7083edb58e09c8f8b6 to your computer and use it in GitHub Desktop.
Cancel an Uber
var https = require('https');
// For information about Uber http status codes see: https://developer.uber.com/docs/api-reference
const successfully_cancelled_uber_status_code = 204;
// For information about Uber tokens see: https://developer.uber.com/docs/authentication
const token = process.env.TOKEN;
function cancelUber(event, context) {
var headers = {
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(data)
};
var options = {
'host': 'api.uber.com',
'path': '/v1/requests/cancel',
'method': 'DELETE',
'headers': headers
};
var req = https.request(options, function(res) {
var body = '';
res.on('data', function (chunk) {
body += chunk;
});
res.on('end', function () {
// Successfully cancelled Uber
if (res.statusCode === successfully_cancelled_uber_status_code) {
console.log('Uber cancelled. Status code: ' + res.statusCode);
}
context.done();
});
});
req.end();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment