Skip to content

Commit ad1e8a4

Browse files
authored
Merge pull request #401 from chughts/json
JSON for Discovery
2 parents cc7dbb3 + c519d96 commit ad1e8a4

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Node-RED Watson Nodes for IBM Cloud
77

88
<a href="https://cla-assistant.io/watson-developer-cloud/node-red-node-watson"><img src="https://cla-assistant.io/readme/badge/watson-developer-cloud/node-red-node-watson" alt="CLA assistant" /></a>
99

10+
### New in version 0.6.10
11+
- Needed to stringify json before addDocument in Discovery node.
12+
- Using Node.js v 6 features, so will not run on Node.js v 4 anymore
13+
1014
### New in version 0.6.9
1115
- Implemented classify collection on Natural Language Classifier node. The collection can be
1216
in the form of multiple sentences, an array of strings, or an array of objects.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-node-watson",
3-
"version": "0.6.9",
3+
"version": "0.6.10",
44
"description": "A collection of Node-RED nodes for IBM Watson services",
55
"dependencies": {
66
"async": "^1.5.2",
@@ -55,6 +55,6 @@
5555
}
5656
},
5757
"engines": {
58-
"node": ">=4.5.0"
58+
"node": ">=6.12.0"
5959
}
6060
}

services/discovery/discovery-utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ DiscoveryUtils.prototype = {
5858
params.file = this.isJsonObject(msg.payload) ?
5959
JSON.stringify(msg.payload) :
6060
msg.payload;
61+
params.file_content_type = 'application/json';
6162
}
6263
return params;
6364
},
@@ -313,7 +314,8 @@ DiscoveryUtils.prototype = {
313314
},
314315

315316
isJsonObject: function(str) {
316-
if (str instanceof Array || str instanceof Object) {
317+
if (str instanceof Array || str instanceof Object ||
318+
'object' === typeof str || Array.isArray(str)) {
317319
return true;
318320
}
319321
return false;

services/discovery/v1-document-loader.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,13 @@ module.exports = function (RED) {
141141
}
142142

143143
discovery = new DiscoveryV1(serviceSettings);
144-
// addJsonDocument is deprecated
145-
//if ('.json' === suffix) {
146-
// method = 'addJsonDocument';
144+
// modify as getting addJsonDocument will be deprecated messages
145+
if ('.json' === suffix) {
146+
//method = 'addJsonDocument';
147+
params.file = JSON.stringify(params.file);
147148
//} else {
148-
// method = 'addDocument';
149-
//}
149+
//method = 'addDocument';
150+
}
150151
method = 'addDocument';
151152

152153
discovery[method](params, function (err, response) {

0 commit comments

Comments
 (0)