From 66da09324ec11ade89e67688a9965e9d511004de Mon Sep 17 00:00:00 2001 From: derAnfaenger Date: Mon, 30 Oct 2017 18:43:21 +0100 Subject: [PATCH] zulip package: Add API functions to access state. --- zulip/zulip/__init__.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/zulip/zulip/__init__.py b/zulip/zulip/__init__.py index 9a529ba..b5c5617 100644 --- a/zulip/zulip/__init__.py +++ b/zulip/zulip/__init__.py @@ -859,6 +859,38 @@ class Client(object): request=request, ) + def update_state(self, request): + # type: (Dict[str, Any]) -> Dict[str, Any] + ''' + Example usage: + + >>> client.update_state({'state': {"entry 1": "value 1", "entry 2": "value 2", "entry 3": "value 3"}}) + >>> client.get_state({'keys': ["entry 1", "entry 3"]}) + {'result': 'success', 'state': {'entry 1': 'value 1', 'entry 3': 'value 3'}, 'msg': ''} + ''' + return self.call_endpoint( + url='user_state', + method='PUT', + request=request, + ) + + def get_state(self, request=None): + # type: (Optional[Dict[str, Any]]) -> Dict[str, Any] + ''' + Example usage: + + >>> client.update_state({'state': {"entry 1": "value 1", "entry 2": "value 2", "entry 3": "value 3"}}) + >>> client.get_state() + {'result': 'success', 'state': {"entry 1": "value 1", "entry 2": "value 2", "entry 3": "value 3"}, 'msg': ''} + >>> client.get_state(keys=('entry 1', 'entry 3')) + {'result': 'success', 'state': {'entry 1': 'value 1', 'entry 3': 'value 3'}, 'msg': ''} + ''' + return self.call_endpoint( + url='user_state', + method='GET', + request=request, + ) + class ZulipStream(object): """ A Zulip stream-like object