{"action":"created","comment":{"url":"https://api.github.com/repos/socrata/cetera-ruby/pulls/comments/72167171","id":72167171,"diff_hunk":"@@ -0,0 +1,43 @@\n+require 'addressable/uri'\n+require 'httparty'\n+require 'json'\n+\n+module Cetera\n+  class Client\n+    class << self\n+\n+      # Creates a new Cetera::Client\n+      #\n+      # @param host [String]\n+      # @param port [String]\n+      def new(host, port)\n+        client_class = Class.new(AbstractClient) do |klass|\n+          cetera_uri = \"http://#{host}:#{port}\"\n+          uri = Addressable::URI.parse(cetera_uri).to_s\n+          klass.base_uri(uri)\n+        end\n+        client_class.new\n+      end\n+    end\n+\n+    class AbstractClient\n+      include HTTParty\n+\n+      def get(path, headers = {}, opts = {})\n+        response = self.class.get(path, query: stringify_keys(opts), headers: stringify_keys(headers))\n+        handle_error(path, opts, response) unless response.code == 200\n+        JSON.parse(response.body)\n+      end\n+\n+      private\n+\n+      def stringify_keys(hash)\n+        Hash[hash.collect{ |k,v| [k.to_s, v] }]\n+      end\n+\n+      def handle_error(path, options, response)\n+        fail(\"Invalid response from Cetera calling #{path} with #{options}\\nResponse code: #{response.code}\\n#{response.body}\")","path":"lib/cetera/client.rb","position":39,"original_position":39,"commit_id":"d119313237e88e5df7f76663854e0d793c3a1acb","original_commit_id":"d119313237e88e5df7f76663854e0d793c3a1acb","user":{"login":"smooshy","id":142420,"avatar_url":"https://avatars.githubusercontent.com/u/142420?v=3","gravatar_id":"","url":"https://api.github.com/users/smooshy","html_url":"https://github.com/smooshy","followers_url":"https://api.github.com/users/smooshy/followers","following_url":"https://api.github.com/users/smooshy/following{/other_user}","gists_url":"https://api.github.com/users/smooshy/gists{/gist_id}","starred_url":"https://api.github.com/users/smooshy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smooshy/subscriptions","organizations_url":"https://api.github.com/users/smooshy/orgs","repos_url":"https://api.github.com/users/smooshy/repos","events_url":"https://api.github.com/users/smooshy/events{/privacy}","received_events_url":"https://api.github.com/users/smooshy/received_events","type":"User","site_admin":false},"body":"I would probably use `raise` instead of `fail` here. Also, the method name `handle_error` is a bit misleading since we're not handling it so much as actually raising it.","created_at":"2016-07-25T23:59:40Z","updated_at":"2016-07-25T23:59:40Z","html_url":"https://github.com/socrata/cetera-ruby/pull/1#discussion_r72167171","pull_request_url":"https://api.github.com/repos/socrata/cetera-ruby/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/socrata/cetera-ruby/pulls/comments/72167171"},"html":{"href":"https://github.com/socrata/cetera-ruby/pull/1#discussion_r72167171"},"pull_request":{"href":"https://api.github.com/repos/socrata/cetera-ruby/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/socrata/cetera-ruby/pulls/1","id":78753877,"html_url":"https://github.com/socrata/cetera-ruby/pull/1","diff_url":"https://github.com/socrata/cetera-ruby/pull/1.diff","patch_url":"https://github.com/socrata/cetera-ruby/pull/1.patch","issue_url":"https://api.github.com/repos/socrata/cetera-ruby/issues/1","number":1,"state":"open","locked":false,"title":"EN-8243: Add Cetera client and UserSearch client.","user":{"login":"aynleslie","id":6155686,"avatar_url":"https://avatars.githubusercontent.com/u/6155686?v=3","gravatar_id":"","url":"https://api.github.com/users/aynleslie","html_url":"https://github.com/aynleslie","followers_url":"https://api.github.com/users/aynleslie/followers","following_url":"https://api.github.com/users/aynleslie/following{/other_user}","gists_url":"https://api.github.com/users/aynleslie/gists{/gist_id}","starred_url":"https://api.github.com/users/aynleslie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aynleslie/subscriptions","organizations_url":"https://api.github.com/users/aynleslie/orgs","repos_url":"https://api.github.com/users/aynleslie/repos","events_url":"https://api.github.com/users/aynleslie/events{/privacy}","received_events_url":"https://api.github.com/users/aynleslie/received_events","type":"User","site_admin":false},"body":"#### What it do?\r\n\r\n* Adds a `Cetera::Client` that holds connection info and performs gets and error handling against the cetera service\r\n* Adds a `Cetera::UserSearch` with convenience methods for finding users by id or email or searching for users by query or matching role or domain.\r\n* Adds all the other things that a ruby repo needs.  ya know, a Gemfile, Rakefile, tests, etc, etc.\r\n\r\n#### What it doesn't do?\r\n\r\nI wanted a reasonably small and focused first commit, so I did not add the clients for ViewSearch or AssetSelection.  But we should definitely add them once this commit gets through.\r\n\r\n#### How was it tested?\r\n\r\n100% code coverage according to simplecov.  So woot woot. \r\n\r\nAnd I played around with irb and my locally running cetera (pointed at prod):\r\n\r\n```ruby\r\nrequire 'cetera'\r\nclient = Cetera::Client.new('localhost', '5704')\r\nx_socrata_host = 'data.ny.gov'\r\ncookie = '_core_session_id=REDACTED'\r\nuser_search_client = Cetera::UserSearch.new(client, x_socrata_host, cookie)\r\nuser_search_client.find_user_by_email('adam.ruder@nyserda.ny.gov')\r\nuser_search_client.find_user_by_role('publisher', 'data.ny.gov', limit:1, offset:1)\r\n```\r\n\r\n#### Notes/ Questions\r\n\r\nThis is the first ruby repo I've ever kicked off on my own, so don't feel bad at all about leaving tons & tons of feedback, however critical it may be. \r\n\r\nShould this repo be public?  It is now and so is the [cetera repo](https://github.com/socrata/cetera). \r\n\r\nShould I have included deploy info in the README?  a la the [core-auth repo](https://github.com/socrata/core-auth-ruby).  Probably not unless we make this repo private.\r\n\r\n","created_at":"2016-07-25T21:17:24Z","updated_at":"2016-07-25T23:59:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d7fded30276b0b2f0776b03e10136c110e7e8e11","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/socrata/cetera-ruby/pulls/1/commits","review_comments_url":"https://api.github.com/repos/socrata/cetera-ruby/pulls/1/comments","review_comment_url":"https://api.github.com/repos/socrata/cetera-ruby/pulls/comments{/number}","comments_url":"https://api.github.com/repos/socrata/cetera-ruby/issues/1/comments","statuses_url":"https://api.github.com/repos/socrata/cetera-ruby/statuses/d119313237e88e5df7f76663854e0d793c3a1acb","head":{"label":"socrata:ayn/EN-8243/initial-cetera-gem","ref":"ayn/EN-8243/initial-cetera-gem","sha":"d119313237e88e5df7f76663854e0d793c3a1acb","user":{"login":"socrata","id":57695,"avatar_url":"https://avatars.githubusercontent.com/u/57695?v=3","gravatar_id":"","url":"https://api.github.com/users/socrata","html_url":"https://github.com/socrata","followers_url":"https://api.github.com/users/socrata/followers","following_url":"https://api.github.com/users/socrata/following{/other_user}","gists_url":"https://api.github.com/users/socrata/gists{/gist_id}","starred_url":"https://api.github.com/users/socrata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/socrata/subscriptions","organizations_url":"https://api.github.com/users/socrata/orgs","repos_url":"https://api.github.com/users/socrata/repos","events_url":"https://api.github.com/users/socrata/events{/privacy}","received_events_url":"https://api.github.com/users/socrata/received_events","type":"Organization","site_admin":false},"repo":{"id":64156462,"name":"cetera-ruby","full_name":"socrata/cetera-ruby","owner":{"login":"socrata","id":57695,"avatar_url":"https://avatars.githubusercontent.com/u/57695?v=3","gravatar_id":"","url":"https://api.github.com/users/socrata","html_url":"https://github.com/socrata","followers_url":"https://api.github.com/users/socrata/followers","following_url":"https://api.github.com/users/socrata/following{/other_user}","gists_url":"https://api.github.com/users/socrata/gists{/gist_id}","starred_url":"https://api.github.com/users/socrata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/socrata/subscriptions","organizations_url":"https://api.github.com/users/socrata/orgs","repos_url":"https://api.github.com/users/socrata/repos","events_url":"https://api.github.com/users/socrata/events{/privacy}","received_events_url":"https://api.github.com/users/socrata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/socrata/cetera-ruby","description":"Ruby wrapper around Cetera search service.","fork":false,"url":"https://api.github.com/repos/socrata/cetera-ruby","forks_url":"https://api.github.com/repos/socrata/cetera-ruby/forks","keys_url":"https://api.github.com/repos/socrata/cetera-ruby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/socrata/cetera-ruby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/socrata/cetera-ruby/teams","hooks_url":"https://api.github.com/repos/socrata/cetera-ruby/hooks","issue_events_url":"https://api.github.com/repos/socrata/cetera-ruby/issues/events{/number}","events_url":"https://api.github.com/repos/socrata/cetera-ruby/events","assignees_url":"https://api.github.com/repos/socrata/cetera-ruby/assignees{/user}","branches_url":"https://api.github.com/repos/socrata/cetera-ruby/branches{/branch}","tags_url":"https://api.github.com/repos/socrata/cetera-ruby/tags","blobs_url":"https://api.github.com/repos/socrata/cetera-ruby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/socrata/cetera-ruby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/socrata/cetera-ruby/git/refs{/sha}","trees_url":"https://api.github.com/repos/socrata/cetera-ruby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/socrata/cetera-ruby/statuses/{sha}","languages_url":"https://api.github.com/repos/socrata/cetera-ruby/languages","stargazers_url":"https://api.github.com/repos/socrata/cetera-ruby/stargazers","contributors_url":"https://api.github.com/repos/socrata/cetera-ruby/contributors","subscribers_url":"https://api.github.com/repos/socrata/cetera-ruby/subscribers","subscription_url":"https://api.github.com/repos/socrata/cetera-ruby/subscription","commits_url":"https://api.github.com/repos/socrata/cetera-ruby/commits{/sha}","git_commits_url":"https://api.github.com/repos/socrata/cetera-ruby/git/commits{/sha}","comments_url":"https://api.github.com/repos/socrata/cetera-ruby/comments{/number}","issue_comment_url":"https://api.github.com/repos/socrata/cetera-ruby/issues/comments{/number}","contents_url":"https://api.github.com/repos/socrata/cetera-ruby/contents/{+path}","compare_url":"https://api.github.com/repos/socrata/cetera-ruby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/socrata/cetera-ruby/merges","archive_url":"https://api.github.com/repos/socrata/cetera-ruby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/socrata/cetera-ruby/downloads","issues_url":"https://api.github.com/repos/socrata/cetera-ruby/issues{/number}","pulls_url":"https://api.github.com/repos/socrata/cetera-ruby/pulls{/number}","milestones_url":"https://api.github.com/repos/socrata/cetera-ruby/milestones{/number}","notifications_url":"https://api.github.com/repos/socrata/cetera-ruby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/socrata/cetera-ruby/labels{/name}","releases_url":"https://api.github.com/repos/socrata/cetera-ruby/releases{/id}","deployments_url":"https://api.github.com/repos/socrata/cetera-ruby/deployments","created_at":"2016-07-25T18:00:33Z","updated_at":"2016-07-25T18:00:33Z","pushed_at":"2016-07-25T21:17:24Z","git_url":"git://github.com/socrata/cetera-ruby.git","ssh_url":"git@github.com:socrata/cetera-ruby.git","clone_url":"https://github.com/socrata/cetera-ruby.git","svn_url":"https://github.com/socrata/cetera-ruby","homepage":null,"size":7,"stargazers_count":0,"watchers_count":0,"language":null,"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":"socrata:master","ref":"master","sha":"b1a9b79d9880598bb25c284a37b335d56b02a141","user":{"login":"socrata","id":57695,"avatar_url":"https://avatars.githubusercontent.com/u/57695?v=3","gravatar_id":"","url":"https://api.github.com/users/socrata","html_url":"https://github.com/socrata","followers_url":"https://api.github.com/users/socrata/followers","following_url":"https://api.github.com/users/socrata/following{/other_user}","gists_url":"https://api.github.com/users/socrata/gists{/gist_id}","starred_url":"https://api.github.com/users/socrata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/socrata/subscriptions","organizations_url":"https://api.github.com/users/socrata/orgs","repos_url":"https://api.github.com/users/socrata/repos","events_url":"https://api.github.com/users/socrata/events{/privacy}","received_events_url":"https://api.github.com/users/socrata/received_events","type":"Organization","site_admin":false},"repo":{"id":64156462,"name":"cetera-ruby","full_name":"socrata/cetera-ruby","owner":{"login":"socrata","id":57695,"avatar_url":"https://avatars.githubusercontent.com/u/57695?v=3","gravatar_id":"","url":"https://api.github.com/users/socrata","html_url":"https://github.com/socrata","followers_url":"https://api.github.com/users/socrata/followers","following_url":"https://api.github.com/users/socrata/following{/other_user}","gists_url":"https://api.github.com/users/socrata/gists{/gist_id}","starred_url":"https://api.github.com/users/socrata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/socrata/subscriptions","organizations_url":"https://api.github.com/users/socrata/orgs","repos_url":"https://api.github.com/users/socrata/repos","events_url":"https://api.github.com/users/socrata/events{/privacy}","received_events_url":"https://api.github.com/users/socrata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/socrata/cetera-ruby","description":"Ruby wrapper around Cetera search service.","fork":false,"url":"https://api.github.com/repos/socrata/cetera-ruby","forks_url":"https://api.github.com/repos/socrata/cetera-ruby/forks","keys_url":"https://api.github.com/repos/socrata/cetera-ruby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/socrata/cetera-ruby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/socrata/cetera-ruby/teams","hooks_url":"https://api.github.com/repos/socrata/cetera-ruby/hooks","issue_events_url":"https://api.github.com/repos/socrata/cetera-ruby/issues/events{/number}","events_url":"https://api.github.com/repos/socrata/cetera-ruby/events","assignees_url":"https://api.github.com/repos/socrata/cetera-ruby/assignees{/user}","branches_url":"https://api.github.com/repos/socrata/cetera-ruby/branches{/branch}","tags_url":"https://api.github.com/repos/socrata/cetera-ruby/tags","blobs_url":"https://api.github.com/repos/socrata/cetera-ruby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/socrata/cetera-ruby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/socrata/cetera-ruby/git/refs{/sha}","trees_url":"https://api.github.com/repos/socrata/cetera-ruby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/socrata/cetera-ruby/statuses/{sha}","languages_url":"https://api.github.com/repos/socrata/cetera-ruby/languages","stargazers_url":"https://api.github.com/repos/socrata/cetera-ruby/stargazers","contributors_url":"https://api.github.com/repos/socrata/cetera-ruby/contributors","subscribers_url":"https://api.github.com/repos/socrata/cetera-ruby/subscribers","subscription_url":"https://api.github.com/repos/socrata/cetera-ruby/subscription","commits_url":"https://api.github.com/repos/socrata/cetera-ruby/commits{/sha}","git_commits_url":"https://api.github.com/repos/socrata/cetera-ruby/git/commits{/sha}","comments_url":"https://api.github.com/repos/socrata/cetera-ruby/comments{/number}","issue_comment_url":"https://api.github.com/repos/socrata/cetera-ruby/issues/comments{/number}","contents_url":"https://api.github.com/repos/socrata/cetera-ruby/contents/{+path}","compare_url":"https://api.github.com/repos/socrata/cetera-ruby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/socrata/cetera-ruby/merges","archive_url":"https://api.github.com/repos/socrata/cetera-ruby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/socrata/cetera-ruby/downloads","issues_url":"https://api.github.com/repos/socrata/cetera-ruby/issues{/number}","pulls_url":"https://api.github.com/repos/socrata/cetera-ruby/pulls{/number}","milestones_url":"https://api.github.com/repos/socrata/cetera-ruby/milestones{/number}","notifications_url":"https://api.github.com/repos/socrata/cetera-ruby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/socrata/cetera-ruby/labels{/name}","releases_url":"https://api.github.com/repos/socrata/cetera-ruby/releases{/id}","deployments_url":"https://api.github.com/repos/socrata/cetera-ruby/deployments","created_at":"2016-07-25T18:00:33Z","updated_at":"2016-07-25T18:00:33Z","pushed_at":"2016-07-25T21:17:24Z","git_url":"git://github.com/socrata/cetera-ruby.git","ssh_url":"git@github.com:socrata/cetera-ruby.git","clone_url":"https://github.com/socrata/cetera-ruby.git","svn_url":"https://github.com/socrata/cetera-ruby","homepage":null,"size":7,"stargazers_count":0,"watchers_count":0,"language":null,"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/socrata/cetera-ruby/pulls/1"},"html":{"href":"https://github.com/socrata/cetera-ruby/pull/1"},"issue":{"href":"https://api.github.com/repos/socrata/cetera-ruby/issues/1"},"comments":{"href":"https://api.github.com/repos/socrata/cetera-ruby/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/socrata/cetera-ruby/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/socrata/cetera-ruby/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/socrata/cetera-ruby/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/socrata/cetera-ruby/statuses/d119313237e88e5df7f76663854e0d793c3a1acb"}}}}
{"actor":{"display_login":"smooshy"}}