forked from confuser/node-dotmailer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (23 loc) · 892 Bytes
/
Copy pathindex.js
File metadata and controls
32 lines (23 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var extend = require('lodash.assign')
, request = require('request')
, endPoints = require('./lib/end-points')
, handleRequest = require('./lib/handle-request')
module.exports = function (options) {
var defaultOptions = { json: true, timeout: 20000 }
options = extend({}, defaultOptions, options)
return send
function send(endpoint) {
var args = Array.prototype.slice.call(arguments, 1)
, cb = args.pop()
if (typeof cb !== 'function') throw new Error('Invalid callback, must be a function')
if (!endPoints[endpoint]) throw new Error('Unknown API endpoint')
var preparedRequest
try {
preparedRequest = extend({}, options, endPoints[endpoint].apply(null, args))
} catch (e) {
return cb(e)
}
preparedRequest.url = 'https://api.dotmailer.com/v2/' + preparedRequest.url
request(preparedRequest, handleRequest(cb))
}
}