Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.