{"action":"created","comment":{"url":"https://api.github.com/repos/chughts/node-red-node-watson/pulls/comments/65798110","id":65798110,"diff_hunk":"@@ -0,0 +1,141 @@\n+/**\n+ * Copyright 2013,2016 IBM Corp.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ **/\n+\n+module.exports = function (RED) {\n+  var watson = require('watson-developer-cloud');  \n+  var cfenv = require('cfenv');\n+  var toneutils = require('../../utilities/tone-utils');\n+\n+  // Require the Cloud Foundry Module to pull credentials from bound service \n+  // If they are found then they are stored in sUsername and sPassword, as the \n+  // service credentials. This separation from sUsername and username to allow \n+  // the end user to modify the node credentials when the service is not bound.\n+  // Otherwise, once set username would never get reset, resulting in a frustrated\n+  // user who, when he errenously enters bad credentials, can't figure out why\n+  // the edited ones are not being taken.\n+\n+  // Not ever used, and codeacy complains about it.\n+\n+  var username, password, sUsername, sPassword;\n+\n+  var service = cfenv.getAppEnv().getServiceCreds(/tone analyzer/i)\n+\n+  if (service) {\n+    sUsername = service.username;\n+    sPassword = service.password;\n+  }\n+\n+\n+  // Node RED Admin - fetch and set vcap services\n+  RED.httpAdmin.get('/watson-tone-analyzer/vcap', function (req, res) {\n+    res.json(service ? {bound_service: true} : null);\n+  });\n+\n+\n+  // Check that the credentials have been provided\n+  // Credentials are needed for each the service.\n+  var checkCreds = function(credentials) {\n+    var taSettings = null;\n+\n+    username = sUsername || credentials.username;\n+    password = sPassword || credentials.password;      \n+\n+    if (username && password) {\n+      taSettings = {};\n+      taSettings.username = username;\n+      taSettings.password = password;\n+    }\n+\n+    return taSettings;\n+  }\n+\n+\n+  // Function that checks the configuration to make sure that credentials,\n+  // payload and options have been provied in the correct format.\n+  var checkConfiguration = function(msg, node, cb) {\n+    var message = null;      \n+    var taSettings = null;\n+\n+    taSettings = checkCreds(node.credentials);\n+\n+    if (!taSettings) {\n+      message = 'Missing Tone Analyzer service credentials';\n+    } else if (msg.payload) {\n+      message = toneutils.checkPayload(msg.payload);\n+    } else  {\n+      message = 'Missing property: msg.payload';\n+    }\n+\n+    if (cb) {\n+      cb(message, taSettings);\n+    }\n+  };\n+\n+\n+  // function when the node recieves input inside a flow. \n+  // Configuration is first checked before the service is invoked.\n+  var processOnInput = function(msg, config, node) {\n+    checkConfiguration (msg, node, function(err, settings){\n+      if (err) {\n+        node.status({fill:'red', shape:'dot', text:err}); \n+        node.error(err, msg);\n+        return;\n+      } else {\n+        var tone_analyzer = watson.tone_analyzer({\n+          'username': settings.username,\n+          'password': settings.password,\n+          'version': 'v3',\n+          'version_date': '2016-05-19'\n+        });\n+\n+        var options = toneutils.parseOptions(msg, config);\n+    \n+        node.status({fill:'blue', shape:'dot', text:'requesting'});\n+        tone_analyzer.tone(options, function (err, response) {","path":"services/tone_analyzer/v3.js","position":107,"original_position":107,"commit_id":"cb36248baf265b915b16f27f5ecfe4ea5cf59203","original_commit_id":"cb36248baf265b915b16f27f5ecfe4ea5cf59203","user":{"login":"chughts","id":10371360,"avatar_url":"https://avatars.githubusercontent.com/u/10371360?v=3","gravatar_id":"","url":"https://api.github.com/users/chughts","html_url":"https://github.com/chughts","followers_url":"https://api.github.com/users/chughts/followers","following_url":"https://api.github.com/users/chughts/following{/other_user}","gists_url":"https://api.github.com/users/chughts/gists{/gist_id}","starred_url":"https://api.github.com/users/chughts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chughts/subscriptions","organizations_url":"https://api.github.com/users/chughts/orgs","repos_url":"https://api.github.com/users/chughts/repos","events_url":"https://api.github.com/users/chughts/events{/privacy}","received_events_url":"https://api.github.com/users/chughts/received_events","type":"User","site_admin":false},"body":"![Codacy](https://www.codacy.com/assets/images/favicon.png) Issue found: [Identifier 'tone_analyzer' is not in camel case.](https://www.codacy.com/app/soheel_chughtai/chughts-node-red-node-watson/file/2690702778/issues/source?bid=3330826&fileBranchId=3339101#l107)","created_at":"2016-06-04T06:04:55Z","updated_at":"2016-06-04T06:04:55Z","html_url":"https://github.com/chughts/node-red-node-watson/pull/17#discussion_r65798110","pull_request_url":"https://api.github.com/repos/chughts/node-red-node-watson/pulls/17","_links":{"self":{"href":"https://api.github.com/repos/chughts/node-red-node-watson/pulls/comments/65798110"},"html":{"href":"https://github.com/chughts/node-red-node-watson/pull/17#discussion_r65798110"},"pull_request":{"href":"https://api.github.com/repos/chughts/node-red-node-watson/pulls/17"}}},"pull_request":{"url":"https://api.github.com/repos/chughts/node-red-node-watson/pulls/17","id":72594252,"html_url":"https://github.com/chughts/node-red-node-watson/pull/17","diff_url":"https://github.com/chughts/node-red-node-watson/pull/17.diff","patch_url":"https://github.com/chughts/node-red-node-watson/pull/17.patch","issue_url":"https://api.github.com/repos/chughts/node-red-node-watson/issues/17","number":17,"state":"open","locked":false,"title":"new PR for VR v3","user":{"login":"ylecleach","id":7034390,"avatar_url":"https://avatars.githubusercontent.com/u/7034390?v=3","gravatar_id":"","url":"https://api.github.com/users/ylecleach","html_url":"https://github.com/ylecleach","followers_url":"https://api.github.com/users/ylecleach/followers","following_url":"https://api.github.com/users/ylecleach/following{/other_user}","gists_url":"https://api.github.com/users/ylecleach/gists{/gist_id}","starred_url":"https://api.github.com/users/ylecleach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ylecleach/subscriptions","organizations_url":"https://api.github.com/users/ylecleach/orgs","repos_url":"https://api.github.com/users/ylecleach/repos","events_url":"https://api.github.com/users/ylecleach/events{/privacy}","received_events_url":"https://api.github.com/users/ylecleach/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-06-04T06:01:37Z","updated_at":"2016-06-04T06:04:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/chughts/node-red-node-watson/pulls/17/commits","review_comments_url":"https://api.github.com/repos/chughts/node-red-node-watson/pulls/17/comments","review_comment_url":"https://api.github.com/repos/chughts/node-red-node-watson/pulls/comments{/number}","comments_url":"https://api.github.com/repos/chughts/node-red-node-watson/issues/17/comments","statuses_url":"https://api.github.com/repos/chughts/node-red-node-watson/statuses/cb36248baf265b915b16f27f5ecfe4ea5cf59203","head":{"label":"ylecleach:master","ref":"master","sha":"cb36248baf265b915b16f27f5ecfe4ea5cf59203","user":{"login":"ylecleach","id":7034390,"avatar_url":"https://avatars.githubusercontent.com/u/7034390?v=3","gravatar_id":"","url":"https://api.github.com/users/ylecleach","html_url":"https://github.com/ylecleach","followers_url":"https://api.github.com/users/ylecleach/followers","following_url":"https://api.github.com/users/ylecleach/following{/other_user}","gists_url":"https://api.github.com/users/ylecleach/gists{/gist_id}","starred_url":"https://api.github.com/users/ylecleach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ylecleach/subscriptions","organizations_url":"https://api.github.com/users/ylecleach/orgs","repos_url":"https://api.github.com/users/ylecleach/repos","events_url":"https://api.github.com/users/ylecleach/events{/privacy}","received_events_url":"https://api.github.com/users/ylecleach/received_events","type":"User","site_admin":false},"repo":{"id":56971768,"name":"node-red-node-watson","full_name":"ylecleach/node-red-node-watson","owner":{"login":"ylecleach","id":7034390,"avatar_url":"https://avatars.githubusercontent.com/u/7034390?v=3","gravatar_id":"","url":"https://api.github.com/users/ylecleach","html_url":"https://github.com/ylecleach","followers_url":"https://api.github.com/users/ylecleach/followers","following_url":"https://api.github.com/users/ylecleach/following{/other_user}","gists_url":"https://api.github.com/users/ylecleach/gists{/gist_id}","starred_url":"https://api.github.com/users/ylecleach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ylecleach/subscriptions","organizations_url":"https://api.github.com/users/ylecleach/orgs","repos_url":"https://api.github.com/users/ylecleach/repos","events_url":"https://api.github.com/users/ylecleach/events{/privacy}","received_events_url":"https://api.github.com/users/ylecleach/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ylecleach/node-red-node-watson","description":"A collection of nodes for the IBM Watson services","fork":true,"url":"https://api.github.com/repos/ylecleach/node-red-node-watson","forks_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/forks","keys_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/teams","hooks_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/hooks","issue_events_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/issues/events{/number}","events_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/events","assignees_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/assignees{/user}","branches_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/branches{/branch}","tags_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/tags","blobs_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/git/refs{/sha}","trees_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/statuses/{sha}","languages_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/languages","stargazers_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/stargazers","contributors_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/contributors","subscribers_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/subscribers","subscription_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/subscription","commits_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/commits{/sha}","git_commits_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/git/commits{/sha}","comments_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/comments{/number}","issue_comment_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/issues/comments{/number}","contents_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/contents/{+path}","compare_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/merges","archive_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/downloads","issues_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/issues{/number}","pulls_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/pulls{/number}","milestones_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/milestones{/number}","notifications_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/labels{/name}","releases_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/releases{/id}","deployments_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/deployments","created_at":"2016-04-24T13:02:37Z","updated_at":"2016-04-24T13:02:38Z","pushed_at":"2016-06-04T04:43:46Z","git_url":"git://github.com/ylecleach/node-red-node-watson.git","ssh_url":"git@github.com:ylecleach/node-red-node-watson.git","clone_url":"https://github.com/ylecleach/node-red-node-watson.git","svn_url":"https://github.com/ylecleach/node-red-node-watson","homepage":null,"size":7742,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"chughts:master","ref":"master","sha":"52cb5466d8ad5401c3b6176d353806ae4f839013","user":{"login":"chughts","id":10371360,"avatar_url":"https://avatars.githubusercontent.com/u/10371360?v=3","gravatar_id":"","url":"https://api.github.com/users/chughts","html_url":"https://github.com/chughts","followers_url":"https://api.github.com/users/chughts/followers","following_url":"https://api.github.com/users/chughts/following{/other_user}","gists_url":"https://api.github.com/users/chughts/gists{/gist_id}","starred_url":"https://api.github.com/users/chughts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chughts/subscriptions","organizations_url":"https://api.github.com/users/chughts/orgs","repos_url":"https://api.github.com/users/chughts/repos","events_url":"https://api.github.com/users/chughts/events{/privacy}","received_events_url":"https://api.github.com/users/chughts/received_events","type":"User","site_admin":false},"repo":{"id":58115630,"name":"node-red-node-watson","full_name":"chughts/node-red-node-watson","owner":{"login":"chughts","id":10371360,"avatar_url":"https://avatars.githubusercontent.com/u/10371360?v=3","gravatar_id":"","url":"https://api.github.com/users/chughts","html_url":"https://github.com/chughts","followers_url":"https://api.github.com/users/chughts/followers","following_url":"https://api.github.com/users/chughts/following{/other_user}","gists_url":"https://api.github.com/users/chughts/gists{/gist_id}","starred_url":"https://api.github.com/users/chughts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chughts/subscriptions","organizations_url":"https://api.github.com/users/chughts/orgs","repos_url":"https://api.github.com/users/chughts/repos","events_url":"https://api.github.com/users/chughts/events{/privacy}","received_events_url":"https://api.github.com/users/chughts/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/chughts/node-red-node-watson","description":"A collection of nodes for the IBM Watson services","fork":true,"url":"https://api.github.com/repos/chughts/node-red-node-watson","forks_url":"https://api.github.com/repos/chughts/node-red-node-watson/forks","keys_url":"https://api.github.com/repos/chughts/node-red-node-watson/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chughts/node-red-node-watson/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chughts/node-red-node-watson/teams","hooks_url":"https://api.github.com/repos/chughts/node-red-node-watson/hooks","issue_events_url":"https://api.github.com/repos/chughts/node-red-node-watson/issues/events{/number}","events_url":"https://api.github.com/repos/chughts/node-red-node-watson/events","assignees_url":"https://api.github.com/repos/chughts/node-red-node-watson/assignees{/user}","branches_url":"https://api.github.com/repos/chughts/node-red-node-watson/branches{/branch}","tags_url":"https://api.github.com/repos/chughts/node-red-node-watson/tags","blobs_url":"https://api.github.com/repos/chughts/node-red-node-watson/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chughts/node-red-node-watson/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chughts/node-red-node-watson/git/refs{/sha}","trees_url":"https://api.github.com/repos/chughts/node-red-node-watson/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chughts/node-red-node-watson/statuses/{sha}","languages_url":"https://api.github.com/repos/chughts/node-red-node-watson/languages","stargazers_url":"https://api.github.com/repos/chughts/node-red-node-watson/stargazers","contributors_url":"https://api.github.com/repos/chughts/node-red-node-watson/contributors","subscribers_url":"https://api.github.com/repos/chughts/node-red-node-watson/subscribers","subscription_url":"https://api.github.com/repos/chughts/node-red-node-watson/subscription","commits_url":"https://api.github.com/repos/chughts/node-red-node-watson/commits{/sha}","git_commits_url":"https://api.github.com/repos/chughts/node-red-node-watson/git/commits{/sha}","comments_url":"https://api.github.com/repos/chughts/node-red-node-watson/comments{/number}","issue_comment_url":"https://api.github.com/repos/chughts/node-red-node-watson/issues/comments{/number}","contents_url":"https://api.github.com/repos/chughts/node-red-node-watson/contents/{+path}","compare_url":"https://api.github.com/repos/chughts/node-red-node-watson/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chughts/node-red-node-watson/merges","archive_url":"https://api.github.com/repos/chughts/node-red-node-watson/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chughts/node-red-node-watson/downloads","issues_url":"https://api.github.com/repos/chughts/node-red-node-watson/issues{/number}","pulls_url":"https://api.github.com/repos/chughts/node-red-node-watson/pulls{/number}","milestones_url":"https://api.github.com/repos/chughts/node-red-node-watson/milestones{/number}","notifications_url":"https://api.github.com/repos/chughts/node-red-node-watson/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chughts/node-red-node-watson/labels{/name}","releases_url":"https://api.github.com/repos/chughts/node-red-node-watson/releases{/id}","deployments_url":"https://api.github.com/repos/chughts/node-red-node-watson/deployments","created_at":"2016-05-05T08:19:28Z","updated_at":"2016-05-14T07:16:53Z","pushed_at":"2016-06-04T06:01:38Z","git_url":"git://github.com/chughts/node-red-node-watson.git","ssh_url":"git@github.com:chughts/node-red-node-watson.git","clone_url":"https://github.com/chughts/node-red-node-watson.git","svn_url":"https://github.com/chughts/node-red-node-watson","homepage":null,"size":7784,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/chughts/node-red-node-watson/pulls/17"},"html":{"href":"https://github.com/chughts/node-red-node-watson/pull/17"},"issue":{"href":"https://api.github.com/repos/chughts/node-red-node-watson/issues/17"},"comments":{"href":"https://api.github.com/repos/chughts/node-red-node-watson/issues/17/comments"},"review_comments":{"href":"https://api.github.com/repos/chughts/node-red-node-watson/pulls/17/comments"},"review_comment":{"href":"https://api.github.com/repos/chughts/node-red-node-watson/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/chughts/node-red-node-watson/pulls/17/commits"},"statuses":{"href":"https://api.github.com/repos/chughts/node-red-node-watson/statuses/cb36248baf265b915b16f27f5ecfe4ea5cf59203"}}}}
{"actor":{"display_login":"chughts"}}