Skip to content

Commit c3fd580

Browse files
authored
Merge pull request #235 from chughts/versionupdate
URL based Services Check
2 parents 17ab8b4 + 526ece2 commit c3fd580

File tree

8 files changed

+40
-37
lines changed

8 files changed

+40
-37
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Node-RED Watson Nodes for IBM Bluemix
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.4.33
11+
- Personality Insights node updated to latest December 15, 2016 GloVe profiles.
12+
- Conversation, Alchemy Feature Extract and Date Extraction nodes updated to use url based services utility to detect bound service.
13+
1014
### New in version 0.4.32
1115
- Added diarization support to STT Node via the parameter speaker_labels
1216
- STT and TTS node use url based services utility to detect bound service.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-node-watson",
3-
"version": "0.4.32",
3+
"version": "0.4.33",
44
"description": "A collection of Node-RED nodes for IBM Watson services",
55
"dependencies": {
66
"alchemy-api": "^1.3.0",

services/alchemy_date_extraction/v1.js

+6-13
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
**/
1616

1717
module.exports = function (RED) {
18-
19-
var cfenv = require('cfenv');
20-
var watson = require('watson-developer-cloud');
21-
22-
var payloadutils = require('../../utilities/payload-utils');
18+
const SERVICE_IDENTIFIER = 'gateway-a.watsonplatform.net';
19+
var watson = require('watson-developer-cloud'),
20+
payloadutils = require('../../utilities/payload-utils'),
21+
serviceutils = require('../../utilities/service-utils'),
22+
apikey, s_apikey,
23+
service = serviceutils.getServiceCredsAlchemy(SERVICE_IDENTIFIER);
2324

2425
// Require the Cloud Foundry Module to pull credentials from bound service
2526
// If they are found then the api key is stored in the variable s_apikey.
@@ -30,14 +31,6 @@ module.exports = function (RED) {
3031
// user who, when he errenously enters bad credentials, can't figure out why
3132
// the edited ones are not being taken.
3233

33-
// Taking this line out as codacy was complaining about it.
34-
// var services = cfenv.getAppEnv().services;
35-
var service;
36-
37-
var apikey, s_apikey;
38-
39-
var service = cfenv.getAppEnv().getServiceCreds(/alchemy/i);
40-
4134
if (service) {
4235
s_apikey = service.apikey;
4336
}

services/alchemy_language/v1.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ var FEATURES = {
3333
};
3434

3535
module.exports = function (RED) {
36+
const SERVICE_IDENTIFIER = 'gateway-a.watsonplatform.net';
3637

37-
var cfenv = require('cfenv');
3838
var watson = require('watson-developer-cloud');
3939

40-
var payloadutils = require('../../utilities/payload-utils');
40+
var payloadutils = require('../../utilities/payload-utils'),
41+
serviceutils = require('../../utilities/service-utils'),
42+
apikey, s_apikey,
43+
service = serviceutils.getServiceCredsAlchemy(SERVICE_IDENTIFIER);
44+
4145

4246
// Require the Cloud Foundry Module to pull credentials from bound service
4347
// If they are found then the api key is stored in the variable s_apikey.
@@ -48,14 +52,6 @@ module.exports = function (RED) {
4852
// user who, when he errenously enters bad credentials, can't figure out why
4953
// the edited ones are not being taken.
5054

51-
// Taking this line out as codacy was complaining about it.
52-
// var services = cfenv.getAppEnv().services;
53-
var service;
54-
55-
var apikey, s_apikey;
56-
57-
var service = cfenv.getAppEnv().getServiceCreds(/alchemy/i);
58-
5955
if (service) {
6056
s_apikey = service.apikey;
6157
}

services/conversation/v1.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
**/
1616

1717
module.exports = function (RED) {
18-
var cfenv = require('cfenv'),
19-
ConversationV1 = require('watson-developer-cloud/conversation/v1'),
18+
const SERVICE_IDENTIFIER = 'conversation';
19+
var ConversationV1 = require('watson-developer-cloud/conversation/v1'),
20+
serviceutils = require('../../utilities/service-utils'),
2021
service = null, sUsername = null, sPassword = null;
2122

22-
service = cfenv.getAppEnv().getServiceCreds(/conversation/i);
23+
service = serviceutils.getServiceCreds(SERVICE_IDENTIFIER);
2324

2425
if (service) {
2526
sUsername = service.username;
@@ -131,7 +132,7 @@ module.exports = function (RED) {
131132
node.service = new ConversationV1({
132133
username: userName,
133134
password: passWord,
134-
version_date: '2016-07-11'
135+
version_date: '2016-09-20'
135136
});
136137
return true;
137138
}

services/language_translator_identify/v2.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</script>
3636

3737
<script type="text/x-red" data-help-name="watson-language-translator-identify">
38-
<p>Packaged in with release 0.4.32 of node-red-node-watson</p>
38+
<p>Packaged in with release 0.4.33 of node-red-node-watson</p>
3939
<p>The Watson Language Translator service can be used to identify languages used in a text input. <p>
4040
<p>Node input : </p>
4141
<ul>

services/personality_insights/v3.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
**/
1616

1717
module.exports = function (RED) {
18+
const SERVICE_IDENTIFIER = 'personality-insights';
1819
var PersonalityInsightsV3 = require('watson-developer-cloud/personality-insights/v3'),
19-
cfenv = require('cfenv'),
2020
payloadutils = require('../../utilities/payload-utils'),
21-
service = cfenv.getAppEnv().getServiceCreds(/personality insights/i),
21+
serviceutils = require('../../utilities/service-utils'),
22+
service = serviceutils.getServiceCreds(SERVICE_IDENTIFIER),
2223
username = null,
2324
password = null,
2425
sUsername = null,
@@ -118,7 +119,7 @@ module.exports = function (RED) {
118119
personality_insights = new PersonalityInsightsV3({
119120
username: username,
120121
password: password,
121-
version_date: '2016-10-20'
122+
version_date: '2016-12-15'
122123
});
123124

124125
node.status({fill:'blue', shape:'dot', text:'requesting'});

utilities/service-utils.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ ServiceUtils.prototype = {
2222
// name may fail because of duplicate usage. This function verifies
2323
// that the url associated with the service, contains the matched
2424
// input value, hence reducing the chances of a false match.
25-
checkCFForService: function(serviceName, returnBoolean) {
26-
var regex = new RegExp('(http|https)(://)([^\/]+)(/)('+serviceName+').*');
25+
checkCFForService: function(serviceName, returnBoolean, alchemyRegex) {
26+
var regex = alchemyRegex ?
27+
RegExp('(http|https)(://)('+serviceName+').*') :
28+
RegExp('(http|https)(://)([^\/]+)(/)('+serviceName+').*');
29+
2730
var services = appEnv.getServices();
31+
2832
for (var service in services) {
2933
if (services[service].hasOwnProperty('credentials')) {
3034
if(services[service].credentials.hasOwnProperty('url')){
@@ -39,13 +43,17 @@ ServiceUtils.prototype = {
3943

4044
// Check for service return a boolean to indicate if it is bound in
4145
checkServiceBound: function(serviceName) {
42-
return ServiceUtils.prototype.checkCFForService(serviceName, true);
46+
return ServiceUtils.prototype.checkCFForService(serviceName, true, false);
4347
},
4448

4549
// Check for and return bound servie
4650
getServiceCreds: function(serviceName) {
47-
return ServiceUtils.prototype.checkCFForService(serviceName, false);
48-
}
51+
return ServiceUtils.prototype.checkCFForService(serviceName, false, false);
52+
},
53+
54+
getServiceCredsAlchemy: function(serviceName) {
55+
return ServiceUtils.prototype.checkCFForService(serviceName, false, true);
56+
},
4957

5058
};
5159

0 commit comments

Comments
 (0)