function Client(url, opts) {
var info = {
'url': url,
'server_version': null
};
};
Client.prototype.server_version = function (cb) {
if (!this.info.server_version){
this.request("info").then(function(result) {
this.info.server_version = result.version;
}).nodeify(cb);
} else {
cb(this.info.server_version);
};
};
Client.prototype.read = function(params, cb) {
this.server_version(function(err, result) {
if (result > [3, 3, 0]) {
...
};
else {
...
}
});
return this.request(params).nodeify(cb);
};
Client.prototype.request = function(method) {
defer = Q.defer();
...
return defer.promise;
};
Have your module expose a create method that makes the initial request to get the version and have that return an object with all of the logic tied to the specific server version to the callback. That way you can avoid needing to check the version in all the subsequent calls.
-- Daniel R. <dan...@neophi.com> [http://danielr.neophi.com/]
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAETDeSBUJnvVfC0ZPRy7bT6HFnc5o_forJ_WmuZfgZ%2BagnxfUQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAJhmvsThAuvjemEUuub_BHBJ5xakr6mX1hHJ50VGVwD-cBmvYg%40mail.gmail.com.