Skip to content

Commit

Permalink
Expose User options to web and internal interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
jordoh authored and raikage committed Nov 2, 2010
1 parent 7d9044c commit a66b247
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions hookbox/api/internal.py
Expand Up @@ -50,6 +50,18 @@ def disconnect_user(self, name):
raise ExpectedException("User %s doesn't exist" % (name,))
user = self.server.get_user(name)
# TODO: disconnect the user

def set_user_options(self, user_name, options):
if not self.server.exists_user(user_name):
raise ExpectedException("User %s doesn't exists" % (user_name,))
user = self.server.get_user(user_name)
user.update_options(**options)

def get_user_info(self, user_name):
if not self.server.exists_user(user_name):
raise ExpectedException("User %s doesn't exists" % (user_name,))
user = self.server.get_user(user_name)
return user.serialize()

def disconnect(self, identifier):
raise ExpectedException("Not Implemented")
Expand Down
21 changes: 21 additions & 0 deletions hookbox/api/web.py
Expand Up @@ -85,6 +85,27 @@ def render_subscribe(self, form, start_response):
start_response('200 Ok', [])
return json.dumps([True, {}])

def render_set_user_options(self, form, start_response):
user_name = form.pop('user_name', None)
if not user_name:
raise ExpectedException("Missing user_name")
for key, val in form.items():
try:
form[key] = json.loads(val)
except:
raise ExpectedException("Invalid json value for option %s" % (key,))
self.api.set_user_options(user_name, form)
start_response('200 Ok', [])
return json.dumps([True, {}])

def render_get_user_info(self, form, start_response):
user_name = form.get('user_name', None)
if not user_name:
raise ExpectedException("Missing user_name")
info = self.api.get_user_info(user_name)
start_response('200 Ok', [])
return json.dumps([True, info])

def render_disconnect(self, form, start_response):
identifier = form.get('identifier', None)
self.api.disconnect(identifier)
Expand Down

0 comments on commit a66b247

Please sign in to comment.