{"action":"created","comment":{"url":"https://api.github.com/repos/cloudtools/nymms/pulls/comments/26000544","id":26000544,"diff_hunk":"@@ -0,0 +1,142 @@\n+import arrow\n+\n+from flask import request\n+from flask.ext.api import FlaskAPI\n+from flask.ext.api import status\n+\n+from schematics.exceptions import ValidationError\n+\n+from nymms.state import sdb_state\n+from nymms.suppress import sdb_suppress\n+from nymms.schemas import APIResult, APISuppression, APIStateRecord\n+from nymms.config import config\n+from nymms.utils import aws_helper\n+from nymms import schemas\n+\n+\n+nymms_api = FlaskAPI(__name__)\n+\n+\n+@nymms_api.route('/state', methods=['GET'])\n+def state():\n+    \"\"\"\n+    List current states.\n+    \"\"\"\n+    region = config.settings['region']\n+    domain = config.settings['state_domain']\n+\n+    state = sdb_state.SDBStateBackend(region, domain)\n+    states = state.get_all_states(","path":"nymms/api/routes.py","position":29,"original_position":29,"commit_id":"416021958b871789a10ef1352a567e476cfa47c1","original_commit_id":"416021958b871789a10ef1352a567e476cfa47c1","user":{"login":"phobologic","id":517334,"avatar_url":"https://avatars.githubusercontent.com/u/517334?v=3","gravatar_id":"","url":"https://api.github.com/users/phobologic","html_url":"https://github.com/phobologic","followers_url":"https://api.github.com/users/phobologic/followers","following_url":"https://api.github.com/users/phobologic/following{/other_user}","gists_url":"https://api.github.com/users/phobologic/gists{/gist_id}","starred_url":"https://api.github.com/users/phobologic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phobologic/subscriptions","organizations_url":"https://api.github.com/users/phobologic/orgs","repos_url":"https://api.github.com/users/phobologic/repos","events_url":"https://api.github.com/users/phobologic/events{/privacy}","received_events_url":"https://api.github.com/users/phobologic/received_events","type":"User","site_admin":false},"body":"So - while working on my own API I was using this, but it had an issue - especially if you wanted to do anything like pagination with results.\r\n\r\nhttp://docs.aws.amazon.com/AmazonSimpleDB/latest/DeveloperGuide/UsingSelect.html\r\n\r\nSDB will, at max return 2500 records (100 by default) and a max of 1mb of results.  it then provides a token that you can requery.\r\n\r\nI started to work with this with this method (I ended up replacing get_all_states with it):\r\n\r\n```\r\n    def filter(self, filters=None, order_by=None, consistent_read=True,\r\n               max_items=None, next_token=None):\r\n        order_by = order_by or getattr(self.schema, 'default_sort_order')\r\n\r\n        query = \"select * from %s\" % self.domain_name\r\n        if filters:\r\n            query += \" where \"\r\n            query += ' and '.join(filters)\r\n\r\n        # TODO: This is kind of a weak way of dealing with the fact that in\r\n        # order to order by something it has to be specified in the where\r\n        # field.\r\n        if order_by and order_by in query:\r\n            query += \" order by `%s`\" % order_by\r\n\r\n        results = []\r\n\r\n        if max_items:\r\n            max_items = int(max_items)\r\n            query += \" limit %s\" % max_items\r\n\r\n        logger.debug(\"Executing query: %s\", query)\r\n        query_results = self.domain.select(query,\r\n                                           consistent_read=consistent_read,\r\n                                           max_items=max_items,\r\n                                           next_token=next_token)\r\n        for item in query_results:\r\n            results.append(self.deserialize(item))\r\n\r\n        _next_token = query_results.next_token\r\n        if _next_token:\r\n            _next_token = _next_token.replace('\\n', '')\r\n        return (results, _next_token)\r\n```\r\n\r\nHow would you expect this to work in your API?  Just keep doing filter() calls till you reach the end of the list of states?","created_at":"2015-03-07T23:19:54Z","updated_at":"2015-03-07T23:19:54Z","html_url":"https://github.com/cloudtools/nymms/pull/31#discussion_r26000544","pull_request_url":"https://api.github.com/repos/cloudtools/nymms/pulls/31","_links":{"self":{"href":"https://api.github.com/repos/cloudtools/nymms/pulls/comments/26000544"},"html":{"href":"https://github.com/cloudtools/nymms/pull/31#discussion_r26000544"},"pull_request":{"href":"https://api.github.com/repos/cloudtools/nymms/pulls/31"}}},"pull_request":{"url":"https://api.github.com/repos/cloudtools/nymms/pulls/31","id":30605622,"html_url":"https://github.com/cloudtools/nymms/pull/31","diff_url":"https://github.com/cloudtools/nymms/pull/31.diff","patch_url":"https://github.com/cloudtools/nymms/pull/31.patch","issue_url":"https://api.github.com/repos/cloudtools/nymms/issues/31","number":31,"state":"open","locked":false,"title":"Add REST API to NYMMS","user":{"login":"berndtj","id":78191,"avatar_url":"https://avatars.githubusercontent.com/u/78191?v=3","gravatar_id":"","url":"https://api.github.com/users/berndtj","html_url":"https://github.com/berndtj","followers_url":"https://api.github.com/users/berndtj/followers","following_url":"https://api.github.com/users/berndtj/following{/other_user}","gists_url":"https://api.github.com/users/berndtj/gists{/gist_id}","starred_url":"https://api.github.com/users/berndtj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/berndtj/subscriptions","organizations_url":"https://api.github.com/users/berndtj/orgs","repos_url":"https://api.github.com/users/berndtj/repos","events_url":"https://api.github.com/users/berndtj/events{/privacy}","received_events_url":"https://api.github.com/users/berndtj/received_events","type":"User","site_admin":false},"body":"* Use Flask-API for simple REST interface\r\n\r\n* Shim in different serirializers (more user friendly) for\r\n  API\r\n\r\n* Additionally allow setting of base config for easier\r\n  development on local systems\r\n\r\n* Add a bunch of sample configs which work for dev","created_at":"2015-03-05T23:08:42Z","updated_at":"2015-03-07T23:19:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8ed256f060021d8ef1f995bb34ae88844661836d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cloudtools/nymms/pulls/31/commits","review_comments_url":"https://api.github.com/repos/cloudtools/nymms/pulls/31/comments","review_comment_url":"https://api.github.com/repos/cloudtools/nymms/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cloudtools/nymms/issues/31/comments","statuses_url":"https://api.github.com/repos/cloudtools/nymms/statuses/416021958b871789a10ef1352a567e476cfa47c1","head":{"label":"berndtj:nymms-api","ref":"nymms-api","sha":"416021958b871789a10ef1352a567e476cfa47c1","user":{"login":"berndtj","id":78191,"avatar_url":"https://avatars.githubusercontent.com/u/78191?v=3","gravatar_id":"","url":"https://api.github.com/users/berndtj","html_url":"https://github.com/berndtj","followers_url":"https://api.github.com/users/berndtj/followers","following_url":"https://api.github.com/users/berndtj/following{/other_user}","gists_url":"https://api.github.com/users/berndtj/gists{/gist_id}","starred_url":"https://api.github.com/users/berndtj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/berndtj/subscriptions","organizations_url":"https://api.github.com/users/berndtj/orgs","repos_url":"https://api.github.com/users/berndtj/repos","events_url":"https://api.github.com/users/berndtj/events{/privacy}","received_events_url":"https://api.github.com/users/berndtj/received_events","type":"User","site_admin":false},"repo":{"id":31741235,"name":"nymms","full_name":"berndtj/nymms","owner":{"login":"berndtj","id":78191,"avatar_url":"https://avatars.githubusercontent.com/u/78191?v=3","gravatar_id":"","url":"https://api.github.com/users/berndtj","html_url":"https://github.com/berndtj","followers_url":"https://api.github.com/users/berndtj/followers","following_url":"https://api.github.com/users/berndtj/following{/other_user}","gists_url":"https://api.github.com/users/berndtj/gists{/gist_id}","starred_url":"https://api.github.com/users/berndtj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/berndtj/subscriptions","organizations_url":"https://api.github.com/users/berndtj/orgs","repos_url":"https://api.github.com/users/berndtj/repos","events_url":"https://api.github.com/users/berndtj/events{/privacy}","received_events_url":"https://api.github.com/users/berndtj/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/berndtj/nymms","description":"Not Your Mother's Monitoring System","fork":true,"url":"https://api.github.com/repos/berndtj/nymms","forks_url":"https://api.github.com/repos/berndtj/nymms/forks","keys_url":"https://api.github.com/repos/berndtj/nymms/keys{/key_id}","collaborators_url":"https://api.github.com/repos/berndtj/nymms/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/berndtj/nymms/teams","hooks_url":"https://api.github.com/repos/berndtj/nymms/hooks","issue_events_url":"https://api.github.com/repos/berndtj/nymms/issues/events{/number}","events_url":"https://api.github.com/repos/berndtj/nymms/events","assignees_url":"https://api.github.com/repos/berndtj/nymms/assignees{/user}","branches_url":"https://api.github.com/repos/berndtj/nymms/branches{/branch}","tags_url":"https://api.github.com/repos/berndtj/nymms/tags","blobs_url":"https://api.github.com/repos/berndtj/nymms/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/berndtj/nymms/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/berndtj/nymms/git/refs{/sha}","trees_url":"https://api.github.com/repos/berndtj/nymms/git/trees{/sha}","statuses_url":"https://api.github.com/repos/berndtj/nymms/statuses/{sha}","languages_url":"https://api.github.com/repos/berndtj/nymms/languages","stargazers_url":"https://api.github.com/repos/berndtj/nymms/stargazers","contributors_url":"https://api.github.com/repos/berndtj/nymms/contributors","subscribers_url":"https://api.github.com/repos/berndtj/nymms/subscribers","subscription_url":"https://api.github.com/repos/berndtj/nymms/subscription","commits_url":"https://api.github.com/repos/berndtj/nymms/commits{/sha}","git_commits_url":"https://api.github.com/repos/berndtj/nymms/git/commits{/sha}","comments_url":"https://api.github.com/repos/berndtj/nymms/comments{/number}","issue_comment_url":"https://api.github.com/repos/berndtj/nymms/issues/comments{/number}","contents_url":"https://api.github.com/repos/berndtj/nymms/contents/{+path}","compare_url":"https://api.github.com/repos/berndtj/nymms/compare/{base}...{head}","merges_url":"https://api.github.com/repos/berndtj/nymms/merges","archive_url":"https://api.github.com/repos/berndtj/nymms/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/berndtj/nymms/downloads","issues_url":"https://api.github.com/repos/berndtj/nymms/issues{/number}","pulls_url":"https://api.github.com/repos/berndtj/nymms/pulls{/number}","milestones_url":"https://api.github.com/repos/berndtj/nymms/milestones{/number}","notifications_url":"https://api.github.com/repos/berndtj/nymms/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/berndtj/nymms/labels{/name}","releases_url":"https://api.github.com/repos/berndtj/nymms/releases{/id}","created_at":"2015-03-05T22:53:24Z","updated_at":"2015-03-05T22:53:24Z","pushed_at":"2015-03-05T23:06:23Z","git_url":"git://github.com/berndtj/nymms.git","ssh_url":"git@github.com:berndtj/nymms.git","clone_url":"https://github.com/berndtj/nymms.git","svn_url":"https://github.com/berndtj/nymms","homepage":null,"size":456,"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":"cloudtools:master","ref":"master","sha":"814b0e1831dd98dcbfc04cda0959ab32623c3699","user":{"login":"cloudtools","id":3028687,"avatar_url":"https://avatars.githubusercontent.com/u/3028687?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudtools","html_url":"https://github.com/cloudtools","followers_url":"https://api.github.com/users/cloudtools/followers","following_url":"https://api.github.com/users/cloudtools/following{/other_user}","gists_url":"https://api.github.com/users/cloudtools/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudtools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudtools/subscriptions","organizations_url":"https://api.github.com/users/cloudtools/orgs","repos_url":"https://api.github.com/users/cloudtools/repos","events_url":"https://api.github.com/users/cloudtools/events{/privacy}","received_events_url":"https://api.github.com/users/cloudtools/received_events","type":"Organization","site_admin":false},"repo":{"id":9202192,"name":"nymms","full_name":"cloudtools/nymms","owner":{"login":"cloudtools","id":3028687,"avatar_url":"https://avatars.githubusercontent.com/u/3028687?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudtools","html_url":"https://github.com/cloudtools","followers_url":"https://api.github.com/users/cloudtools/followers","following_url":"https://api.github.com/users/cloudtools/following{/other_user}","gists_url":"https://api.github.com/users/cloudtools/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudtools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudtools/subscriptions","organizations_url":"https://api.github.com/users/cloudtools/orgs","repos_url":"https://api.github.com/users/cloudtools/repos","events_url":"https://api.github.com/users/cloudtools/events{/privacy}","received_events_url":"https://api.github.com/users/cloudtools/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudtools/nymms","description":"Not Your Mother's Monitoring System","fork":false,"url":"https://api.github.com/repos/cloudtools/nymms","forks_url":"https://api.github.com/repos/cloudtools/nymms/forks","keys_url":"https://api.github.com/repos/cloudtools/nymms/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudtools/nymms/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudtools/nymms/teams","hooks_url":"https://api.github.com/repos/cloudtools/nymms/hooks","issue_events_url":"https://api.github.com/repos/cloudtools/nymms/issues/events{/number}","events_url":"https://api.github.com/repos/cloudtools/nymms/events","assignees_url":"https://api.github.com/repos/cloudtools/nymms/assignees{/user}","branches_url":"https://api.github.com/repos/cloudtools/nymms/branches{/branch}","tags_url":"https://api.github.com/repos/cloudtools/nymms/tags","blobs_url":"https://api.github.com/repos/cloudtools/nymms/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudtools/nymms/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudtools/nymms/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudtools/nymms/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudtools/nymms/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudtools/nymms/languages","stargazers_url":"https://api.github.com/repos/cloudtools/nymms/stargazers","contributors_url":"https://api.github.com/repos/cloudtools/nymms/contributors","subscribers_url":"https://api.github.com/repos/cloudtools/nymms/subscribers","subscription_url":"https://api.github.com/repos/cloudtools/nymms/subscription","commits_url":"https://api.github.com/repos/cloudtools/nymms/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudtools/nymms/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudtools/nymms/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudtools/nymms/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudtools/nymms/contents/{+path}","compare_url":"https://api.github.com/repos/cloudtools/nymms/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudtools/nymms/merges","archive_url":"https://api.github.com/repos/cloudtools/nymms/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudtools/nymms/downloads","issues_url":"https://api.github.com/repos/cloudtools/nymms/issues{/number}","pulls_url":"https://api.github.com/repos/cloudtools/nymms/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudtools/nymms/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudtools/nymms/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudtools/nymms/labels{/name}","releases_url":"https://api.github.com/repos/cloudtools/nymms/releases{/id}","created_at":"2013-04-03T18:46:03Z","updated_at":"2015-01-26T10:46:48Z","pushed_at":"2014-11-10T05:38:14Z","git_url":"git://github.com/cloudtools/nymms.git","ssh_url":"git@github.com:cloudtools/nymms.git","clone_url":"https://github.com/cloudtools/nymms.git","svn_url":"https://github.com/cloudtools/nymms","homepage":null,"size":1360,"stargazers_count":23,"watchers_count":23,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":15,"forks":3,"open_issues":15,"watchers":23,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cloudtools/nymms/pulls/31"},"html":{"href":"https://github.com/cloudtools/nymms/pull/31"},"issue":{"href":"https://api.github.com/repos/cloudtools/nymms/issues/31"},"comments":{"href":"https://api.github.com/repos/cloudtools/nymms/issues/31/comments"},"review_comments":{"href":"https://api.github.com/repos/cloudtools/nymms/pulls/31/comments"},"review_comment":{"href":"https://api.github.com/repos/cloudtools/nymms/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cloudtools/nymms/pulls/31/commits"},"statuses":{"href":"https://api.github.com/repos/cloudtools/nymms/statuses/416021958b871789a10ef1352a567e476cfa47c1"}}}}