Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create README.md files for documentation. #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions lib/douche/wsdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var WSDL = function(href) {
this.operations = {};
this.endpoint = '';
this.element_form_default = 'unqualified';
};
}

module.exports = WSDL;

Expand All @@ -21,40 +21,42 @@ WSDL.prototype.parse = function(cb) {
self._read_xml(xml);
cb(self);
});
};
}

WSDL.prototype._read_xml = function(attrs) {
var self = this;

var types_tag = this._read_tag(attrs,'types','http://schemas.xmlsoap.org/wsdl/');
var schema_tag = this._read_tag(types_tag,'schema','http://www.w3.org/2001/XMLSchema');

this.element_form_default = schema_tag['@'].elementFormDefault || this.element_form_default;

if(schema_tag) {
this.element_form_default = schema_tag['@']['elementFormDefault'] || this.element_form_default;
}

var binding_tag = this._read_tag(attrs,'binding','http://schemas.xmlsoap.org/wsdl/');
var operation_tag = this._read_tag(binding_tag,'operation','http://schemas.xmlsoap.org/wsdl/');

if(operation_tag instanceof Array) {
operation_tag.forEach(function(operation_tag,index) {
var name = operation_tag['@'].name;
var soap_action = self._read_tag(operation_tag,'operation','http://schemas.xmlsoap.org/wsdl/soap/')['@'].soapAction;
var name = operation_tag['@']['name'];
var soap_action = self._read_tag(operation_tag,'operation','http://schemas.xmlsoap.org/wsdl/soap/')['@']['soapAction'];
self.operations[name] = {
soap_action: soap_action
};
});
} else {
var name = operation_tag['@'].name;
var soap_action = self._read_tag(operation_tag,'operation','http://schemas.xmlsoap.org/wsdl/soap/')['@'].soapAction;
var name = operation_tag['@']['name'];
var soap_action = self._read_tag(operation_tag,'operation','http://schemas.xmlsoap.org/wsdl/soap/')['@']['soapAction'];
self.operations[name] = {
soap_action: soap_action
};
}

var service_tag = this._read_tag(attrs,'service','http://schemas.xmlsoap.org/wsdl/');
var port_tag = this._read_tag(service_tag,'port','http://schemas.xmlsoap.org/wsdl/');
this.endpoint = this._read_tag(port_tag,'address','http://schemas.xmlsoap.org/wsdl/soap/')['@'].location;
this.endpoint = this._read_tag(port_tag,'address','http://schemas.xmlsoap.org/wsdl/soap/')['@']['location'];
return;
};
}

WSDL.prototype._read_tag = function(attrs,tag_name,namespace) {
for(var prefix in this.namespaces) {
Expand All @@ -67,21 +69,23 @@ WSDL.prototype._read_tag = function(attrs,tag_name,namespace) {
}
}
return false;
};
}

WSDL.prototype._read_namespaces = function(attrs) {
var self = this;
attrs.forEach(function(url,index) {
if(index == 'targetNamespace') {

for(var key in attrs) {
var url = attrs[key];
if(key == 'targetNamespace') {
self.target_namespace = url;
}
if(index == 'xmlns') {
self.namespaces._xmlns = url;
if(key == 'xmlns') {
self.namespaces['_xmlns'] = url;
}
if(index.indexOf('xmlns:') === 0) {
self.namespaces[index.split(':')[1]] = url;
if(key.indexOf('xmlns:') == 0) {
self.namespaces[key.split(':')[1]] = url;
}
});
}
};

WSDL.prototype._get = function(cb) {
Expand All @@ -90,7 +94,7 @@ WSDL.prototype._get = function(cb) {
http.get({
host: url_parts.host,
port: url_parts.port || 80,
path: (url_parts.pathname || '/') + (url_parts.search || '')
path: (url_parts.pathname || '/') + (url_parts.search || ''),
}, function(res) {
var xml = '';
res.setEncoding('utf8');
Expand All @@ -104,4 +108,4 @@ WSDL.prototype._get = function(cb) {
}).on('error', function(err) {
cb(err,null);
});
};
}