From 6972ce61c8073a91b65fa93c86e403c534e622e9 Mon Sep 17 00:00:00 2001 From: Rafid Aslam Date: Fri, 30 Dec 2016 17:42:59 +0700 Subject: [PATCH] Move endpoints to use stream_id instead of stream_name in their URLs - Change `stream_name` into `stream_id` on some API endpoints that use `stream_name` in their URLs to prevent confusion of `views` selection. For example: If the stream name is "foo/members", the URL would be trigger "^streams/(?P.*)/members$" and it would be confusing because we intend to use the endpoint with "^streams/(?P.*)$" regex. All stream-related endpoints now use stream id instead of stream name, except for a single endpoint that lets you convert stream names to stream ids. See https://github.com/zulip/zulip/issues/2930#issuecomment-269576231 - Add `get_stream_id()` method to Zulip API client, and change `get_subscribers()` method to comply with the new stream API (replace `stream_name` with `stream_id`). Fixes #2930. --- zulip/__init__.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/zulip/__init__.py b/zulip/__init__.py index 45a5756..209be5d 100644 --- a/zulip/__init__.py +++ b/zulip/__init__.py @@ -641,13 +641,30 @@ class Client(object): request=request, ) + def get_stream_id(self, stream): + # type: (str) -> Dict[str, Any] + ''' + Example usage: client.get_stream_id('devel') + ''' + stream_encoded = urllib.parse.quote(stream, safe='') + url = 'get_stream_id?stream=%s' % (stream_encoded,) + return self.call_endpoint( + url=url, + method='GET', + request=None, + ) + def get_subscribers(self, **request): # type: (**Any) -> Dict[str, Any] ''' Example usage: client.get_subscribers(stream='devel') ''' - stream = urllib.parse.quote(request['stream'], safe='') - url = 'streams/%s/members' % (stream,) + request_stream_id = self.get_stream_id(request['stream']) + try: + stream_id = request_stream_id['stream_id'] + except KeyError: + return request_stream_id + url = 'streams/%d/members' % (stream_id,) return self.call_endpoint( url=url, method='GET',