{"action":"created","comment":{"url":"https://api.github.com/repos/CascadeEnergy/consul-client/pulls/comments/60616958","id":60616958,"diff_hunk":"@@ -30,31 +32,52 @@ function consulClient(host) {\n     var requestOptions = prepareRequestOptions(settings);\n     var healthUrl = composeConsulHealthUrl(\n       host,\n-      settings.serviceName,\n-      settings.version\n+      settings.serviceName\n     );\n+    var version = semver.validRange(settings.version);\n \n     // Make a request to Consul host to retrieve service health info\n     // selects a healthy service, if one exists\n     // uses service data found to compose a url of where to reach the service\n     // makes an HTTP request to the service.\n     return got(healthUrl, { json: true })\n-      .then(selectServiceInstance)\n+      .then(function(response) {\n+        return selectServiceInstance(response, version)\n+      })\n       .then(serviceUrlComposer(settings.endpoint))\n       .then(makeRequest);\n \n     /**\n      * Selects a healthy service instance to use if one exists.\n      *\n      * @param {object} response\n+     * @param {String} version\n      * @returns {Service|*}\n      */\n-    function selectServiceInstance(response) {\n+    function selectServiceInstance(response, version) {\n       if (isEmpty(response.body)) {\n         throw new Error('no service instances available');\n       }\n \n-      return sample(response.body).Service;\n+      if (!version) {\n+        throw new Error('invalid version supplied');\n+      }\n+\n+      var matches = [];\n+\n+      response.body.forEach(function(hit) {\n+        if (semver.satisfies(hit.Service.Tags[0] = hit.Service.Tags[0].replace(/-/g, '.'), version)) {\n+          matches.push(hit.Service);\n+        }\n+      });\n+\n+      if(isEmpty(matches)) {\n+        throw new Error('no services matching requested version were found');","path":"index.js","position":58,"original_position":58,"commit_id":"fcac56b3c73c512d77465ca493beca5d0b05c536","original_commit_id":"fcac56b3c73c512d77465ca493beca5d0b05c536","user":{"login":"cberube","id":141515,"avatar_url":"https://avatars.githubusercontent.com/u/141515?v=3","gravatar_id":"","url":"https://api.github.com/users/cberube","html_url":"https://github.com/cberube","followers_url":"https://api.github.com/users/cberube/followers","following_url":"https://api.github.com/users/cberube/following{/other_user}","gists_url":"https://api.github.com/users/cberube/gists{/gist_id}","starred_url":"https://api.github.com/users/cberube/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cberube/subscriptions","organizations_url":"https://api.github.com/users/cberube/orgs","repos_url":"https://api.github.com/users/cberube/repos","events_url":"https://api.github.com/users/cberube/events{/privacy}","received_events_url":"https://api.github.com/users/cberube/received_events","type":"User","site_admin":false},"body":"This is a little bit outside the scope of this ticket, but it drives me a bit crazy: could you go through and capitalize the first letter of the error messages here? (e.g. `No services matching the requested version were found`) They don't need to be perfect, but it would be nice if they felt a little more like ... sentences.","created_at":"2016-04-21T16:54:20Z","updated_at":"2016-04-21T16:54:20Z","html_url":"https://github.com/CascadeEnergy/consul-client/pull/11#discussion_r60616958","pull_request_url":"https://api.github.com/repos/CascadeEnergy/consul-client/pulls/11","_links":{"self":{"href":"https://api.github.com/repos/CascadeEnergy/consul-client/pulls/comments/60616958"},"html":{"href":"https://github.com/CascadeEnergy/consul-client/pull/11#discussion_r60616958"},"pull_request":{"href":"https://api.github.com/repos/CascadeEnergy/consul-client/pulls/11"}}},"pull_request":{"url":"https://api.github.com/repos/CascadeEnergy/consul-client/pulls/11","id":67248002,"html_url":"https://github.com/CascadeEnergy/consul-client/pull/11","diff_url":"https://github.com/CascadeEnergy/consul-client/pull/11.diff","patch_url":"https://github.com/CascadeEnergy/consul-client/pull/11.patch","issue_url":"https://api.github.com/repos/CascadeEnergy/consul-client/issues/11","number":11,"state":"open","locked":false,"title":"Add support for passing in a version string or version range","user":{"login":"nwarlen","id":6005464,"avatar_url":"https://avatars.githubusercontent.com/u/6005464?v=3","gravatar_id":"","url":"https://api.github.com/users/nwarlen","html_url":"https://github.com/nwarlen","followers_url":"https://api.github.com/users/nwarlen/followers","following_url":"https://api.github.com/users/nwarlen/following{/other_user}","gists_url":"https://api.github.com/users/nwarlen/gists{/gist_id}","starred_url":"https://api.github.com/users/nwarlen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nwarlen/subscriptions","organizations_url":"https://api.github.com/users/nwarlen/orgs","repos_url":"https://api.github.com/users/nwarlen/repos","events_url":"https://api.github.com/users/nwarlen/events{/privacy}","received_events_url":"https://api.github.com/users/nwarlen/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-04-20T19:54:46Z","updated_at":"2016-04-21T16:54:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a9e617f5d571d335053f70b88ede93fe8ce1630d","assignee":{"login":"nwarlen","id":6005464,"avatar_url":"https://avatars.githubusercontent.com/u/6005464?v=3","gravatar_id":"","url":"https://api.github.com/users/nwarlen","html_url":"https://github.com/nwarlen","followers_url":"https://api.github.com/users/nwarlen/followers","following_url":"https://api.github.com/users/nwarlen/following{/other_user}","gists_url":"https://api.github.com/users/nwarlen/gists{/gist_id}","starred_url":"https://api.github.com/users/nwarlen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nwarlen/subscriptions","organizations_url":"https://api.github.com/users/nwarlen/orgs","repos_url":"https://api.github.com/users/nwarlen/repos","events_url":"https://api.github.com/users/nwarlen/events{/privacy}","received_events_url":"https://api.github.com/users/nwarlen/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/CascadeEnergy/consul-client/pulls/11/commits","review_comments_url":"https://api.github.com/repos/CascadeEnergy/consul-client/pulls/11/comments","review_comment_url":"https://api.github.com/repos/CascadeEnergy/consul-client/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CascadeEnergy/consul-client/issues/11/comments","statuses_url":"https://api.github.com/repos/CascadeEnergy/consul-client/statuses/fcac56b3c73c512d77465ca493beca5d0b05c536","head":{"label":"nwarlen:semantic-versioning-support","ref":"semantic-versioning-support","sha":"fcac56b3c73c512d77465ca493beca5d0b05c536","user":{"login":"nwarlen","id":6005464,"avatar_url":"https://avatars.githubusercontent.com/u/6005464?v=3","gravatar_id":"","url":"https://api.github.com/users/nwarlen","html_url":"https://github.com/nwarlen","followers_url":"https://api.github.com/users/nwarlen/followers","following_url":"https://api.github.com/users/nwarlen/following{/other_user}","gists_url":"https://api.github.com/users/nwarlen/gists{/gist_id}","starred_url":"https://api.github.com/users/nwarlen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nwarlen/subscriptions","organizations_url":"https://api.github.com/users/nwarlen/orgs","repos_url":"https://api.github.com/users/nwarlen/repos","events_url":"https://api.github.com/users/nwarlen/events{/privacy}","received_events_url":"https://api.github.com/users/nwarlen/received_events","type":"User","site_admin":false},"repo":{"id":39593242,"name":"consul-client","full_name":"nwarlen/consul-client","owner":{"login":"nwarlen","id":6005464,"avatar_url":"https://avatars.githubusercontent.com/u/6005464?v=3","gravatar_id":"","url":"https://api.github.com/users/nwarlen","html_url":"https://github.com/nwarlen","followers_url":"https://api.github.com/users/nwarlen/followers","following_url":"https://api.github.com/users/nwarlen/following{/other_user}","gists_url":"https://api.github.com/users/nwarlen/gists{/gist_id}","starred_url":"https://api.github.com/users/nwarlen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nwarlen/subscriptions","organizations_url":"https://api.github.com/users/nwarlen/orgs","repos_url":"https://api.github.com/users/nwarlen/repos","events_url":"https://api.github.com/users/nwarlen/events{/privacy}","received_events_url":"https://api.github.com/users/nwarlen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nwarlen/consul-client","description":"Client code for service discovery and invocation","fork":true,"url":"https://api.github.com/repos/nwarlen/consul-client","forks_url":"https://api.github.com/repos/nwarlen/consul-client/forks","keys_url":"https://api.github.com/repos/nwarlen/consul-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nwarlen/consul-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nwarlen/consul-client/teams","hooks_url":"https://api.github.com/repos/nwarlen/consul-client/hooks","issue_events_url":"https://api.github.com/repos/nwarlen/consul-client/issues/events{/number}","events_url":"https://api.github.com/repos/nwarlen/consul-client/events","assignees_url":"https://api.github.com/repos/nwarlen/consul-client/assignees{/user}","branches_url":"https://api.github.com/repos/nwarlen/consul-client/branches{/branch}","tags_url":"https://api.github.com/repos/nwarlen/consul-client/tags","blobs_url":"https://api.github.com/repos/nwarlen/consul-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nwarlen/consul-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nwarlen/consul-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/nwarlen/consul-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nwarlen/consul-client/statuses/{sha}","languages_url":"https://api.github.com/repos/nwarlen/consul-client/languages","stargazers_url":"https://api.github.com/repos/nwarlen/consul-client/stargazers","contributors_url":"https://api.github.com/repos/nwarlen/consul-client/contributors","subscribers_url":"https://api.github.com/repos/nwarlen/consul-client/subscribers","subscription_url":"https://api.github.com/repos/nwarlen/consul-client/subscription","commits_url":"https://api.github.com/repos/nwarlen/consul-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/nwarlen/consul-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/nwarlen/consul-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/nwarlen/consul-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/nwarlen/consul-client/contents/{+path}","compare_url":"https://api.github.com/repos/nwarlen/consul-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nwarlen/consul-client/merges","archive_url":"https://api.github.com/repos/nwarlen/consul-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nwarlen/consul-client/downloads","issues_url":"https://api.github.com/repos/nwarlen/consul-client/issues{/number}","pulls_url":"https://api.github.com/repos/nwarlen/consul-client/pulls{/number}","milestones_url":"https://api.github.com/repos/nwarlen/consul-client/milestones{/number}","notifications_url":"https://api.github.com/repos/nwarlen/consul-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nwarlen/consul-client/labels{/name}","releases_url":"https://api.github.com/repos/nwarlen/consul-client/releases{/id}","deployments_url":"https://api.github.com/repos/nwarlen/consul-client/deployments","created_at":"2015-07-23T21:13:35Z","updated_at":"2015-07-23T21:13:35Z","pushed_at":"2016-04-20T20:16:32Z","git_url":"git://github.com/nwarlen/consul-client.git","ssh_url":"git@github.com:nwarlen/consul-client.git","clone_url":"https://github.com/nwarlen/consul-client.git","svn_url":"https://github.com/nwarlen/consul-client","homepage":null,"size":37,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"CascadeEnergy:master","ref":"master","sha":"0c9fb7b967086bdee84fbffd9fbc65e53539f987","user":{"login":"CascadeEnergy","id":3847760,"avatar_url":"https://avatars.githubusercontent.com/u/3847760?v=3","gravatar_id":"","url":"https://api.github.com/users/CascadeEnergy","html_url":"https://github.com/CascadeEnergy","followers_url":"https://api.github.com/users/CascadeEnergy/followers","following_url":"https://api.github.com/users/CascadeEnergy/following{/other_user}","gists_url":"https://api.github.com/users/CascadeEnergy/gists{/gist_id}","starred_url":"https://api.github.com/users/CascadeEnergy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CascadeEnergy/subscriptions","organizations_url":"https://api.github.com/users/CascadeEnergy/orgs","repos_url":"https://api.github.com/users/CascadeEnergy/repos","events_url":"https://api.github.com/users/CascadeEnergy/events{/privacy}","received_events_url":"https://api.github.com/users/CascadeEnergy/received_events","type":"Organization","site_admin":false},"repo":{"id":36096222,"name":"consul-client","full_name":"CascadeEnergy/consul-client","owner":{"login":"CascadeEnergy","id":3847760,"avatar_url":"https://avatars.githubusercontent.com/u/3847760?v=3","gravatar_id":"","url":"https://api.github.com/users/CascadeEnergy","html_url":"https://github.com/CascadeEnergy","followers_url":"https://api.github.com/users/CascadeEnergy/followers","following_url":"https://api.github.com/users/CascadeEnergy/following{/other_user}","gists_url":"https://api.github.com/users/CascadeEnergy/gists{/gist_id}","starred_url":"https://api.github.com/users/CascadeEnergy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CascadeEnergy/subscriptions","organizations_url":"https://api.github.com/users/CascadeEnergy/orgs","repos_url":"https://api.github.com/users/CascadeEnergy/repos","events_url":"https://api.github.com/users/CascadeEnergy/events{/privacy}","received_events_url":"https://api.github.com/users/CascadeEnergy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CascadeEnergy/consul-client","description":"Client code for service discovery and invocation","fork":false,"url":"https://api.github.com/repos/CascadeEnergy/consul-client","forks_url":"https://api.github.com/repos/CascadeEnergy/consul-client/forks","keys_url":"https://api.github.com/repos/CascadeEnergy/consul-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CascadeEnergy/consul-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CascadeEnergy/consul-client/teams","hooks_url":"https://api.github.com/repos/CascadeEnergy/consul-client/hooks","issue_events_url":"https://api.github.com/repos/CascadeEnergy/consul-client/issues/events{/number}","events_url":"https://api.github.com/repos/CascadeEnergy/consul-client/events","assignees_url":"https://api.github.com/repos/CascadeEnergy/consul-client/assignees{/user}","branches_url":"https://api.github.com/repos/CascadeEnergy/consul-client/branches{/branch}","tags_url":"https://api.github.com/repos/CascadeEnergy/consul-client/tags","blobs_url":"https://api.github.com/repos/CascadeEnergy/consul-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CascadeEnergy/consul-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CascadeEnergy/consul-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/CascadeEnergy/consul-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CascadeEnergy/consul-client/statuses/{sha}","languages_url":"https://api.github.com/repos/CascadeEnergy/consul-client/languages","stargazers_url":"https://api.github.com/repos/CascadeEnergy/consul-client/stargazers","contributors_url":"https://api.github.com/repos/CascadeEnergy/consul-client/contributors","subscribers_url":"https://api.github.com/repos/CascadeEnergy/consul-client/subscribers","subscription_url":"https://api.github.com/repos/CascadeEnergy/consul-client/subscription","commits_url":"https://api.github.com/repos/CascadeEnergy/consul-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/CascadeEnergy/consul-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/CascadeEnergy/consul-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/CascadeEnergy/consul-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/CascadeEnergy/consul-client/contents/{+path}","compare_url":"https://api.github.com/repos/CascadeEnergy/consul-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CascadeEnergy/consul-client/merges","archive_url":"https://api.github.com/repos/CascadeEnergy/consul-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CascadeEnergy/consul-client/downloads","issues_url":"https://api.github.com/repos/CascadeEnergy/consul-client/issues{/number}","pulls_url":"https://api.github.com/repos/CascadeEnergy/consul-client/pulls{/number}","milestones_url":"https://api.github.com/repos/CascadeEnergy/consul-client/milestones{/number}","notifications_url":"https://api.github.com/repos/CascadeEnergy/consul-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CascadeEnergy/consul-client/labels{/name}","releases_url":"https://api.github.com/repos/CascadeEnergy/consul-client/releases{/id}","deployments_url":"https://api.github.com/repos/CascadeEnergy/consul-client/deployments","created_at":"2015-05-22T21:33:03Z","updated_at":"2015-07-01T19:49:51Z","pushed_at":"2016-04-20T20:16:32Z","git_url":"git://github.com/CascadeEnergy/consul-client.git","ssh_url":"git@github.com:CascadeEnergy/consul-client.git","clone_url":"https://github.com/CascadeEnergy/consul-client.git","svn_url":"https://github.com/CascadeEnergy/consul-client","homepage":null,"size":205,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":1,"forks":6,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CascadeEnergy/consul-client/pulls/11"},"html":{"href":"https://github.com/CascadeEnergy/consul-client/pull/11"},"issue":{"href":"https://api.github.com/repos/CascadeEnergy/consul-client/issues/11"},"comments":{"href":"https://api.github.com/repos/CascadeEnergy/consul-client/issues/11/comments"},"review_comments":{"href":"https://api.github.com/repos/CascadeEnergy/consul-client/pulls/11/comments"},"review_comment":{"href":"https://api.github.com/repos/CascadeEnergy/consul-client/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CascadeEnergy/consul-client/pulls/11/commits"},"statuses":{"href":"https://api.github.com/repos/CascadeEnergy/consul-client/statuses/fcac56b3c73c512d77465ca493beca5d0b05c536"}}}}