Skip to content

Commit 1e02d1b

Browse files
committed
Merge pull request #59 from chughts/bugfixes
Bugfixes
2 parents 4610616 + f32fefd commit 1e02d1b

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

services/alchemy_language/v1.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@
9999
<p>For full details on the feature details, please see the <a href="http://www.alchemyapi.com/api">Alchemy API documentation</a></p>
100100
<p>The content to be analysed should be passed in on <code>msg.payload</code>.</p>
101101
<p>Valid <code>msg.payload</code> types: URL, HTML or Text Content.</p>
102-
<p>If you need to send custom parameters along with each feature, set those parameters as children of the <code>msg.alchemy_options</code> object.</p>
102+
<p>If you need to send custom parameters along with each feature, set those parameters as children of the <code>msg.alchemy_options</code> object. eg. to limit the output to 3 values per feature set
103+
<code>msg.alchemy_options = {maxRetrieve: 3};</code>
104+
</p>
103105
<br>
104106
<p>Results from the Alchemy API service will made available at <code>msg.features</code>. Each feature result will be a separate child property.</p>
105107
</script>

services/alchemy_language/v1.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ module.exports = function (RED) {
4646
// user who, when he errenously enters bad credentials, can't figure out why
4747
// the edited ones are not being taken.
4848

49-
var services = cfenv.getAppEnv().services;
49+
// Taking this line out as codacy was complaining about it.
50+
// var services = cfenv.getAppEnv().services;
5051
var service;
5152

5253
var apikey, s_apikey;
@@ -103,13 +104,18 @@ module.exports = function (RED) {
103104
return;
104105
}
105106

106-
// The watson node-SDK expects the features as a single string.
107-
var extract = "" ; //doc-sentiment";
108-
enabled_features.forEach(function(entry){extract += (',' + entry)})
107+
// The watson node-SDK expects the features as a single string.
108+
var extract = "" ;
109+
extract = enabled_features.join(",");
109110

110111
//console.log("Will be looking for ", extract)
111112

112-
var params = { text: msg.payload, extract: extract };
113+
var params = { text: msg.payload, extract: extract };
114+
115+
// Splice in the additional options from msg.alchemy_options
116+
// eg. The user may have entered msg.alchemy_options = {maxRetrieve: 2};
117+
118+
for (var key in msg.alchemy_options) { params[key] = msg.alchemy_options[key]; }
113119

114120
alchemy_language.combined(params, function (err, response) {
115121
if (err || response.status === 'ERROR') {
@@ -118,16 +124,16 @@ module.exports = function (RED) {
118124
node.error(err, msg);
119125
}
120126
else {
121-
msg.features = {};
122-
//msg.features['all'] = response;
127+
msg.features = {};
128+
//msg.features['all'] = response;
123129

124-
Object.keys(FEATURES).forEach(function (feature) {
125-
var answer_feature = FEATURES[feature];
130+
Object.keys(FEATURES).forEach(function (feature) {
131+
var answer_feature = FEATURES[feature];
126132

127-
msg.features[feature] = response[answer_feature] || {};
128-
});
133+
msg.features[feature] = response[answer_feature] || {};
134+
});
129135

130-
node.send(msg);
136+
node.send(msg);
131137
}
132138
});
133139

0 commit comments

Comments
 (0)