feat(webhooks): add webhooks to user.preferences (API settings) so we can post to external services (eg, Beeminder)

This commit is contained in:
Tyler Renelle
2014-10-25 14:44:01 -06:00
parent d45f40ca1f
commit 9efaf39b2b
4 changed files with 54 additions and 1 deletions
+10
View File
@@ -14,6 +14,7 @@ var moment = require('moment');
var logging = require('./../logging');
var acceptablePUTPaths;
var api = module.exports;
var request = require('request');
// api.purchase // Shared.ops
@@ -106,6 +107,15 @@ api.score = function(req, res, next) {
_tmp: user._tmp
}, saved.toJSON().stats));
// Webhooks
_.each(user.preferences.webhooks, function(h){
request.post({
url: h.url,
//form: {task: task, delta: delta, user: _.pick(user, ['stats', '_tmp'])} // this is causing "Maximum Call Stack Exceeded"
body: {direction:direction, task: task, delta: delta, user: _.pick(user, ['_id', 'stats', '_tmp'])}, json:true
});
});
if (
(!task.challenge || !task.challenge.id || task.challenge.broken) // If it's a challenge task, sync the score. Do it in the background, we've already sent down a response and the user doesn't care what happens back there
|| (task.type == 'reward') // we don't want to update the reward GP cost
+2 -1
View File
@@ -274,7 +274,8 @@ var UserSchema = new Schema({
tagsCollapsed: {type: Boolean, 'default': false},
advancedCollapsed: {type: Boolean, 'default': false},
toolbarCollapsed: {type:Boolean, 'default':false},
background: String
background: String,
webhooks: {type:Array, 'default': []}
},
profile: {
blurb: String,