Last active
May 30, 2016 21:13
-
-
Save andywarr/7f18f95c4654ef7083edb58e09c8f8b6 to your computer and use it in GitHub Desktop.
Cancel an Uber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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