Move message handling in RPC responses out of individual commands and to a general property of the response.

This commit is contained in:
Ian Gulliver
2014-05-06 13:47:57 -07:00
parent cf05c0f620
commit bb5c0752b1
3 changed files with 17 additions and 10 deletions

16
api.py
View File

@@ -94,11 +94,21 @@ class APIWrapper(webapp2.RequestHandler):
@security.weak_security_checks
@session.session_required
def post(self):
ret = []
ret = {
'status': 'ok',
'responses': [],
'messages': [],
}
for command in self.request_json['commands']:
callback = self._COMMANDS[command['command']]
result = callback(self.verified_google_user, self.client, command.get('arguments', {}))
ret.append(result)
result = callback(
self.verified_google_user,
self.client,
command.get('arguments', {}))
# Magic: if result contains "messages", haul them up a level so the
# client can see them as a single stream.
ret['messages'].extend(result.pop('messages', []))
ret['responses'].append(result)
return ret