node-red-m2x
Advanced tools
Comparing version 0.0.5 to 0.0.6
40
m2x.js
@@ -27,2 +27,15 @@ module.exports = function (RED) { | ||
} | ||
function cleanForNextNode(msg) { | ||
// CF: Clear the clatter for the next node | ||
try { | ||
delete msg.topic; | ||
delete msg.topic_id; | ||
delete msg.sub_topic_id; | ||
delete msg.action; | ||
} catch (e) { | ||
console.log("WARNING - cannot delete msg input field, probably working on STRICT mode") | ||
} | ||
} | ||
@@ -47,3 +60,4 @@ function M2XFeedNode(n) { | ||
_this.on("input", function (msg) { | ||
// Override Configured API Key with the one on the request, The feed ID is allways used by the one in the request | ||
// Override Configured API Key with the one on the request, | ||
// The feed ID is allways used by the one in the request | ||
// and fail over to the configured one. | ||
@@ -69,4 +83,11 @@ var api_key; | ||
if (!msg.action || methods.indexOf(msg.action) === -1) { | ||
console.log("methods doesn't exists"); | ||
_this.handle_msg_failure(msg, INPUT_ERROR_CODE, "action for " + topic + " must be either " + methods); | ||
} | ||
//TODO : validate why devices.listTriggers pass this parttrig | ||
// CF: Verification - from some reason the above doesn't allways works | ||
if (!(typeof (_this.m2xClient[topic][msg.action]) === 'function')) { | ||
this.handle_msg_failure(msg, INPUT_ERROR_CODE, | ||
"Cannot find " + msg.action +" in " + topic + " validate agains m2x client node, API is applicable"); | ||
} | ||
// Get list of parameters for that method | ||
@@ -133,3 +154,3 @@ var arguments = getParamNames(_this.m2xClient[topic][msg.action]); | ||
try { | ||
if (!statusCode) { | ||
if (typeof (statusCode) === 'undefined') { | ||
_this.error("No result was found, setting error msg to 500 - General Error"); | ||
@@ -141,3 +162,3 @@ msg.statusCode = ERROR_CODE; | ||
} | ||
if (!reason) { | ||
if (typeof (reason) === 'undefined') { | ||
msg.payload = {}; | ||
@@ -150,2 +171,3 @@ } else if (!reason.body) { | ||
} finally { | ||
cleanForNextNode(msg); | ||
_this.send(msg); | ||
@@ -156,10 +178,16 @@ } | ||
_this.handle_msg_response = function (msg, result) { | ||
if (!result) { | ||
if (!result || !result.status) { | ||
this.error("General Error on M2X Flow"); | ||
this.handle_msg_failure(msg, ERROR_CODE, "Geneal Error"); | ||
} else if (!is_msg_succeed(result.status)) { | ||
this.handle_msg_failure(msg, result.status, result.json.message); | ||
this.handle_msg_failure(msg, result.status, | ||
(!result.json.message ? "" : result.json.message)); | ||
} else { | ||
console.log("Successful M2X Api call [" + result.status + "]"); | ||
msg.payload = result.json; | ||
if (typeof (result.json) === 'undefined') { | ||
msg.payload = result; | ||
} else { | ||
msg.payload = result.json; | ||
} | ||
cleanForNextNode(msg); | ||
this.send(msg); | ||
@@ -166,0 +194,0 @@ } |
{ | ||
"name": "node-red-m2x", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "A Node-RED node to AT&T M2X", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
60657
7
182
2