UNPKG

eirenerx-sdk

Version:
40 lines (32 loc) 1.02 kB
var request = require('request'); var _ = require('lodash'); module.exports = function(opts) { var r = request.defaults({ json: true, auth: { user: opts.key, pass: opts.secret }, headers: { 'X-Sponsor-Id': opts.sponsor } }); var handle = _.curry(function(cb, err, request, body) { cb(err, body); }); var list = function(cb) { r.get(opts.api + '/api/vendor/v2/webhooks', handle(cb)); }; var create = function(hook, cb) { // simple validate hook object // confirm nodes and maybe test for underscore expression ???? r.post(opts.api + '/api/vendor/v2/webhooks', {json: hook }, handle(cb)); }; var update = function(id, hook, cb) { // validate .... same as post r.put(opts.api + '/api/vendor/v2/webhooks/' + id, {json: hook }, handle(cb)); }; var remove = function(id, cb) { r.del(opts.api + '/api/vendor/v2/webhooks/' + id, handle(cb)); }; return Object.freeze({ list: list, create: create, update: update, remove: remove }); };