-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (41 loc) · 1.24 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
49
50
51
var soap = require("soap");
module.exports = function(config){
var client = false;
this.config = config;
this.isConnected = function(){
return !!this.client;
};
this.connect = function(cb){
var that = this;
soap.createClient (this.config.endpoint, function (err, result) {
if (err) {
if (cb) cb(new Error("SOAP Connector: Can not connect to server - " + JSON.stringify(err, null, " ")));
return;
}
that.client = result;
if (cb) cb();
});
};
this.disconnect = function(cb){
};
this.execute = function(method, args, cb){
if (!this.client) {
if (cb) cb(new Error("Connector is not connected."));
return;
}
var func = this.client[method];
if (!func) {
if (cb) cb(new Error("The method '" + method + "' does not exist."));
return;
}
var params = [].concat(args);
if (cb) params.push(function(err, result){
if (err) {
cb(err);
} else {
cb(null, result[method + "Result"]);
}
});
func.apply (this.client, params);
};
};