Skip to content

Instantly share code, notes, and snippets.

@andywarr
Created May 30, 2016 20:00
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/9f7684dccf28cba0ae24fc8ebc647eb5 to your computer and use it in GitHub Desktop.
Save andywarr/9f7684dccf28cba0ae24fc8ebc647eb5 to your computer and use it in GitHub Desktop.
Accept surge pricing
var https = require('https');
// For information about Uber http status codes see: https://developer.uber.com/docs/api-reference
const uber_surge_pricing_status_code = 409;
function requestUber(event, context, product_id, surge_confirmation_id) {
// MOAR CODE
// Uber has surge pricing
else if (res.statusCode === uber_surge_pricing_status_code && !surge_confirmation_id) {
// Send an email to confirm surge pricing
console.log('Surge pricing. Status code: ' + res.statusCode);
var options = {
'host': 'api.uber.com',
'path': '/v1/surge-confirmations/' + parsed.meta.surge_confirmation.surge_confirmation_id
};
https.get(options, function (resp) {
var body = '';
resp.on('data', function (chunk) {
body += chunk;
});
resp.on("end", function () {
var csrf_token_etc = body.substring(body.lastIndexOf('<input name="csrf_token" type="hidden" value="')+46);
var csrf_token = csrf_token_etc = csrf_token_etc.substring(0, csrf_token_etc.indexOf('">'));
var data = {
'csrf_token': csrf_token
};
data = JSON.stringify(data);
var headers = {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(data)
};
var options = {
'host': 'api.uber.com',
'path': '/v1/surge-confirmations/' + parsed.meta.surge_confirmation.surge_confirmation_id,
'method': 'POST',
'headers': headers
};
var requ = https.request(options, function(respo) {
var body = '';
respo.on('data', function (chunk) {
body += chunk;
});
respo.on('end', function () {
var parsed = JSON.parse(body);
requestUber(event, context, product_id, parsed.surge_confirmation_token);
});
});
requ.write(data);
requ.end();
});
});
// MOAR CODE
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment