{"action":"created","comment":{"url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/pulls/comments/53278408","id":53278408,"diff_hunk":"@@ -124,15 +124,22 @@ def parse_cli_args(self):\n                             help='Force refresh of cache by making API requests to foreman (default: False - use cache files)')\n         self.args = parser.parse_args()\n \n-    def _get_json(self, url):\n+    def _get_json(self, url, page = 1, results = []):\n         ret = requests.get(url,\n                            auth=HTTPBasicAuth(self.foreman_user, self.foreman_pw),\n-                           verify=self.foreman_ssl_verify)\n+                           verify=self.foreman_ssl_verify,\n+                           params={'page': page})\n         ret.raise_for_status()\n-        return ret.json()\n+        if not ret.json().has_key('results'):\n+            return ret.json()\n+        results = results + ret.json()['results']\n+        if len(results) >= ret.json()['total']:\n+            return results\n+        else:\n+            return self._get_json(url, page=page+1, results=results)","path":"foreman_ansible_inventory.py","position":19,"original_position":19,"commit_id":"18423747f8c6e94b1f33f08f90ae623a6340b12a","original_commit_id":"18423747f8c6e94b1f33f08f90ae623a6340b12a","user":{"login":"agx","id":2052773,"avatar_url":"https://avatars.githubusercontent.com/u/2052773?v=3","gravatar_id":"","url":"https://api.github.com/users/agx","html_url":"https://github.com/agx","followers_url":"https://api.github.com/users/agx/followers","following_url":"https://api.github.com/users/agx/following{/other_user}","gists_url":"https://api.github.com/users/agx/gists{/gist_id}","starred_url":"https://api.github.com/users/agx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agx/subscriptions","organizations_url":"https://api.github.com/users/agx/orgs","repos_url":"https://api.github.com/users/agx/repos","events_url":"https://api.github.com/users/agx/events{/privacy}","received_events_url":"https://api.github.com/users/agx/received_events","type":"User","site_admin":false},"body":"Wouldn't we better not recurse here but use a simple loop? Otherwise we keep references to lots of data for now good reason. And I don't think python optimizes tail recursion ;)","created_at":"2016-02-18T07:13:27Z","updated_at":"2016-02-18T07:13:27Z","html_url":"https://github.com/theforeman/foreman_ansible_inventory/pull/4#discussion_r53278408","pull_request_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/pulls/comments/53278408"},"html":{"href":"https://github.com/theforeman/foreman_ansible_inventory/pull/4#discussion_r53278408"},"pull_request":{"href":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/pulls/4","id":59710544,"html_url":"https://github.com/theforeman/foreman_ansible_inventory/pull/4","diff_url":"https://github.com/theforeman/foreman_ansible_inventory/pull/4.diff","patch_url":"https://github.com/theforeman/foreman_ansible_inventory/pull/4.patch","issue_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/issues/4","number":4,"state":"open","locked":false,"title":"add support for pagination","user":{"login":"brandonweeks","id":15869,"avatar_url":"https://avatars.githubusercontent.com/u/15869?v=3","gravatar_id":"","url":"https://api.github.com/users/brandonweeks","html_url":"https://github.com/brandonweeks","followers_url":"https://api.github.com/users/brandonweeks/followers","following_url":"https://api.github.com/users/brandonweeks/following{/other_user}","gists_url":"https://api.github.com/users/brandonweeks/gists{/gist_id}","starred_url":"https://api.github.com/users/brandonweeks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brandonweeks/subscriptions","organizations_url":"https://api.github.com/users/brandonweeks/orgs","repos_url":"https://api.github.com/users/brandonweeks/repos","events_url":"https://api.github.com/users/brandonweeks/events{/privacy}","received_events_url":"https://api.github.com/users/brandonweeks/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-02-17T21:20:08Z","updated_at":"2016-02-18T07:13:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"453906d59873ca729d202ec6e299de8ee2aa27e7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/pulls/4/commits","review_comments_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/pulls/4/comments","review_comment_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/pulls/comments{/number}","comments_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/issues/4/comments","statuses_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/statuses/18423747f8c6e94b1f33f08f90ae623a6340b12a","head":{"label":"brandonweeks:pagination","ref":"pagination","sha":"18423747f8c6e94b1f33f08f90ae623a6340b12a","user":{"login":"brandonweeks","id":15869,"avatar_url":"https://avatars.githubusercontent.com/u/15869?v=3","gravatar_id":"","url":"https://api.github.com/users/brandonweeks","html_url":"https://github.com/brandonweeks","followers_url":"https://api.github.com/users/brandonweeks/followers","following_url":"https://api.github.com/users/brandonweeks/following{/other_user}","gists_url":"https://api.github.com/users/brandonweeks/gists{/gist_id}","starred_url":"https://api.github.com/users/brandonweeks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brandonweeks/subscriptions","organizations_url":"https://api.github.com/users/brandonweeks/orgs","repos_url":"https://api.github.com/users/brandonweeks/repos","events_url":"https://api.github.com/users/brandonweeks/events{/privacy}","received_events_url":"https://api.github.com/users/brandonweeks/received_events","type":"User","site_admin":false},"repo":{"id":51953848,"name":"foreman_ansible_inventory","full_name":"brandonweeks/foreman_ansible_inventory","owner":{"login":"brandonweeks","id":15869,"avatar_url":"https://avatars.githubusercontent.com/u/15869?v=3","gravatar_id":"","url":"https://api.github.com/users/brandonweeks","html_url":"https://github.com/brandonweeks","followers_url":"https://api.github.com/users/brandonweeks/followers","following_url":"https://api.github.com/users/brandonweeks/following{/other_user}","gists_url":"https://api.github.com/users/brandonweeks/gists{/gist_id}","starred_url":"https://api.github.com/users/brandonweeks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brandonweeks/subscriptions","organizations_url":"https://api.github.com/users/brandonweeks/orgs","repos_url":"https://api.github.com/users/brandonweeks/repos","events_url":"https://api.github.com/users/brandonweeks/events{/privacy}","received_events_url":"https://api.github.com/users/brandonweeks/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/brandonweeks/foreman_ansible_inventory","description":"Foreman dynamic inventory script for ansible","fork":true,"url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory","forks_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/forks","keys_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/keys{/key_id}","collaborators_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/teams","hooks_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/hooks","issue_events_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/issues/events{/number}","events_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/events","assignees_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/assignees{/user}","branches_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/branches{/branch}","tags_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/tags","blobs_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/git/refs{/sha}","trees_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/git/trees{/sha}","statuses_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/statuses/{sha}","languages_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/languages","stargazers_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/stargazers","contributors_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/contributors","subscribers_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/subscribers","subscription_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/subscription","commits_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/commits{/sha}","git_commits_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/git/commits{/sha}","comments_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/comments{/number}","issue_comment_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/issues/comments{/number}","contents_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/contents/{+path}","compare_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/compare/{base}...{head}","merges_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/merges","archive_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/downloads","issues_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/issues{/number}","pulls_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/pulls{/number}","milestones_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/milestones{/number}","notifications_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/labels{/name}","releases_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/releases{/id}","deployments_url":"https://api.github.com/repos/brandonweeks/foreman_ansible_inventory/deployments","created_at":"2016-02-17T20:41:06Z","updated_at":"2016-02-17T20:41:08Z","pushed_at":"2016-02-17T21:20:01Z","git_url":"git://github.com/brandonweeks/foreman_ansible_inventory.git","ssh_url":"git@github.com:brandonweeks/foreman_ansible_inventory.git","clone_url":"https://github.com/brandonweeks/foreman_ansible_inventory.git","svn_url":"https://github.com/brandonweeks/foreman_ansible_inventory","homepage":null,"size":25,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"theforeman:master","ref":"master","sha":"07d7d5f42ad84047f0512a28bc0136c4eed53ff8","user":{"login":"theforeman","id":1439844,"avatar_url":"https://avatars.githubusercontent.com/u/1439844?v=3","gravatar_id":"","url":"https://api.github.com/users/theforeman","html_url":"https://github.com/theforeman","followers_url":"https://api.github.com/users/theforeman/followers","following_url":"https://api.github.com/users/theforeman/following{/other_user}","gists_url":"https://api.github.com/users/theforeman/gists{/gist_id}","starred_url":"https://api.github.com/users/theforeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theforeman/subscriptions","organizations_url":"https://api.github.com/users/theforeman/orgs","repos_url":"https://api.github.com/users/theforeman/repos","events_url":"https://api.github.com/users/theforeman/events{/privacy}","received_events_url":"https://api.github.com/users/theforeman/received_events","type":"Organization","site_admin":false},"repo":{"id":50940412,"name":"foreman_ansible_inventory","full_name":"theforeman/foreman_ansible_inventory","owner":{"login":"theforeman","id":1439844,"avatar_url":"https://avatars.githubusercontent.com/u/1439844?v=3","gravatar_id":"","url":"https://api.github.com/users/theforeman","html_url":"https://github.com/theforeman","followers_url":"https://api.github.com/users/theforeman/followers","following_url":"https://api.github.com/users/theforeman/following{/other_user}","gists_url":"https://api.github.com/users/theforeman/gists{/gist_id}","starred_url":"https://api.github.com/users/theforeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theforeman/subscriptions","organizations_url":"https://api.github.com/users/theforeman/orgs","repos_url":"https://api.github.com/users/theforeman/repos","events_url":"https://api.github.com/users/theforeman/events{/privacy}","received_events_url":"https://api.github.com/users/theforeman/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/theforeman/foreman_ansible_inventory","description":"Foreman dynamic inventory script for ansible","fork":false,"url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory","forks_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/forks","keys_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/keys{/key_id}","collaborators_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/teams","hooks_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/hooks","issue_events_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/issues/events{/number}","events_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/events","assignees_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/assignees{/user}","branches_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/branches{/branch}","tags_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/tags","blobs_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/git/refs{/sha}","trees_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/git/trees{/sha}","statuses_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/statuses/{sha}","languages_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/languages","stargazers_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/stargazers","contributors_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/contributors","subscribers_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/subscribers","subscription_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/subscription","commits_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/commits{/sha}","git_commits_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/git/commits{/sha}","comments_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/comments{/number}","issue_comment_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/issues/comments{/number}","contents_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/contents/{+path}","compare_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/compare/{base}...{head}","merges_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/merges","archive_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/downloads","issues_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/issues{/number}","pulls_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/pulls{/number}","milestones_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/milestones{/number}","notifications_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/labels{/name}","releases_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/releases{/id}","deployments_url":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/deployments","created_at":"2016-02-02T18:03:19Z","updated_at":"2016-02-16T23:51:38Z","pushed_at":"2016-02-17T22:13:19Z","git_url":"git://github.com/theforeman/foreman_ansible_inventory.git","ssh_url":"git@github.com:theforeman/foreman_ansible_inventory.git","clone_url":"https://github.com/theforeman/foreman_ansible_inventory.git","svn_url":"https://github.com/theforeman/foreman_ansible_inventory","homepage":null,"size":25,"stargazers_count":5,"watchers_count":5,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/pulls/4"},"html":{"href":"https://github.com/theforeman/foreman_ansible_inventory/pull/4"},"issue":{"href":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/issues/4"},"comments":{"href":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/theforeman/foreman_ansible_inventory/statuses/18423747f8c6e94b1f33f08f90ae623a6340b12a"}}}}