1717module . exports = function ( RED ) {
1818 var watson = require ( 'watson-developer-cloud' ) ;
1919 var cfenv = require ( 'cfenv' ) ;
20+ var toneutils = require ( '../../utilities/tone-utils' ) ;
2021
2122 // Require the Cloud Foundry Module to pull credentials from bound service
2223 // If they are found then they are stored in sUsername and sPassword, as the
@@ -37,31 +38,13 @@ module.exports = function (RED) {
3738 sPassword = service . password ;
3839 }
3940
41+ //toneutils.ping();
42+
4043 // Node RED Admin - fetch and set vcap services
4144 RED . httpAdmin . get ( '/watson-tone-analyzer/vcap' , function ( req , res ) {
4245 res . json ( service ? { bound_service : true } : null ) ;
4346 } ) ;
4447
45- // Function that checks the payload and determines
46- // whether it is JSON or a Buffer
47- var checkPayload = function ( payload ) {
48- var message = null ;
49- var isBuffer = false ;
50-
51- var hasJSONmethod = ( typeof payload . toJSON === 'function' ) ;
52-
53- if ( hasJSONmethod === true ) {
54- if ( payload . toJSON ( ) . type === 'Buffer' ) {
55- isBuffer = true ;
56- }
57- }
58- // Payload (text to be analysed) must be a string (content is either raw string or Buffer)
59- if ( typeof payload !== 'string' && isBuffer !== true ) {
60- message = 'The payload must be either a string or a Buffer' ;
61- }
62-
63- return message ;
64- } ;
6548
6649 // Check that the credentials have been provided
6750 // Credentials are needed for each the service.
@@ -92,7 +75,7 @@ module.exports = function (RED) {
9275 if ( ! taSettings ) {
9376 message = 'Missing Tone Analyzer service credentials' ;
9477 } else if ( msg . payload ) {
95- message = checkPayload ( msg . payload ) ;
78+ message = toneutils . checkPayload ( msg . payload ) ;
9679 } else {
9780 message = 'Missing property: msg.payload' ;
9881 }
0 commit comments