Comparing version 0.1.7 to 0.1.8
@@ -27,11 +27,11 @@ var _ = require('lodash'); | ||
var me = this; | ||
var localArgs; | ||
var requestArgs, pagingArgs = {}; | ||
if (arguments.length === 2) { | ||
callback = args; | ||
localArgs = { | ||
requestArgs = { | ||
uuid: me.config.uuid | ||
}; | ||
} else if (arguments.length === 3) { | ||
localArgs = _.assign({ | ||
requestArgs = _.assign({ | ||
uuid: me.config.uuid | ||
@@ -43,3 +43,3 @@ }, args || {}); | ||
if (!localArgs.uuid) { | ||
if (!requestArgs.uuid) { | ||
return setImmediate(function() { | ||
@@ -50,2 +50,7 @@ callback(new Error('uuid missing. Provide it with the 2nd arguments object or with client instantiation. Hint: `var clang = new Clang({uuid: \'12345678-...\'})`')); | ||
pagingArgs.offset = requestArgs._offset || 0; | ||
pagingArgs.size = requestArgs._size || 50; | ||
delete requestArgs._offset; | ||
delete requestArgs._size; | ||
async.waterfall([ | ||
@@ -83,5 +88,22 @@ function async_init(callback){ | ||
fn(localArgs, buildCallback(me.config, me.api, callback)); | ||
fn(requestArgs, buildCallback(me.config, me.api, pagingArgs, callback)); | ||
} | ||
], callback); | ||
], function(err, result) { | ||
if (err) { | ||
if (err.root && err.root.Envelope && err.root.Envelope.Body) { | ||
/** | ||
* err.root.Envelope.Body: | ||
* { | ||
* "Fault": { | ||
* "faultcode": "105", | ||
* "faultstring": "Size must be between 1 and 50" | ||
* } | ||
* } | ||
*/ | ||
return callback(err.root.Envelope.Body); | ||
} | ||
return callback(err); | ||
} | ||
return callback(null, result); | ||
}); | ||
}; | ||
@@ -139,6 +161,8 @@ | ||
*/ | ||
var buildCallback = function (config, api, callback) { | ||
var me = this; | ||
var buildCallback = function (config, api, pagingArgs, callback) { | ||
return function apiCallback(err, result) { | ||
if (config.logRequests) { | ||
console.log(api.lastRequest); | ||
} | ||
/* | ||
@@ -203,12 +227,40 @@ first result that indicate there's a recource looks like this: { code: 0, msg: '210577' } | ||
if (result.msg.size > 0) { | ||
api[setMethods[result.msg.type]]({ | ||
uuid : config.uuid, | ||
resourceId: resourceId, | ||
offset : 0, | ||
size : 50 | ||
}, function (err, result) { | ||
if (err) { | ||
console.error('Error in getting resource set', JSON.stringify(err.stack)); | ||
async.series([ | ||
function(callback){ | ||
if (config.debug) { | ||
console.log('Getting data from resource with resourceId: ' + resourceId + ' using ' + setMethods[result.msg.type]); | ||
} | ||
api[setMethods[result.msg.type]]({ | ||
uuid : config.uuid, | ||
resourceId: resourceId, | ||
offset : pagingArgs.offset, | ||
size : pagingArgs.size | ||
}, function (err, result) { | ||
if (config.logRequests) { | ||
console.log(api.lastRequest); | ||
} | ||
if (err) { | ||
if (config.debug) { | ||
console.error('Error in getting resource set'); | ||
} | ||
return callback(err); | ||
} | ||
callback(null, normalizeResponse(config, result)); | ||
}); | ||
}, | ||
function(callback){ | ||
if (config.debug) { | ||
console.log('Free resource with resourceId: ' + resourceId); | ||
} | ||
api.resource_free({ | ||
uuid : config.uuid, | ||
resourceId: resourceId | ||
}, callback); | ||
} | ||
callback(null, normalizeResponse(config, result)); | ||
], | ||
function(err, results) { | ||
if (config.logRequests) { | ||
console.log(api.lastRequest); | ||
} | ||
callback(err, results[0]); | ||
}); | ||
@@ -215,0 +267,0 @@ return; |
{ | ||
"name": "clang", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "Node.js api wrapper for Clang's SOAP api", | ||
@@ -5,0 +5,0 @@ "author": "Christiaan Westerbeek <chris@devotis.nl>", |
@@ -27,2 +27,8 @@ [![Build Status](https://travis-ci.org/devotis/node-clang.svg)](https://travis-ci.org/devotis/node-clang) | ||
//Paging using the special parameters _size and _offset. Defaults are 50 and 0 | ||
clang.request('customer_getAll', { | ||
_size: 10 | ||
}, function(err, result) { | ||
console.log(arguments); | ||
}); | ||
@@ -29,0 +35,0 @@ ##WSDL |
@@ -22,3 +22,3 @@ var should = require('should'); | ||
clang.request(function(err, result) { | ||
false.should.be.equal(false); | ||
false.should.be.equal(true); | ||
done(); | ||
@@ -25,0 +25,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
225785
6553
38