Skip to content
Open
Show file tree
Hide file tree
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
17 changes: 13 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {};

Expand All @@ -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
Expand All @@ -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 = '';

Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down