{"action":"created","comment":{"url":"https://api.github.com/repos/democracyworks/google-civic-clojure/pulls/comments/85570142","pull_request_review_id":6280946,"id":85570142,"diff_hunk":"@@ -1,39 +1,106 @@\n (ns google-civic.core\n   (:require [clj-http.client :as client]\n             [cheshire.core :as json]\n-            [slingshot.slingshot :refer [try+]]))\n+            [clojure.set :as set]))\n \n (def api-root \"https://www.googleapis.com/civicinfo/v2\")\n \n+(def temporary-rate-limit-reasons\n+  #{\"concurrentLimitExceeded\" \"rateLimitExceeded\"\n+    \"servingLimitExceeded\" \"userRateLimitExceeded\"})\n+\n+(defn temporary-rate-limit?\n+  \"True if the errors in the response only include errors from the\n+  temporary-rate-limit-reasons set and the code is 403.\"\n+  [response body]\n+  (and (= 403 (:status response))\n+       (let [errors (get-in body [:error :errors])\n+             reasons (->> errors (map :reason) set)]\n+         (and (seq reasons)\n+              (set/superset? temporary-rate-limit-reasons\n+                             reasons)))))\n+\n+(defn can-retry?\n+  \"We can retry if the response code indicates a server error, or\n+   if the error is deemed a temporary rate limit.\"\n+  [response body]\n+  (cond\n+    (client/server-error? response) true\n+    (temporary-rate-limit? response body) true\n+    :else\n+    false))\n+\n (defn api-url [endpoint]\n   (str api-root endpoint))\n \n (defn api-response [api-key endpoint & [query-params]]\n   (let [url (api-url endpoint)]\n     (client/get url {:accept :json","path":"src/google_civic/core.clj","position":39,"original_position":39,"commit_id":"d5e5a00eee2ac47b9b04e16eb9851df17609cd9d","original_commit_id":"d5e5a00eee2ac47b9b04e16eb9851df17609cd9d","user":{"login":"danielglauser","id":102263,"avatar_url":"https://avatars.githubusercontent.com/u/102263?v=3","gravatar_id":"","url":"https://api.github.com/users/danielglauser","html_url":"https://github.com/danielglauser","followers_url":"https://api.github.com/users/danielglauser/followers","following_url":"https://api.github.com/users/danielglauser/following{/other_user}","gists_url":"https://api.github.com/users/danielglauser/gists{/gist_id}","starred_url":"https://api.github.com/users/danielglauser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielglauser/subscriptions","organizations_url":"https://api.github.com/users/danielglauser/orgs","repos_url":"https://api.github.com/users/danielglauser/repos","events_url":"https://api.github.com/users/danielglauser/events{/privacy}","received_events_url":"https://api.github.com/users/danielglauser/received_events","type":"User","site_admin":false},"body":"It's not zero based, as in `:tries 0` means one try. If you want unlimited tries you use `:tries :unlimited`, otherwise `tries 0` should be a no-op.","created_at":"2016-10-28T17:01:01Z","updated_at":"2016-10-28T17:01:01Z","html_url":"https://github.com/democracyworks/google-civic-clojure/pull/1#discussion_r85570142","pull_request_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/democracyworks/google-civic-clojure/pulls/comments/85570142"},"html":{"href":"https://github.com/democracyworks/google-civic-clojure/pull/1#discussion_r85570142"},"pull_request":{"href":"https://api.github.com/repos/democracyworks/google-civic-clojure/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/democracyworks/google-civic-clojure/pulls/1","id":91231189,"html_url":"https://github.com/democracyworks/google-civic-clojure/pull/1","diff_url":"https://github.com/democracyworks/google-civic-clojure/pull/1.diff","patch_url":"https://github.com/democracyworks/google-civic-clojure/pull/1.patch","issue_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/issues/1","number":1,"state":"open","locked":false,"title":"Backoff retries","user":{"login":"tank157","id":4147,"avatar_url":"https://avatars.githubusercontent.com/u/4147?v=3","gravatar_id":"","url":"https://api.github.com/users/tank157","html_url":"https://github.com/tank157","followers_url":"https://api.github.com/users/tank157/followers","following_url":"https://api.github.com/users/tank157/following{/other_user}","gists_url":"https://api.github.com/users/tank157/gists{/gist_id}","starred_url":"https://api.github.com/users/tank157/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tank157/subscriptions","organizations_url":"https://api.github.com/users/tank157/orgs","repos_url":"https://api.github.com/users/tank157/repos","events_url":"https://api.github.com/users/tank157/events{/privacy}","received_events_url":"https://api.github.com/users/tank157/received_events","type":"User","site_admin":false},"body":"Can do optional backoff/retry http calls to the API when the response comes back as either a server error or one (or more) of several 403 reasons that should indicate a temporary rate limit exceeded. See the Civic Info API errors [here](https://developers.google.com/civic-information/docs/v2/errors) and more importantly the standard errors [here](https://developers.google.com/civic-information/docs/v2/standard_errors).\r\n\r\nIncorporating this will allow large scale operations to backoff when we might overwhelm Google, in particular the vote-tomorrow notifications.\r\n\r\nAssigning @danielglauser ","created_at":"2016-10-27T16:01:59Z","updated_at":"2016-10-28T17:01:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2b062db873c77fad5962fb12c0b64d91970f9667","assignee":{"login":"danielglauser","id":102263,"avatar_url":"https://avatars.githubusercontent.com/u/102263?v=3","gravatar_id":"","url":"https://api.github.com/users/danielglauser","html_url":"https://github.com/danielglauser","followers_url":"https://api.github.com/users/danielglauser/followers","following_url":"https://api.github.com/users/danielglauser/following{/other_user}","gists_url":"https://api.github.com/users/danielglauser/gists{/gist_id}","starred_url":"https://api.github.com/users/danielglauser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielglauser/subscriptions","organizations_url":"https://api.github.com/users/danielglauser/orgs","repos_url":"https://api.github.com/users/danielglauser/repos","events_url":"https://api.github.com/users/danielglauser/events{/privacy}","received_events_url":"https://api.github.com/users/danielglauser/received_events","type":"User","site_admin":false},"assignees":[{"login":"danielglauser","id":102263,"avatar_url":"https://avatars.githubusercontent.com/u/102263?v=3","gravatar_id":"","url":"https://api.github.com/users/danielglauser","html_url":"https://github.com/danielglauser","followers_url":"https://api.github.com/users/danielglauser/followers","following_url":"https://api.github.com/users/danielglauser/following{/other_user}","gists_url":"https://api.github.com/users/danielglauser/gists{/gist_id}","starred_url":"https://api.github.com/users/danielglauser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielglauser/subscriptions","organizations_url":"https://api.github.com/users/danielglauser/orgs","repos_url":"https://api.github.com/users/danielglauser/repos","events_url":"https://api.github.com/users/danielglauser/events{/privacy}","received_events_url":"https://api.github.com/users/danielglauser/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/pulls/1/commits","review_comments_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/pulls/1/comments","review_comment_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/pulls/comments{/number}","comments_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/issues/1/comments","statuses_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/statuses/d5e5a00eee2ac47b9b04e16eb9851df17609cd9d","head":{"label":"democracyworks:backoff-retries","ref":"backoff-retries","sha":"d5e5a00eee2ac47b9b04e16eb9851df17609cd9d","user":{"login":"democracyworks","id":1373557,"avatar_url":"https://avatars.githubusercontent.com/u/1373557?v=3","gravatar_id":"","url":"https://api.github.com/users/democracyworks","html_url":"https://github.com/democracyworks","followers_url":"https://api.github.com/users/democracyworks/followers","following_url":"https://api.github.com/users/democracyworks/following{/other_user}","gists_url":"https://api.github.com/users/democracyworks/gists{/gist_id}","starred_url":"https://api.github.com/users/democracyworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/democracyworks/subscriptions","organizations_url":"https://api.github.com/users/democracyworks/orgs","repos_url":"https://api.github.com/users/democracyworks/repos","events_url":"https://api.github.com/users/democracyworks/events{/privacy}","received_events_url":"https://api.github.com/users/democracyworks/received_events","type":"Organization","site_admin":false},"repo":{"id":6655227,"name":"google-civic-clojure","full_name":"democracyworks/google-civic-clojure","owner":{"login":"democracyworks","id":1373557,"avatar_url":"https://avatars.githubusercontent.com/u/1373557?v=3","gravatar_id":"","url":"https://api.github.com/users/democracyworks","html_url":"https://github.com/democracyworks","followers_url":"https://api.github.com/users/democracyworks/followers","following_url":"https://api.github.com/users/democracyworks/following{/other_user}","gists_url":"https://api.github.com/users/democracyworks/gists{/gist_id}","starred_url":"https://api.github.com/users/democracyworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/democracyworks/subscriptions","organizations_url":"https://api.github.com/users/democracyworks/orgs","repos_url":"https://api.github.com/users/democracyworks/repos","events_url":"https://api.github.com/users/democracyworks/events{/privacy}","received_events_url":"https://api.github.com/users/democracyworks/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/democracyworks/google-civic-clojure","description":"Google Civic Info API client for Clojure","fork":false,"url":"https://api.github.com/repos/democracyworks/google-civic-clojure","forks_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/forks","keys_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/keys{/key_id}","collaborators_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/teams","hooks_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/hooks","issue_events_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/issues/events{/number}","events_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/events","assignees_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/assignees{/user}","branches_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/branches{/branch}","tags_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/tags","blobs_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/git/refs{/sha}","trees_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/git/trees{/sha}","statuses_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/statuses/{sha}","languages_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/languages","stargazers_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/stargazers","contributors_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/contributors","subscribers_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/subscribers","subscription_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/subscription","commits_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/commits{/sha}","git_commits_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/git/commits{/sha}","comments_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/comments{/number}","issue_comment_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/issues/comments{/number}","contents_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/contents/{+path}","compare_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/compare/{base}...{head}","merges_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/merges","archive_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/downloads","issues_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/issues{/number}","pulls_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/pulls{/number}","milestones_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/milestones{/number}","notifications_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/labels{/name}","releases_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/releases{/id}","deployments_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/deployments","created_at":"2012-11-12T15:12:35Z","updated_at":"2016-10-27T15:37:56Z","pushed_at":"2016-10-27T16:53:08Z","git_url":"git://github.com/democracyworks/google-civic-clojure.git","ssh_url":"git@github.com:democracyworks/google-civic-clojure.git","clone_url":"https://github.com/democracyworks/google-civic-clojure.git","svn_url":"https://github.com/democracyworks/google-civic-clojure","homepage":null,"size":15,"stargazers_count":0,"watchers_count":0,"language":"Clojure","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":"democracyworks:master","ref":"master","sha":"32c1e84e373e04b8032e1fdbefbdeba40007fb98","user":{"login":"democracyworks","id":1373557,"avatar_url":"https://avatars.githubusercontent.com/u/1373557?v=3","gravatar_id":"","url":"https://api.github.com/users/democracyworks","html_url":"https://github.com/democracyworks","followers_url":"https://api.github.com/users/democracyworks/followers","following_url":"https://api.github.com/users/democracyworks/following{/other_user}","gists_url":"https://api.github.com/users/democracyworks/gists{/gist_id}","starred_url":"https://api.github.com/users/democracyworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/democracyworks/subscriptions","organizations_url":"https://api.github.com/users/democracyworks/orgs","repos_url":"https://api.github.com/users/democracyworks/repos","events_url":"https://api.github.com/users/democracyworks/events{/privacy}","received_events_url":"https://api.github.com/users/democracyworks/received_events","type":"Organization","site_admin":false},"repo":{"id":6655227,"name":"google-civic-clojure","full_name":"democracyworks/google-civic-clojure","owner":{"login":"democracyworks","id":1373557,"avatar_url":"https://avatars.githubusercontent.com/u/1373557?v=3","gravatar_id":"","url":"https://api.github.com/users/democracyworks","html_url":"https://github.com/democracyworks","followers_url":"https://api.github.com/users/democracyworks/followers","following_url":"https://api.github.com/users/democracyworks/following{/other_user}","gists_url":"https://api.github.com/users/democracyworks/gists{/gist_id}","starred_url":"https://api.github.com/users/democracyworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/democracyworks/subscriptions","organizations_url":"https://api.github.com/users/democracyworks/orgs","repos_url":"https://api.github.com/users/democracyworks/repos","events_url":"https://api.github.com/users/democracyworks/events{/privacy}","received_events_url":"https://api.github.com/users/democracyworks/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/democracyworks/google-civic-clojure","description":"Google Civic Info API client for Clojure","fork":false,"url":"https://api.github.com/repos/democracyworks/google-civic-clojure","forks_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/forks","keys_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/keys{/key_id}","collaborators_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/teams","hooks_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/hooks","issue_events_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/issues/events{/number}","events_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/events","assignees_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/assignees{/user}","branches_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/branches{/branch}","tags_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/tags","blobs_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/git/refs{/sha}","trees_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/git/trees{/sha}","statuses_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/statuses/{sha}","languages_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/languages","stargazers_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/stargazers","contributors_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/contributors","subscribers_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/subscribers","subscription_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/subscription","commits_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/commits{/sha}","git_commits_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/git/commits{/sha}","comments_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/comments{/number}","issue_comment_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/issues/comments{/number}","contents_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/contents/{+path}","compare_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/compare/{base}...{head}","merges_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/merges","archive_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/downloads","issues_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/issues{/number}","pulls_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/pulls{/number}","milestones_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/milestones{/number}","notifications_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/labels{/name}","releases_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/releases{/id}","deployments_url":"https://api.github.com/repos/democracyworks/google-civic-clojure/deployments","created_at":"2012-11-12T15:12:35Z","updated_at":"2016-10-27T15:37:56Z","pushed_at":"2016-10-27T16:53:08Z","git_url":"git://github.com/democracyworks/google-civic-clojure.git","ssh_url":"git@github.com:democracyworks/google-civic-clojure.git","clone_url":"https://github.com/democracyworks/google-civic-clojure.git","svn_url":"https://github.com/democracyworks/google-civic-clojure","homepage":null,"size":15,"stargazers_count":0,"watchers_count":0,"language":"Clojure","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/democracyworks/google-civic-clojure/pulls/1"},"html":{"href":"https://github.com/democracyworks/google-civic-clojure/pull/1"},"issue":{"href":"https://api.github.com/repos/democracyworks/google-civic-clojure/issues/1"},"comments":{"href":"https://api.github.com/repos/democracyworks/google-civic-clojure/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/democracyworks/google-civic-clojure/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/democracyworks/google-civic-clojure/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/democracyworks/google-civic-clojure/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/democracyworks/google-civic-clojure/statuses/d5e5a00eee2ac47b9b04e16eb9851df17609cd9d"}}}}
{"actor":{"display_login":"danielglauser"}}