diff --git a/lib/index.js b/lib/index.js index ec4a50a..ee82fe2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,10 +2,11 @@ var assert = require('assert'); -var http = require('http'), - jayson = require('jayson'), +var jayson = require('jayson'), _ = require('lodash'); +var http; // set on connect depending on the option given by the user + var Odoo = function (config) { config = config || {}; @@ -14,6 +15,7 @@ var Odoo = function (config) { this.database = config.database; this.username = config.username; this.password = config.password; + this.protocol = config.protocol || "http" }; // Connect @@ -40,6 +42,8 @@ Odoo.prototype.connect = function (cb) { var self = this; + http = require(this.protocol) + var req = http.request(options, function (res) { var response = ''; @@ -50,7 +54,12 @@ Odoo.prototype.connect = function (cb) { }); res.on('end', function () { - response = JSON.parse(response); + try { + response = JSON.parse(response); + } + catch(err) { + return cb(err, null); + } if (response.error) { return cb(response.error, null); @@ -203,7 +212,7 @@ Odoo.prototype._request = function (path, params, callback) { } }; - var client = jayson.client.http(options); + var client = jayson.client[this.protocol](options); client.request('call', params, function (e, err, res) { if (e || err) { diff --git a/package.json b/package.json index e79f8b3..ff92574 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "odoo", - "version": "0.4.0", + "version": "0.4.2", "description": "Node.js client library for Odoo using JSON-RPC", "main": "./lib/index.js", "directories": {