viewpoint
Version:
the exchange email API for nodejs module
66 lines (46 loc) • 1.99 kB
JavaScript
var EWSFolderOperations, EWSItemOperations, EWSRes, EWSResponse, EWSSyncOperations, EWSWebService, RequestClient, SoapError, libxml,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
EWSItemOperations = require('./ews/ews-item-operations');
EWSFolderOperations = require('./ews/ews-folder-operations');
EWSSyncOperations = require('./ews/ews-sync-operations');
RequestClient = require('./http/request-client');
EWSRes = require('./ews-response');
libxml = require('libxmljs');
EWSResponse = EWSRes.EWSResponse;
SoapError = (function(superClass) {
extend(SoapError, superClass);
function SoapError() {
var err;
err = SoapError.__super__.constructor.apply(this, arguments);
this.name = 'SoapError';
this.stack = err.stack;
this.message = err.message;
}
return SoapError;
})(Error);
module.exports = EWSWebService = (function() {
EWSItemOperations.includeInto(EWSWebService);
EWSFolderOperations.includeInto(EWSWebService);
EWSSyncOperations.includeInto(EWSWebService);
RequestClient.includeInto(EWSWebService);
function EWSWebService() {
RequestClient.apply(this, arguments);
}
EWSWebService.prototype.doSoapRequest = function(doc, resName) {
return this.send(doc.toString(false)).then(function(res) {
var Response, ewsRes, param;
Response = resName ? EWSRes[resName] : EWSResponse;
ewsRes = new Response(libxml.parseXmlString(res.body));
if (!ewsRes.isSuccess) {
param = {
responseCode: ewsRes.responseCode,
messageText: ewsRes.messageText
};
throw new SoapError("SOAP Error:" + (JSON.stringify(param, null, 2)));
}
return ewsRes;
});
};
return EWSWebService;
})();