diff --git a/README.md b/README.md index 07db75b..1335d4b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # API endpoints: -| Endpoint | Return | -| ------------------------ | ----------------------- | -| `/mocha/users/{user_id}` | row with the given user | -| `/mocha/users/*` | all rows | +| Endpoint | Return | +| ------------------------ | ------------------------------ | +| `/mocha/users/{user_id}` | row with the given user | +| `/mocha/users/*` | all rows | +| `/mocha/top/{n}` | user with the n highest scores | diff --git a/mocha_server.py b/mocha_server.py index bc7729d..fbcd6ec 100755 --- a/mocha_server.py +++ b/mocha_server.py @@ -104,6 +104,15 @@ def fetch_user(user_id): return output +def fetch_top_n(n): + output = get_top_N('score', True, n) + + if output == '[]': + output = None + + return output + + def process_request(uri): """ Handles the API endpoint. @@ -118,6 +127,8 @@ def process_request(uri): if parts[1] == 'users': output = fetch_user(parts[2]) + elif parts[1] == 'top': + output = fetch_top_n(parts[2]) return output