Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit e52fb98ceabecb081e4b276ae76b827829c15c66 Marc Greenstock committed Apr 25, 2011
Showing with 141 additions and 0 deletions.
  1. +1 −0 index.js
  2. +7 −0 lib/douche/client.js
  3. +1 −0 lib/douche/index.js
  4. +105 −0 lib/douche/wsdl.js
  5. +20 −0 package.js
  6. +7 −0 test/test.js
1 index.js
@@ -0,0 +1 @@
+module.exports = require('./lib/douche');
7 lib/douche/client.js
@@ -0,0 +1,7 @@
+var wsdl = require('./wsdl');
+
+var Client = function(wsdl_url) {
+ this.wsdl = new wsdl(wsdl_url);
+}
+
+module.exports = Client;
1 lib/douche/index.js
@@ -0,0 +1 @@
+module.exports = require('./client');
105 lib/douche/wsdl.js
@@ -0,0 +1,105 @@
+var url = require('url'),
+ http = require('http'),
+ xml2js = require('xml2js');
+
+var WSDL = function(href) {
+ this.href = href;
+ this.target_namespace = '';
+ this.namespaces = {};
+ this.operations = {};
+ this.element_form_default = 'unqualified';
+}
+
+module.exports = WSDL;
+
+WSDL.prototype.parse = function(cb) {
+ var self = this;
+
+ this._get(function(err,xml) {
+ self._read_namespaces(xml['@']);
+ self._read_tag(xml);
+
+ console.log(self.operations);
+ });
+}
+
+WSDL.prototype._read_tag = function(attrs, parent_path) {
+ parent_path = parent_path == undefined ? [] : parent_path;
+
+ var prefixes = {
+ soap: '',
+ wsdl: '',
+ xsd: ''
+ };
+
+ this.namespaces.forEach(function(prefix,url) {
+ if(prefix != '_xmlns') {
+ if(url.indexOf('http://schemas.xmlsoap.org/wsdl/soap') == 0) {
+ prefixes.soap = prefix + ':';
+ }
+ if(url.indexOf('http://schemas.xmlsoap.org/wsdl') == 0) {
+ prefixes.wsdl = prefix + ':';
+ }
+ if(url.indexOf('http://www.w3.org/2001/XMLSchema') == 0) {
+ prefixes.xsd = prefix + ':';
+ }
+ }
+ });
+
+ for(var tag in attrs[prefixes.wsdl + 'types']) {
+ if(prefixes.xsd + tag == 'schema') {
+ this.element_form_default = attrs[prefixes.wsdl + 'types'][tag]['@']['elementFormDefault'];
+ break;
+ }
+ }
+
+ for(var tag in attrs[prefixes.wsdl + 'binding']) {
+ if(tag == prefixes.wsdl + 'operation') {
+ var name = attrs[prefixes.wsdl + 'binding'][tag]['@']['name'];
+ var location = attrs[prefixes.wsdl + 'binding'][tag][prefixes.soap + 'operation']['@']['soapAction'];
+
+ this.operations[name] = {
+ location: location
+ };
+ }
+ }
+
+ return;
+}
+
+WSDL.prototype._read_namespaces = function(attrs) {
+ var self = this;
+ attrs.forEach(function(value,index) {
+ if(index == 'targetNamespace') {
+ self.target_namespace = value;
+ }
+ if(index == 'xmlns') {
+ self.namespaces[value] = '';
+ }
+ if(index.indexOf('xmlns:') == 0) {
+ self.namespaces[value] = index.split(':')[1];
+ }
+ });
+}
+
+WSDL.prototype._get = function(cb) {
+ var url_parts = url.parse(this.href);
+
+ http.get({
+ host: url_parts.host,
+ port: url_parts.port || 80,
+ path: (url_parts.pathname || '/') + (url_parts.search || ''),
+ }, function(res) {
+ var xml = '';
+ res.setEncoding('utf8');
+ res.on('data',function(chunk) {
+ xml += chunk;
+ }).on('end',function() {
+ var parser = new xml2js.Parser();
+ parser.parseString(xml);
+ cb(null,parser.resultObject);
+ });
+ }).on('error', function(err) {
+ cb(err,null);
+ });
+}
20 package.js
@@ -0,0 +1,20 @@
+{
+ "name": "douche",
+ "description": "A SOAP client based off savon.",
+ "version": "0.0.1",
+ "keywords": [
+ "soap"
+ ],
+ "directories": {
+ "lib": "./lib"
+ },
+ "dependencies": {
+ "jsdom": ">=0.2.0"
+ },
+ "maintainers": [
+ {
+ "name": "Marc Greenstock",
+ "email": "hello@marcgreenstock.com"
+ }
+ ]
+}
7 test/test.js
@@ -0,0 +1,7 @@
+var douche = require('../index.js');
+
+var client = new douche('http://api.search.live.net/search.wsdl');
+client.wsdl.parse();
+
+var client = new douche('http://soap.amazon.com/schemas3/AmazonWebServices.wsdl');
+client.wsdl.parse();

0 comments on commit e52fb98

Please sign in to comment.