-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.js
33 lines (26 loc) · 995 Bytes
/
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
var rest = require('rest');
var interceptor = require('./interceptor');
var errorCodeInterceptor = require('rest/interceptor/errorCode');
var pathPrefixInterceptor = require('rest/interceptor/pathPrefix');
var mimeInterceptor = require('rest/interceptor/mime');
var retryInterceptor = require('rest/interceptor/retry');
var timeoutInterceptor = require('rest/interceptor/timeout');
module.exports = function(config) {
var config = config || {};
var restCall = rest
.wrap(pathPrefixInterceptor, { prefix: 'https://api.geekdo.com/xmlapi2/'})
.wrap(mimeInterceptor, {mime:'text/xml', accept: 'text/xml'})
.wrap(errorCodeInterceptor)
.wrap(interceptor)
.wrap(timeoutInterceptor, { timeout: config.timeout || 5000 });
if(config.retry) {
restCall = restCall.wrap(retryInterceptor, config.retry);
}
return function(path, params){
var restConfig = {path: path};
if(params){
restConfig.params = params;
}
return restCall(restConfig);
};
}