util/watson.js
function(options, content, res) {
  return function (/*function*/ callback) {
    // create the post data to send to the User Modeling service
    var post_data = {
      'contentItems' : [{ 
        'userid' : 'dummy',
        'id' : 'dummyUuid',
        'sourceid' : 'freetext',
        'contenttype' : 'text/plain',
        'language' : 'en',
        'content': content
      }]
    };
    // Create a request to POST to the User Modeling service
    var profile_req = https.request(options, function(result) {
      result.setEncoding('utf-8');
      var response_string = '';

      result.on('data', function(chunk) {
        response_string += chunk;
      });
      
      result.on('end', function() {
        if (result.statusCode != 200) {
          var error = JSON.parse(response_string);
          // render error if the results are less than 100 words
          callback({'message': error.user_message}, null);
        } else
          callback(null,response_string);
      });
    });
  
    profile_req.on('error', function(e) {
      callback(e,null);
    });

    profile_req.write(JSON.stringify(post_data));
    profile_req.end();
  }
}
function(options, content, res) {
  return function (/*function*/ callback) {
    // create the post data to send to the User Modeling service
    var post_data = {
      'contentItems' : [{ 
        'userid' : 'dummy',
        'id' : 'dummyUuid',
        'sourceid' : 'freetext',
        'contenttype' : 'text/plain',
        'language' : 'en',
        'content': content
      }]
    };
    // Create a request to POST to the User Modeling service
    var profile_req = https.request(options, function(result) {
      result.setEncoding('utf-8');
      var response_string = '';

      result.on('data', function(chunk) {
        response_string += chunk;
      });
      
      result.on('end', function() {
        if (result.statusCode != 200) {
          var error = JSON.parse(response_string);
          // render error if the results are less than 100 words
          callback({'message': error.user_message}, null);
        } else
          callback(null,response_string);
      });
    });
  
    profile_req.on('error', function(e) {
      callback(e,null);
    });

    profile_req.write(JSON.stringify(post_data));
    profile_req.end();
  }
}
function ( options , content , res ) { return function ( /*function*/ callback ) { // create the post data to send to the User Modeling service var post_data = { 'contentItems' : [ { 'userid' : 'dummy' , 'id' : 'dummyUuid' , 'sourceid' : 'freetext' , 'contenttype' : 'text/plain' , 'language' : 'en' , 'content' : content } ] } ; // Create a request to POST to the User Modeling service var profile_req = https . request ( options , function ( result ) { result . setEncoding ( 'utf-8' ) ; var response_string = '' ; result . on ( 'data' , function ( chunk ) { response_string += chunk ; } ) ; result . on ( 'end' , function ( ) { if ( result . statusCode != 200 ) { var error = JSON . parse ( response_string ) ; // render error if the results are less than 100 words callback ( { 'message' : error . user_message } , null ) ; } else callback ( null , response_string ) ; } ) ; } ) ; profile_req . on ( 'error' , function ( e ) { callback ( e , null ) ; } ) ; profile_req . write ( JSON . stringify ( post_data ) ) ; profile_req . end ( ) ; } }
creates a request function using the https options and the text in content the function that return receives a callback
creates a request function using the https options and the text in content the function that return receives a callback