feat(webhooks): add webhooks operations

This commit is contained in:
Tyler Renelle 2014-11-16 20:03:20 -08:00
parent d078654f41
commit 83a22b8133
2 changed files with 47 additions and 0 deletions

View file

@ -14620,6 +14620,33 @@ api.wrap = function(user, main) {
});
return typeof cb === "function" ? cb(null, user.tags) : void 0;
},
addWebhook: function(req, cb) {
var wh;
wh = user.preferences.webhooks;
wh[req.body.id || api.uuid()] = {
url: req.body.url,
enabled: req.body.enabled || true,
sort: _.isEmpty(wh) ? 0 : _.max(wh, 'sort').sort + 1
};
if (typeof user.markModified === "function") {
user.markModified('preferences.webhooks');
}
return typeof cb === "function" ? cb(null, user.preferences.webhooks) : void 0;
},
updateWebhook: function(req, cb) {
_.merge(user.preferences.webhooks[req.params.id], req.body);
if (typeof user.markModified === "function") {
user.markModified('preferences.webhooks');
}
return typeof cb === "function" ? cb(null, user.preferences.webhooks) : void 0;
},
deleteWebhook: function(req, cb) {
delete user.preferences.webhooks[req.params.id];
if (typeof user.markModified === "function") {
user.markModified('preferences.webhooks');
}
return typeof cb === "function" ? cb(null, user.preferences.webhooks) : void 0;
},
feed: function(req, cb) {
var egg, evolve, food, message, pet, potion, userPets, _ref, _ref1, _ref2;
_ref = req.params, pet = _ref.pet, food = _ref.food;

View file

@ -594,6 +594,26 @@ api.wrap = (user, main=true) ->
user.markModified? type
cb? null, user.tags
# ------
# Webhooks
# ------
addWebhook: (req, cb) ->
wh = user.preferences.webhooks
wh[req.body.id or api.uuid()] =
url: req.body.url
enabled: req.body.enabled or true
sort: if _.isEmpty(wh) then 0 else _.max(wh,'sort').sort+1
user.markModified? 'preferences.webhooks'
cb? null, user.preferences.webhooks
updateWebhook: (req, cb) ->
_.merge(user.preferences.webhooks[req.params.id], req.body)
user.markModified? 'preferences.webhooks'
cb? null, user.preferences.webhooks
deleteWebhook: (req, cb) ->
delete user.preferences.webhooks[req.params.id]
user.markModified? 'preferences.webhooks'
cb? null, user.preferences.webhooks
# ------
# Inventory
# ------