{"action":"created","comment":{"url":"https://api.github.com/repos/medic/medic-api/pulls/comments/64735451","id":64735451,"diff_hunk":"@@ -0,0 +1,187 @@\n+/**\n+ * This module implements GET and POST to support medic-gateway's API\n+ * @see https://github.com/medic/medic-gateway\n+ */\n+\n+var _ = require('underscore'),\n+    db = require('../db'),\n+    http = require('http'),\n+    querystring = require('querystring'),\n+    utils = require('./utils'),\n+    messageUtils = require('./messages');\n+\n+require('lie/polyfill');\n+\n+function warn() {\n+  var args = Array.prototype.slice.call(arguments, 0);\n+  args.unshift('WARN', 'sms-gateway');\n+  console.error.apply(console, args);\n+}\n+\n+function readBody(stream) {\n+  var body = '';\n+  return new Promise(function(resolve, reject) {\n+    stream.on('data', function(data) {\n+      body += data.toString();\n+    });\n+    stream.on('end', function() {\n+      resolve(body);\n+    });\n+    stream.on('error', reject);\n+  });\n+}\n+\n+function readResBody(res) {\n+  return readBody(res)\n+    .then(function(body) {\n+      if (res.statusCode >= 400) {\n+        throw new Error('Bad status received: ' + res.statusCode + ': ' + body);\n+      }\n+      return body;\n+    });\n+}\n+\n+function saveToDb(gatewayRequest, wtMessage) {\n+  var messageBody = querystring.stringify({\n+    from: wtMessage.from,\n+    message: wtMessage.content,\n+    'medic-gateway_id': wtMessage.id,\n+  });\n+\n+  return new Promise(function(resolve, reject) {\n+    var req = http.request(\n+      {\n+        hostname: 'localhost',\n+        port: 5984,\n+        path: '/medic/_design/medic/_rewrite/add',","path":"controllers/sms-gateway.js","position":56,"original_position":56,"commit_id":"8f22a4c724f04e3736e6893e9d1c98a7dbe970d2","original_commit_id":"8f22a4c724f04e3736e6893e9d1c98a7dbe970d2","user":{"login":"mandric","id":25641,"avatar_url":"https://avatars.githubusercontent.com/u/25641?v=3","gravatar_id":"","url":"https://api.github.com/users/mandric","html_url":"https://github.com/mandric","followers_url":"https://api.github.com/users/mandric/followers","following_url":"https://api.github.com/users/mandric/following{/other_user}","gists_url":"https://api.github.com/users/mandric/gists{/gist_id}","starred_url":"https://api.github.com/users/mandric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mandric/subscriptions","organizations_url":"https://api.github.com/users/mandric/orgs","repos_url":"https://api.github.com/users/mandric/repos","events_url":"https://api.github.com/users/mandric/events{/privacy}","received_events_url":"https://api.github.com/users/mandric/received_events","type":"User","site_admin":false},"body":"The less references we have to direct couch api the better.","created_at":"2016-05-26T12:19:41Z","updated_at":"2016-05-26T12:19:41Z","html_url":"https://github.com/medic/medic-api/pull/69#discussion_r64735451","pull_request_url":"https://api.github.com/repos/medic/medic-api/pulls/69","_links":{"self":{"href":"https://api.github.com/repos/medic/medic-api/pulls/comments/64735451"},"html":{"href":"https://github.com/medic/medic-api/pull/69#discussion_r64735451"},"pull_request":{"href":"https://api.github.com/repos/medic/medic-api/pulls/69"}}},"pull_request":{"url":"https://api.github.com/repos/medic/medic-api/pulls/69","id":71447720,"html_url":"https://github.com/medic/medic-api/pull/69","diff_url":"https://github.com/medic/medic-api/pull/69.diff","patch_url":"https://github.com/medic/medic-api/pull/69.patch","issue_url":"https://api.github.com/repos/medic/medic-api/issues/69","number":69,"state":"open","locked":false,"title":"Add integration with `medic-gateway` for sending and receiving SMS","user":{"login":"alxndrsn","id":191496,"avatar_url":"https://avatars.githubusercontent.com/u/191496?v=3","gravatar_id":"","url":"https://api.github.com/users/alxndrsn","html_url":"https://github.com/alxndrsn","followers_url":"https://api.github.com/users/alxndrsn/followers","following_url":"https://api.github.com/users/alxndrsn/following{/other_user}","gists_url":"https://api.github.com/users/alxndrsn/gists{/gist_id}","starred_url":"https://api.github.com/users/alxndrsn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alxndrsn/subscriptions","organizations_url":"https://api.github.com/users/alxndrsn/orgs","repos_url":"https://api.github.com/users/alxndrsn/repos","events_url":"https://api.github.com/users/alxndrsn/events{/privacy}","received_events_url":"https://api.github.com/users/alxndrsn/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-05-25T19:19:11Z","updated_at":"2016-05-26T12:19:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"13b78fab5083d0d098f1e73e0ffff6d575f1f98b","assignee":{"login":"alxndrsn","id":191496,"avatar_url":"https://avatars.githubusercontent.com/u/191496?v=3","gravatar_id":"","url":"https://api.github.com/users/alxndrsn","html_url":"https://github.com/alxndrsn","followers_url":"https://api.github.com/users/alxndrsn/followers","following_url":"https://api.github.com/users/alxndrsn/following{/other_user}","gists_url":"https://api.github.com/users/alxndrsn/gists{/gist_id}","starred_url":"https://api.github.com/users/alxndrsn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alxndrsn/subscriptions","organizations_url":"https://api.github.com/users/alxndrsn/orgs","repos_url":"https://api.github.com/users/alxndrsn/repos","events_url":"https://api.github.com/users/alxndrsn/events{/privacy}","received_events_url":"https://api.github.com/users/alxndrsn/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/medic/medic-api/pulls/69/commits","review_comments_url":"https://api.github.com/repos/medic/medic-api/pulls/69/comments","review_comment_url":"https://api.github.com/repos/medic/medic-api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/medic/medic-api/issues/69/comments","statuses_url":"https://api.github.com/repos/medic/medic-api/statuses/8f22a4c724f04e3736e6893e9d1c98a7dbe970d2","head":{"label":"medic:medic-gateway-support-pr","ref":"medic-gateway-support-pr","sha":"8f22a4c724f04e3736e6893e9d1c98a7dbe970d2","user":{"login":"medic","id":474424,"avatar_url":"https://avatars.githubusercontent.com/u/474424?v=3","gravatar_id":"","url":"https://api.github.com/users/medic","html_url":"https://github.com/medic","followers_url":"https://api.github.com/users/medic/followers","following_url":"https://api.github.com/users/medic/following{/other_user}","gists_url":"https://api.github.com/users/medic/gists{/gist_id}","starred_url":"https://api.github.com/users/medic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/medic/subscriptions","organizations_url":"https://api.github.com/users/medic/orgs","repos_url":"https://api.github.com/users/medic/repos","events_url":"https://api.github.com/users/medic/events{/privacy}","received_events_url":"https://api.github.com/users/medic/received_events","type":"Organization","site_admin":false},"repo":{"id":18199775,"name":"medic-api","full_name":"medic/medic-api","owner":{"login":"medic","id":474424,"avatar_url":"https://avatars.githubusercontent.com/u/474424?v=3","gravatar_id":"","url":"https://api.github.com/users/medic","html_url":"https://github.com/medic","followers_url":"https://api.github.com/users/medic/followers","following_url":"https://api.github.com/users/medic/following{/other_user}","gists_url":"https://api.github.com/users/medic/gists{/gist_id}","starred_url":"https://api.github.com/users/medic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/medic/subscriptions","organizations_url":"https://api.github.com/users/medic/orgs","repos_url":"https://api.github.com/users/medic/repos","events_url":"https://api.github.com/users/medic/events{/privacy}","received_events_url":"https://api.github.com/users/medic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/medic/medic-api","description":"Node server to support medic-webapp","fork":false,"url":"https://api.github.com/repos/medic/medic-api","forks_url":"https://api.github.com/repos/medic/medic-api/forks","keys_url":"https://api.github.com/repos/medic/medic-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/medic/medic-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/medic/medic-api/teams","hooks_url":"https://api.github.com/repos/medic/medic-api/hooks","issue_events_url":"https://api.github.com/repos/medic/medic-api/issues/events{/number}","events_url":"https://api.github.com/repos/medic/medic-api/events","assignees_url":"https://api.github.com/repos/medic/medic-api/assignees{/user}","branches_url":"https://api.github.com/repos/medic/medic-api/branches{/branch}","tags_url":"https://api.github.com/repos/medic/medic-api/tags","blobs_url":"https://api.github.com/repos/medic/medic-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/medic/medic-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/medic/medic-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/medic/medic-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/medic/medic-api/statuses/{sha}","languages_url":"https://api.github.com/repos/medic/medic-api/languages","stargazers_url":"https://api.github.com/repos/medic/medic-api/stargazers","contributors_url":"https://api.github.com/repos/medic/medic-api/contributors","subscribers_url":"https://api.github.com/repos/medic/medic-api/subscribers","subscription_url":"https://api.github.com/repos/medic/medic-api/subscription","commits_url":"https://api.github.com/repos/medic/medic-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/medic/medic-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/medic/medic-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/medic/medic-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/medic/medic-api/contents/{+path}","compare_url":"https://api.github.com/repos/medic/medic-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/medic/medic-api/merges","archive_url":"https://api.github.com/repos/medic/medic-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/medic/medic-api/downloads","issues_url":"https://api.github.com/repos/medic/medic-api/issues{/number}","pulls_url":"https://api.github.com/repos/medic/medic-api/pulls{/number}","milestones_url":"https://api.github.com/repos/medic/medic-api/milestones{/number}","notifications_url":"https://api.github.com/repos/medic/medic-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/medic/medic-api/labels{/name}","releases_url":"https://api.github.com/repos/medic/medic-api/releases{/id}","deployments_url":"https://api.github.com/repos/medic/medic-api/deployments","created_at":"2014-03-28T03:20:43Z","updated_at":"2016-01-12T16:42:13Z","pushed_at":"2016-05-26T10:33:05Z","git_url":"git://github.com/medic/medic-api.git","ssh_url":"git@github.com:medic/medic-api.git","clone_url":"https://github.com/medic/medic-api.git","svn_url":"https://github.com/medic/medic-api","homepage":"","size":710,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":15,"forks":5,"open_issues":15,"watchers":1,"default_branch":"develop"}},"base":{"label":"medic:master","ref":"master","sha":"48260f8c581dd255aab9aeec3c41649b0e05e4b0","user":{"login":"medic","id":474424,"avatar_url":"https://avatars.githubusercontent.com/u/474424?v=3","gravatar_id":"","url":"https://api.github.com/users/medic","html_url":"https://github.com/medic","followers_url":"https://api.github.com/users/medic/followers","following_url":"https://api.github.com/users/medic/following{/other_user}","gists_url":"https://api.github.com/users/medic/gists{/gist_id}","starred_url":"https://api.github.com/users/medic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/medic/subscriptions","organizations_url":"https://api.github.com/users/medic/orgs","repos_url":"https://api.github.com/users/medic/repos","events_url":"https://api.github.com/users/medic/events{/privacy}","received_events_url":"https://api.github.com/users/medic/received_events","type":"Organization","site_admin":false},"repo":{"id":18199775,"name":"medic-api","full_name":"medic/medic-api","owner":{"login":"medic","id":474424,"avatar_url":"https://avatars.githubusercontent.com/u/474424?v=3","gravatar_id":"","url":"https://api.github.com/users/medic","html_url":"https://github.com/medic","followers_url":"https://api.github.com/users/medic/followers","following_url":"https://api.github.com/users/medic/following{/other_user}","gists_url":"https://api.github.com/users/medic/gists{/gist_id}","starred_url":"https://api.github.com/users/medic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/medic/subscriptions","organizations_url":"https://api.github.com/users/medic/orgs","repos_url":"https://api.github.com/users/medic/repos","events_url":"https://api.github.com/users/medic/events{/privacy}","received_events_url":"https://api.github.com/users/medic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/medic/medic-api","description":"Node server to support medic-webapp","fork":false,"url":"https://api.github.com/repos/medic/medic-api","forks_url":"https://api.github.com/repos/medic/medic-api/forks","keys_url":"https://api.github.com/repos/medic/medic-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/medic/medic-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/medic/medic-api/teams","hooks_url":"https://api.github.com/repos/medic/medic-api/hooks","issue_events_url":"https://api.github.com/repos/medic/medic-api/issues/events{/number}","events_url":"https://api.github.com/repos/medic/medic-api/events","assignees_url":"https://api.github.com/repos/medic/medic-api/assignees{/user}","branches_url":"https://api.github.com/repos/medic/medic-api/branches{/branch}","tags_url":"https://api.github.com/repos/medic/medic-api/tags","blobs_url":"https://api.github.com/repos/medic/medic-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/medic/medic-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/medic/medic-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/medic/medic-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/medic/medic-api/statuses/{sha}","languages_url":"https://api.github.com/repos/medic/medic-api/languages","stargazers_url":"https://api.github.com/repos/medic/medic-api/stargazers","contributors_url":"https://api.github.com/repos/medic/medic-api/contributors","subscribers_url":"https://api.github.com/repos/medic/medic-api/subscribers","subscription_url":"https://api.github.com/repos/medic/medic-api/subscription","commits_url":"https://api.github.com/repos/medic/medic-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/medic/medic-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/medic/medic-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/medic/medic-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/medic/medic-api/contents/{+path}","compare_url":"https://api.github.com/repos/medic/medic-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/medic/medic-api/merges","archive_url":"https://api.github.com/repos/medic/medic-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/medic/medic-api/downloads","issues_url":"https://api.github.com/repos/medic/medic-api/issues{/number}","pulls_url":"https://api.github.com/repos/medic/medic-api/pulls{/number}","milestones_url":"https://api.github.com/repos/medic/medic-api/milestones{/number}","notifications_url":"https://api.github.com/repos/medic/medic-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/medic/medic-api/labels{/name}","releases_url":"https://api.github.com/repos/medic/medic-api/releases{/id}","deployments_url":"https://api.github.com/repos/medic/medic-api/deployments","created_at":"2014-03-28T03:20:43Z","updated_at":"2016-01-12T16:42:13Z","pushed_at":"2016-05-26T10:33:05Z","git_url":"git://github.com/medic/medic-api.git","ssh_url":"git@github.com:medic/medic-api.git","clone_url":"https://github.com/medic/medic-api.git","svn_url":"https://github.com/medic/medic-api","homepage":"","size":710,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":15,"forks":5,"open_issues":15,"watchers":1,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/medic/medic-api/pulls/69"},"html":{"href":"https://github.com/medic/medic-api/pull/69"},"issue":{"href":"https://api.github.com/repos/medic/medic-api/issues/69"},"comments":{"href":"https://api.github.com/repos/medic/medic-api/issues/69/comments"},"review_comments":{"href":"https://api.github.com/repos/medic/medic-api/pulls/69/comments"},"review_comment":{"href":"https://api.github.com/repos/medic/medic-api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/medic/medic-api/pulls/69/commits"},"statuses":{"href":"https://api.github.com/repos/medic/medic-api/statuses/8f22a4c724f04e3736e6893e9d1c98a7dbe970d2"}}}}
{"actor":{"display_login":"mandric"}}