-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (38 loc) · 1.34 KB
/
index.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var http = require('http')
, get = require('./modules/get')
, save = require('./modules/save')
, remove = require('./modules/remove')
, query = require('./modules/query')
, httpStub = require('./modules/httpStub')
, utils = require('./utils')
, setup = function (keyIn, tokenIn, hostIn, httpIn) {
'use strict';
var config = {
version: 'v1'
};
if (typeof keyIn !== 'string'){
throw new Error('key is required and must be a string');
}
if (typeof tokenIn !== 'string'){
throw new Error('token is required and must be a string');
}
config.key = keyIn;
config.token = tokenIn;
config.http = typeof httpIn === 'undefined' ? http : httpIn;
config.host = utils.getHost(hostIn, config.version);
config.port = utils.getPort(hostIn);
return {
query: query(config)
, remove: remove(config)
, save: save(config)
, get: get(config)
, httpStub: function (stubs) {
config.http = httpStub(stubs);
this.query = query(config);
this.remove = remove(config);
this.save = save(config);
this.get = get(config);
}
};
};
module.exports = setup;