{"action":"created","comment":{"url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/pulls/comments/60490206","id":60490206,"diff_hunk":"@@ -15,18 +15,152 @@ var brMessages = require('bedrock-messages');\n var request = require('request');\n var scheduler = require('bedrock-jobs');\n var uuid = require('node-uuid').v4;\n+require('bedrock-express');\n \n require('./config');\n \n+var api = {};\n+module.exports = api;\n+\n+var logger = bedrock.loggers.get('app');\n+\n // configure for tests\n bedrock.events.on('bedrock.test.configure', function() {\n   require('./test.config');\n });\n \n-var api = {};\n-module.exports = api;\n+bedrock.events.on('bedrock-express.configure.routes', function(app) {\n+  // TODO: Add authentication\n+  // The restart-job endpoint is operating on the premise that there can only\n+  // be one client polling on an endpoint\n+  /**\n+   * Restarts message clients on the specified endpoints with\n+   * the specified interval. If no endpoints specified, all clients will\n+   * be restarted.\n+   *\n+   * @param interval the number of minutes to wait between polling\n+   * the endpoint (e.g. 1, 5, or 10)\n+   * @param endpoints array of endpoints for clients to be restarted\n+   */\n+  app.post(config['messages-client']['settings-endpoint'],\n+    function(req, res, next) {\n+      var interval = req.body.interval;\n+      var endpoints = req.body.endpoints;\n+      var clients =\n+        bedrock.util.clone(config['messages-client'].clients);\n \n-var logger = bedrock.loggers.get('app');\n+      if(!!endpoints) {\n+        clients = clients.filter(function(client) {\n+          return endpoints.indexOf(client.endpoint) >= 0;\n+        });\n+      }\n+\n+      async.each(clients, function(client, callback) {\n+        api.start(client.endpoint, interval, callback);\n+      },\n+      function(err) {\n+        if(err) {\n+          return next(new BedrockError(\n+            'Failed to start message client.',\n+            'MessageClientFailure',\n+            {interval: interval, httpStatusCode: 500, 'public': true}));\n+        }\n+        res.status(200);\n+        res.send();\n+      });\n+    });\n+});\n+\n+bedrock.events.on('bedrock-mongodb.ready', function(callback) {\n+  if(!config['messages-client'].enable) {\n+    return callback();\n+  }\n+  var interval = 1;\n+  config['messages-client'].clients\n+    .forEach(function(clientOptions) {\n+      var jobId = createJobId(clientOptions.endpoint);\n+      var endpoint = clientOptions.endpoint;\n+      var privateKeyPem = clientOptions.privateKeyPem;\n+      var publicKeyId = clientOptions.publicKeyId;\n+      var strictSSL = !('strictSSL' in clientOptions) ?\n+        true : !!clientOptions.strictSSL;\n+      var fn = function(job, callback) {\n+        var options = {\n+          job: job,\n+          endpoint: endpoint,\n+          privateKeyPem: privateKeyPem,\n+          publicKeyId: publicKeyId,\n+          strictSSL: strictSSL\n+        };\n+        pollServer(options, function(err, results) {\n+          if(err) {\n+            return callback(err);\n+          }\n+          callback(null);","path":"lib/client.js","position":88,"original_position":88,"commit_id":"0ff3ef7a89f4e7be99d682a96f60f66cb88ad419","original_commit_id":"0ff3ef7a89f4e7be99d682a96f60f66cb88ad419","user":{"login":"davidlehn","id":109587,"avatar_url":"https://avatars.githubusercontent.com/u/109587?v=3","gravatar_id":"","url":"https://api.github.com/users/davidlehn","html_url":"https://github.com/davidlehn","followers_url":"https://api.github.com/users/davidlehn/followers","following_url":"https://api.github.com/users/davidlehn/following{/other_user}","gists_url":"https://api.github.com/users/davidlehn/gists{/gist_id}","starred_url":"https://api.github.com/users/davidlehn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidlehn/subscriptions","organizations_url":"https://api.github.com/users/davidlehn/orgs","repos_url":"https://api.github.com/users/davidlehn/repos","events_url":"https://api.github.com/users/davidlehn/events{/privacy}","received_events_url":"https://api.github.com/users/davidlehn/received_events","type":"User","site_admin":false},"body":"Don't need to specify null here.","created_at":"2016-04-20T21:22:19Z","updated_at":"2016-04-20T21:22:19Z","html_url":"https://github.com/digitalbazaar/bedrock-messages-client/pull/1#discussion_r60490206","pull_request_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/pulls/comments/60490206"},"html":{"href":"https://github.com/digitalbazaar/bedrock-messages-client/pull/1#discussion_r60490206"},"pull_request":{"href":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/pulls/1","id":66195176,"html_url":"https://github.com/digitalbazaar/bedrock-messages-client/pull/1","diff_url":"https://github.com/digitalbazaar/bedrock-messages-client/pull/1.diff","patch_url":"https://github.com/digitalbazaar/bedrock-messages-client/pull/1.patch","issue_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/issues/1","number":1,"state":"open","locked":false,"title":"New message client api","user":{"login":"OmarMalik","id":6423023,"avatar_url":"https://avatars.githubusercontent.com/u/6423023?v=3","gravatar_id":"","url":"https://api.github.com/users/OmarMalik","html_url":"https://github.com/OmarMalik","followers_url":"https://api.github.com/users/OmarMalik/followers","following_url":"https://api.github.com/users/OmarMalik/following{/other_user}","gists_url":"https://api.github.com/users/OmarMalik/gists{/gist_id}","starred_url":"https://api.github.com/users/OmarMalik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OmarMalik/subscriptions","organizations_url":"https://api.github.com/users/OmarMalik/orgs","repos_url":"https://api.github.com/users/OmarMalik/repos","events_url":"https://api.github.com/users/OmarMalik/events{/privacy}","received_events_url":"https://api.github.com/users/OmarMalik/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-04-12T17:20:17Z","updated_at":"2016-04-20T21:22:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"eaa5933824d30e8b0b5f3a2da8b6e2bb6a421b15","assignee":{"login":"dlongley","id":168137,"avatar_url":"https://avatars.githubusercontent.com/u/168137?v=3","gravatar_id":"","url":"https://api.github.com/users/dlongley","html_url":"https://github.com/dlongley","followers_url":"https://api.github.com/users/dlongley/followers","following_url":"https://api.github.com/users/dlongley/following{/other_user}","gists_url":"https://api.github.com/users/dlongley/gists{/gist_id}","starred_url":"https://api.github.com/users/dlongley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dlongley/subscriptions","organizations_url":"https://api.github.com/users/dlongley/orgs","repos_url":"https://api.github.com/users/dlongley/repos","events_url":"https://api.github.com/users/dlongley/events{/privacy}","received_events_url":"https://api.github.com/users/dlongley/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/pulls/1/commits","review_comments_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/pulls/1/comments","review_comment_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/pulls/comments{/number}","comments_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/issues/1/comments","statuses_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/statuses/0ff3ef7a89f4e7be99d682a96f60f66cb88ad419","head":{"label":"digitalbazaar:newMessageClientAPI","ref":"newMessageClientAPI","sha":"0ff3ef7a89f4e7be99d682a96f60f66cb88ad419","user":{"login":"digitalbazaar","id":167436,"avatar_url":"https://avatars.githubusercontent.com/u/167436?v=3","gravatar_id":"","url":"https://api.github.com/users/digitalbazaar","html_url":"https://github.com/digitalbazaar","followers_url":"https://api.github.com/users/digitalbazaar/followers","following_url":"https://api.github.com/users/digitalbazaar/following{/other_user}","gists_url":"https://api.github.com/users/digitalbazaar/gists{/gist_id}","starred_url":"https://api.github.com/users/digitalbazaar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/digitalbazaar/subscriptions","organizations_url":"https://api.github.com/users/digitalbazaar/orgs","repos_url":"https://api.github.com/users/digitalbazaar/repos","events_url":"https://api.github.com/users/digitalbazaar/events{/privacy}","received_events_url":"https://api.github.com/users/digitalbazaar/received_events","type":"Organization","site_admin":false},"repo":{"id":46565566,"name":"bedrock-messages-client","full_name":"digitalbazaar/bedrock-messages-client","owner":{"login":"digitalbazaar","id":167436,"avatar_url":"https://avatars.githubusercontent.com/u/167436?v=3","gravatar_id":"","url":"https://api.github.com/users/digitalbazaar","html_url":"https://github.com/digitalbazaar","followers_url":"https://api.github.com/users/digitalbazaar/followers","following_url":"https://api.github.com/users/digitalbazaar/following{/other_user}","gists_url":"https://api.github.com/users/digitalbazaar/gists{/gist_id}","starred_url":"https://api.github.com/users/digitalbazaar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/digitalbazaar/subscriptions","organizations_url":"https://api.github.com/users/digitalbazaar/orgs","repos_url":"https://api.github.com/users/digitalbazaar/repos","events_url":"https://api.github.com/users/digitalbazaar/events{/privacy}","received_events_url":"https://api.github.com/users/digitalbazaar/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/digitalbazaar/bedrock-messages-client","description":"A client for accessing bedrock-messages","fork":false,"url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client","forks_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/forks","keys_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/teams","hooks_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/hooks","issue_events_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/issues/events{/number}","events_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/events","assignees_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/assignees{/user}","branches_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/branches{/branch}","tags_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/tags","blobs_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/statuses/{sha}","languages_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/languages","stargazers_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/stargazers","contributors_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/contributors","subscribers_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/subscribers","subscription_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/subscription","commits_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/contents/{+path}","compare_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/merges","archive_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/downloads","issues_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/issues{/number}","pulls_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/pulls{/number}","milestones_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/milestones{/number}","notifications_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/labels{/name}","releases_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/releases{/id}","deployments_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/deployments","created_at":"2015-11-20T14:09:29Z","updated_at":"2016-01-12T19:44:35Z","pushed_at":"2016-04-20T20:00:29Z","git_url":"git://github.com/digitalbazaar/bedrock-messages-client.git","ssh_url":"git@github.com:digitalbazaar/bedrock-messages-client.git","clone_url":"https://github.com/digitalbazaar/bedrock-messages-client.git","svn_url":"https://github.com/digitalbazaar/bedrock-messages-client","homepage":null,"size":25,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"digitalbazaar:master","ref":"master","sha":"627de10b170340c07392f8d4ced98d81eaf39158","user":{"login":"digitalbazaar","id":167436,"avatar_url":"https://avatars.githubusercontent.com/u/167436?v=3","gravatar_id":"","url":"https://api.github.com/users/digitalbazaar","html_url":"https://github.com/digitalbazaar","followers_url":"https://api.github.com/users/digitalbazaar/followers","following_url":"https://api.github.com/users/digitalbazaar/following{/other_user}","gists_url":"https://api.github.com/users/digitalbazaar/gists{/gist_id}","starred_url":"https://api.github.com/users/digitalbazaar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/digitalbazaar/subscriptions","organizations_url":"https://api.github.com/users/digitalbazaar/orgs","repos_url":"https://api.github.com/users/digitalbazaar/repos","events_url":"https://api.github.com/users/digitalbazaar/events{/privacy}","received_events_url":"https://api.github.com/users/digitalbazaar/received_events","type":"Organization","site_admin":false},"repo":{"id":46565566,"name":"bedrock-messages-client","full_name":"digitalbazaar/bedrock-messages-client","owner":{"login":"digitalbazaar","id":167436,"avatar_url":"https://avatars.githubusercontent.com/u/167436?v=3","gravatar_id":"","url":"https://api.github.com/users/digitalbazaar","html_url":"https://github.com/digitalbazaar","followers_url":"https://api.github.com/users/digitalbazaar/followers","following_url":"https://api.github.com/users/digitalbazaar/following{/other_user}","gists_url":"https://api.github.com/users/digitalbazaar/gists{/gist_id}","starred_url":"https://api.github.com/users/digitalbazaar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/digitalbazaar/subscriptions","organizations_url":"https://api.github.com/users/digitalbazaar/orgs","repos_url":"https://api.github.com/users/digitalbazaar/repos","events_url":"https://api.github.com/users/digitalbazaar/events{/privacy}","received_events_url":"https://api.github.com/users/digitalbazaar/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/digitalbazaar/bedrock-messages-client","description":"A client for accessing bedrock-messages","fork":false,"url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client","forks_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/forks","keys_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/teams","hooks_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/hooks","issue_events_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/issues/events{/number}","events_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/events","assignees_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/assignees{/user}","branches_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/branches{/branch}","tags_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/tags","blobs_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/statuses/{sha}","languages_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/languages","stargazers_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/stargazers","contributors_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/contributors","subscribers_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/subscribers","subscription_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/subscription","commits_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/contents/{+path}","compare_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/merges","archive_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/downloads","issues_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/issues{/number}","pulls_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/pulls{/number}","milestones_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/milestones{/number}","notifications_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/labels{/name}","releases_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/releases{/id}","deployments_url":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/deployments","created_at":"2015-11-20T14:09:29Z","updated_at":"2016-01-12T19:44:35Z","pushed_at":"2016-04-20T20:00:29Z","git_url":"git://github.com/digitalbazaar/bedrock-messages-client.git","ssh_url":"git@github.com:digitalbazaar/bedrock-messages-client.git","clone_url":"https://github.com/digitalbazaar/bedrock-messages-client.git","svn_url":"https://github.com/digitalbazaar/bedrock-messages-client","homepage":null,"size":25,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"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/digitalbazaar/bedrock-messages-client/pulls/1"},"html":{"href":"https://github.com/digitalbazaar/bedrock-messages-client/pull/1"},"issue":{"href":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/issues/1"},"comments":{"href":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/digitalbazaar/bedrock-messages-client/statuses/0ff3ef7a89f4e7be99d682a96f60f66cb88ad419"}}}}