{"action":"created","comment":{"url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/pulls/comments/54906127","id":54906127,"diff_hunk":"@@ -0,0 +1,177 @@\n+_ = require('lodash')\n+flat = require('flat')\n+soap = require('soap')\n+\n+validate = require('./validate')\n+\n+helpers = require('./helpers')\n+ensureArray = helpers.ensureArray\n+inverseOutcome = helpers.inverseOutcome\n+toRegex = helpers.toRegex\n+\n+\n+\n+handle = (vars, callback) ->\n+\n+  vars = flat.unflatten(vars)\n+\n+  # get SOAP function arguments\n+  args = flat.flatten(vars.arg ? {})\n+  args = _.mapValues args, (value) ->\n+    value.valueOf()\n+  args = flat.unflatten(args)\n+\n+\n+  options =\n+    valueKey: '#value'\n+    forceSoap12Headers: vars.version?.trim() == '1.2'\n+\n+  soap.createClient vars.url, options, (err, client) ->\n+    return callback(err) if err\n+\n+    # the SOAP function to execute\n+    fxn = client[vars.function]\n+\n+    # ensure the SOAP function is supported\n+    return callback(new Error('Unsupported SOAP function specified')) unless fxn\n+\n+    # build the security credentials\n+    security =\n+      if vars.basic_username and vars.basic_password\n+        new soap.BasicAuthSecurity(vars.basic_username, vars.basic_password)\n+      else if vars.bearer_token\n+        new soap.BearerSecurity(vars.bearer_token)\n+      else if vars.ws_username and vars.ws_password\n+        passwordType =\n+          if vars.ws_digest_password\n+            'PasswordDigest'\n+          else\n+            'PasswordText'\n+        new soap.WSSecurity(vars.ws_username, vars.ws_password, passwordType: passwordType)\n+\n+    # set the security credentials\n+    client.setSecurity(security) if security\n+\n+    # the callback to handle the SOAP function response\n+    handleResponse = (err, result, body) ->\n+      fault = err?.root?.Envelope?.Body?.Fault\n+      if fault?\n+        return callback null, outcome: 'error', reason: fault.faultstring ? fault.faultcode\n+      else if err\n+        return callback(err)\n+\n+      searchTerm = toRegex(vars.outcome_search_term)\n+      searchOutcome = vars.outcome_on_match?.trim().toLowerCase() ? 'success'\n+      searchPath = vars.outcome_search_path?.trim()\n+      reasonSelector = vars.reason_path?.trim()\n+\n+      # narrow the search scope\n+      searchIn =\n+        if searchPath\n+          # limit outcome_search_term to this path in the document\n+          _.get(result, searchPath).toString()\n+\n+        else\n+          # no search path was provided, so search the entire response body\n+          body\n+\n+      # look in all possible search scopes for the term\n+      found = searchIn.match(searchTerm)\n+\n+      # determine the outcome based on whether the search term was found\n+      outcome =\n+        if found\n+          searchOutcome\n+        else\n+          inverseOutcome(searchOutcome)\n+\n+      # determine the reason based on the reason selector\n+      reasons =\n+        if reasonSelector\n+          _.get(result, reasonSelector)\n+        else\n+          []\n+\n+      # trim and comma delimit reasons\n+      reason = _(ensureArray(reasons))\n+        .map _.trim\n+        .compact()\n+        .sort()\n+        .join(', ')\n+\n+      # set the default reason, if necessary\n+      reason or= vars.default_reason?.trim()\n+\n+      # build the event\n+      event = result\n+      event.outcome = outcome\n+      event.reason = reason if reason\n+\n+      # return the event\n+      callback null, event\n+\n+    # calculate the timeout\n+    timeoutMs = (vars.timeout_seconds ? 10) * 1000\n+\n+    # call the function\n+    fxn args, handleResponse, timeout: timeoutMs\n+\n+\n+\n+#\n+# Validate ---------------------------------------------------------------\n+#\n+\n+functionRegex = /^[a-zA-Z0-9_]+$/\n+\n+validateFunction = (vars) ->\n+  return 'Function is required' unless vars.function?\n+  return 'Function must have valid name' unless vars.function.match(functionRegex)\n+\n+\n+\n+\n+#\n+# Variables --------------------------------------------------------------\n+#\n+\n+requestVariables = ->\n+  [\n+    { name: 'url', description: 'WSDL URL', type: 'string', required: true }\n+    { name: 'function', description: 'Name of the SOAP function to call', type: 'string', required: true }\n+    { name: 'version', description: 'SOAP version to use: 1.1 or 1.2 (default: 1.1)', type: 'string', required: false }\n+    { name: 'basic_username', description: 'HTTP Basic Authentication user name', type: 'string', required: false }\n+    { name: 'basic_password', description: 'HTTP Basic Authentication password', type: 'string', required: false }\n+    { name: 'bearer_token', description: 'HTTP Bearer Token', type: 'string', required: false }\n+    { name: 'ws_username', description: 'WS Security user name', type: 'string', required: false }\n+    { name: 'ws_password', description: 'WS Security password', type: 'string', required: false }\n+    { name: 'ws_digest_password', description: 'Digest the WS Password (default: true)', type: 'boolean', required: false }\n+    { name: 'arg.*', description: 'Named function argument', type: 'wildcard', required: false }","path":"src/soap.coffee","position":149,"original_position":149,"commit_id":"bef8789f8f9fb4822f16c51867054689224b5d46","original_commit_id":"bef8789f8f9fb4822f16c51867054689224b5d46","user":{"login":"cgrayson","id":5596,"avatar_url":"https://avatars.githubusercontent.com/u/5596?v=3","gravatar_id":"","url":"https://api.github.com/users/cgrayson","html_url":"https://github.com/cgrayson","followers_url":"https://api.github.com/users/cgrayson/followers","following_url":"https://api.github.com/users/cgrayson/following{/other_user}","gists_url":"https://api.github.com/users/cgrayson/gists{/gist_id}","starred_url":"https://api.github.com/users/cgrayson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cgrayson/subscriptions","organizations_url":"https://api.github.com/users/cgrayson/orgs","repos_url":"https://api.github.com/users/cgrayson/repos","events_url":"https://api.github.com/users/cgrayson/events{/privacy}","received_events_url":"https://api.github.com/users/cgrayson/received_events","type":"User","site_admin":false},"body":"Avast, mate! :stuck_out_tongue: ","created_at":"2016-03-03T16:34:51Z","updated_at":"2016-03-03T16:34:51Z","html_url":"https://github.com/activeprospect/leadconduit-integration-custom/pull/9#discussion_r54906127","pull_request_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/pulls/comments/54906127"},"html":{"href":"https://github.com/activeprospect/leadconduit-integration-custom/pull/9#discussion_r54906127"},"pull_request":{"href":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/pulls/9","id":61503086,"html_url":"https://github.com/activeprospect/leadconduit-integration-custom/pull/9","diff_url":"https://github.com/activeprospect/leadconduit-integration-custom/pull/9.diff","patch_url":"https://github.com/activeprospect/leadconduit-integration-custom/pull/9.patch","issue_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/issues/9","number":9,"state":"open","locked":false,"title":"Add custom SOAP outbound","user":{"login":"alexkwolfe","id":569,"avatar_url":"https://avatars.githubusercontent.com/u/569?v=3","gravatar_id":"","url":"https://api.github.com/users/alexkwolfe","html_url":"https://github.com/alexkwolfe","followers_url":"https://api.github.com/users/alexkwolfe/followers","following_url":"https://api.github.com/users/alexkwolfe/following{/other_user}","gists_url":"https://api.github.com/users/alexkwolfe/gists{/gist_id}","starred_url":"https://api.github.com/users/alexkwolfe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexkwolfe/subscriptions","organizations_url":"https://api.github.com/users/alexkwolfe/orgs","repos_url":"https://api.github.com/users/alexkwolfe/repos","events_url":"https://api.github.com/users/alexkwolfe/events{/privacy}","received_events_url":"https://api.github.com/users/alexkwolfe/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-03-03T02:48:25Z","updated_at":"2016-03-03T16:34:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f23c540ed5775b815e5b2cc275a56dbf1e757bc0","assignee":{"login":"cgrayson","id":5596,"avatar_url":"https://avatars.githubusercontent.com/u/5596?v=3","gravatar_id":"","url":"https://api.github.com/users/cgrayson","html_url":"https://github.com/cgrayson","followers_url":"https://api.github.com/users/cgrayson/followers","following_url":"https://api.github.com/users/cgrayson/following{/other_user}","gists_url":"https://api.github.com/users/cgrayson/gists{/gist_id}","starred_url":"https://api.github.com/users/cgrayson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cgrayson/subscriptions","organizations_url":"https://api.github.com/users/cgrayson/orgs","repos_url":"https://api.github.com/users/cgrayson/repos","events_url":"https://api.github.com/users/cgrayson/events{/privacy}","received_events_url":"https://api.github.com/users/cgrayson/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/pulls/9/commits","review_comments_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/pulls/9/comments","review_comment_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/pulls/comments{/number}","comments_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/issues/9/comments","statuses_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/statuses/bef8789f8f9fb4822f16c51867054689224b5d46","head":{"label":"activeprospect:soap","ref":"soap","sha":"bef8789f8f9fb4822f16c51867054689224b5d46","user":{"login":"activeprospect","id":245554,"avatar_url":"https://avatars.githubusercontent.com/u/245554?v=3","gravatar_id":"","url":"https://api.github.com/users/activeprospect","html_url":"https://github.com/activeprospect","followers_url":"https://api.github.com/users/activeprospect/followers","following_url":"https://api.github.com/users/activeprospect/following{/other_user}","gists_url":"https://api.github.com/users/activeprospect/gists{/gist_id}","starred_url":"https://api.github.com/users/activeprospect/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/activeprospect/subscriptions","organizations_url":"https://api.github.com/users/activeprospect/orgs","repos_url":"https://api.github.com/users/activeprospect/repos","events_url":"https://api.github.com/users/activeprospect/events{/privacy}","received_events_url":"https://api.github.com/users/activeprospect/received_events","type":"Organization","site_admin":false},"repo":{"id":51462047,"name":"leadconduit-integration-custom","full_name":"activeprospect/leadconduit-integration-custom","owner":{"login":"activeprospect","id":245554,"avatar_url":"https://avatars.githubusercontent.com/u/245554?v=3","gravatar_id":"","url":"https://api.github.com/users/activeprospect","html_url":"https://github.com/activeprospect","followers_url":"https://api.github.com/users/activeprospect/followers","following_url":"https://api.github.com/users/activeprospect/following{/other_user}","gists_url":"https://api.github.com/users/activeprospect/gists{/gist_id}","starred_url":"https://api.github.com/users/activeprospect/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/activeprospect/subscriptions","organizations_url":"https://api.github.com/users/activeprospect/orgs","repos_url":"https://api.github.com/users/activeprospect/repos","events_url":"https://api.github.com/users/activeprospect/events{/privacy}","received_events_url":"https://api.github.com/users/activeprospect/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/activeprospect/leadconduit-integration-custom","description":"Custom LeadConduit integration","fork":false,"url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom","forks_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/forks","keys_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/keys{/key_id}","collaborators_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/teams","hooks_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/hooks","issue_events_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/issues/events{/number}","events_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/events","assignees_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/assignees{/user}","branches_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/branches{/branch}","tags_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/tags","blobs_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/git/refs{/sha}","trees_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/git/trees{/sha}","statuses_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/statuses/{sha}","languages_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/languages","stargazers_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/stargazers","contributors_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/contributors","subscribers_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/subscribers","subscription_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/subscription","commits_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/commits{/sha}","git_commits_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/git/commits{/sha}","comments_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/comments{/number}","issue_comment_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/issues/comments{/number}","contents_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/contents/{+path}","compare_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/compare/{base}...{head}","merges_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/merges","archive_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/downloads","issues_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/issues{/number}","pulls_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/pulls{/number}","milestones_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/milestones{/number}","notifications_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/labels{/name}","releases_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/releases{/id}","deployments_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/deployments","created_at":"2016-02-10T18:30:53Z","updated_at":"2016-02-15T17:28:06Z","pushed_at":"2016-03-03T02:48:26Z","git_url":"git://github.com/activeprospect/leadconduit-integration-custom.git","ssh_url":"git@github.com:activeprospect/leadconduit-integration-custom.git","clone_url":"https://github.com/activeprospect/leadconduit-integration-custom.git","svn_url":"https://github.com/activeprospect/leadconduit-integration-custom","homepage":"","size":30,"stargazers_count":0,"watchers_count":0,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"activeprospect:master","ref":"master","sha":"9f3532f2c608aa51c3c288c623213bc60b6a084a","user":{"login":"activeprospect","id":245554,"avatar_url":"https://avatars.githubusercontent.com/u/245554?v=3","gravatar_id":"","url":"https://api.github.com/users/activeprospect","html_url":"https://github.com/activeprospect","followers_url":"https://api.github.com/users/activeprospect/followers","following_url":"https://api.github.com/users/activeprospect/following{/other_user}","gists_url":"https://api.github.com/users/activeprospect/gists{/gist_id}","starred_url":"https://api.github.com/users/activeprospect/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/activeprospect/subscriptions","organizations_url":"https://api.github.com/users/activeprospect/orgs","repos_url":"https://api.github.com/users/activeprospect/repos","events_url":"https://api.github.com/users/activeprospect/events{/privacy}","received_events_url":"https://api.github.com/users/activeprospect/received_events","type":"Organization","site_admin":false},"repo":{"id":51462047,"name":"leadconduit-integration-custom","full_name":"activeprospect/leadconduit-integration-custom","owner":{"login":"activeprospect","id":245554,"avatar_url":"https://avatars.githubusercontent.com/u/245554?v=3","gravatar_id":"","url":"https://api.github.com/users/activeprospect","html_url":"https://github.com/activeprospect","followers_url":"https://api.github.com/users/activeprospect/followers","following_url":"https://api.github.com/users/activeprospect/following{/other_user}","gists_url":"https://api.github.com/users/activeprospect/gists{/gist_id}","starred_url":"https://api.github.com/users/activeprospect/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/activeprospect/subscriptions","organizations_url":"https://api.github.com/users/activeprospect/orgs","repos_url":"https://api.github.com/users/activeprospect/repos","events_url":"https://api.github.com/users/activeprospect/events{/privacy}","received_events_url":"https://api.github.com/users/activeprospect/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/activeprospect/leadconduit-integration-custom","description":"Custom LeadConduit integration","fork":false,"url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom","forks_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/forks","keys_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/keys{/key_id}","collaborators_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/teams","hooks_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/hooks","issue_events_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/issues/events{/number}","events_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/events","assignees_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/assignees{/user}","branches_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/branches{/branch}","tags_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/tags","blobs_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/git/refs{/sha}","trees_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/git/trees{/sha}","statuses_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/statuses/{sha}","languages_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/languages","stargazers_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/stargazers","contributors_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/contributors","subscribers_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/subscribers","subscription_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/subscription","commits_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/commits{/sha}","git_commits_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/git/commits{/sha}","comments_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/comments{/number}","issue_comment_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/issues/comments{/number}","contents_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/contents/{+path}","compare_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/compare/{base}...{head}","merges_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/merges","archive_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/downloads","issues_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/issues{/number}","pulls_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/pulls{/number}","milestones_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/milestones{/number}","notifications_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/labels{/name}","releases_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/releases{/id}","deployments_url":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/deployments","created_at":"2016-02-10T18:30:53Z","updated_at":"2016-02-15T17:28:06Z","pushed_at":"2016-03-03T02:48:26Z","git_url":"git://github.com/activeprospect/leadconduit-integration-custom.git","ssh_url":"git@github.com:activeprospect/leadconduit-integration-custom.git","clone_url":"https://github.com/activeprospect/leadconduit-integration-custom.git","svn_url":"https://github.com/activeprospect/leadconduit-integration-custom","homepage":"","size":30,"stargazers_count":0,"watchers_count":0,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/pulls/9"},"html":{"href":"https://github.com/activeprospect/leadconduit-integration-custom/pull/9"},"issue":{"href":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/issues/9"},"comments":{"href":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/activeprospect/leadconduit-integration-custom/statuses/bef8789f8f9fb4822f16c51867054689224b5d46"}}}}