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<stream_name>.*)/members$" and it would be confusing because
we intend to use the endpoint with "^streams/(?P<stream_name>.*)$" 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.
This commit is contained in:
Rafid Aslam 2016-12-30 17:42:59 +07:00 committed by showell
parent 0e26a0bb3b
commit 6972ce61c8

View file

@ -641,13 +641,30 @@ class Client(object):
request=request, 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): def get_subscribers(self, **request):
# type: (**Any) -> Dict[str, Any] # type: (**Any) -> Dict[str, Any]
''' '''
Example usage: client.get_subscribers(stream='devel') Example usage: client.get_subscribers(stream='devel')
''' '''
stream = urllib.parse.quote(request['stream'], safe='') request_stream_id = self.get_stream_id(request['stream'])
url = 'streams/%s/members' % (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( return self.call_endpoint(
url=url, url=url,
method='GET', method='GET',