-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathimportset.js
49 lines (42 loc) · 1.42 KB
/
importset.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
49
var Promise = require('bluebird');
var request = Promise.promisifyAll(require('request'));
var qs = require('querystring');
var ImportSet = (function() {
'use strict';
function ImportSet(instance, tablename, user, password) {
// enforces new
if (!(this instanceof ImportSet)) {
return new ImportSet(instance, tablename, user, password);
}
this.reqobj = new req(instance, tablename, user, password);
}
ImportSet.prototype.get = function(sysid) {
this.reqobj.url += '/'+sysid;
return request.getAsync(this.reqobj).then(plogic);
};
ImportSet.prototype.insert = function(obj) {
this.reqobj.body = obj
return request.postAsync(this.reqobj).then(plogic);
};
return ImportSet;
function req(instance, tablename, user, password) {
this.url = 'https://' + instance + '.service-now.com/api/now/v1/import/' + tablename,
this.header = {
'Accept': 'application/json'
};
this.json = true;
this.auth = {
user: user,
password: password
}
}
function plogic(value) {
var statuscode = value.statusCode;
if (statuscode == 400 || statuscode == 404 || statuscode == 401) {
return Promise.reject(value.body)
}
console.log(value.headers)
return Promise.resolve(value.body.result);
}
}());
module.exports = ImportSet