From 2045b73ea4968dc7234fbae196016d7cf45d8f77 Mon Sep 17 00:00:00 2001 From: Zev Benjamin Date: Sat, 1 Mar 2014 23:49:17 -0500 Subject: [PATCH] api: Add get_subscribers method (imported from commit 801021768431a04cfecf146b58f4d118e1dc7508) --- zulip/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/zulip/__init__.py b/zulip/__init__.py index 6f0bf81..4be0921 100644 --- a/zulip/__init__.py +++ b/zulip/__init__.py @@ -29,6 +29,7 @@ import sys import os import optparse import platform +import urllib from distutils.version import LooseVersion from ConfigParser import SafeConfigParser @@ -245,12 +246,16 @@ class Client(object): @classmethod def _register(cls, name, url=None, make_request=(lambda request={}: request), - method="POST", **query_kwargs): + method="POST", computed_url=None, **query_kwargs): if url is None: url = name def call(self, *args, **kwargs): request = make_request(*args, **kwargs) - return self.do_api_query(request, API_VERSTRING + url, method=method, **query_kwargs) + if computed_url is not None: + req_url = computed_url(request) + else: + req_url = url + return self.do_api_query(request, API_VERSTRING + req_url, method=method, **query_kwargs) call.func_name = name setattr(cls, name, call) @@ -363,5 +368,8 @@ Client._register('get_members', method='GET', url='users') Client._register('list_subscriptions', method='GET', url='users/me/subscriptions') Client._register('add_subscriptions', url='users/me/subscriptions', make_request=_mk_subs) Client._register('remove_subscriptions', method='PATCH', url='users/me/subscriptions', make_request=_mk_rm_subs) +Client._register('get_subscribers', method='GET', + computed_url=lambda request: 'streams/%s/members' % (urllib.quote(request['stream'], safe=''),), + make_request=_kwargs_to_dict) Client._register('render_message', method='GET', url='messages/render') Client._register('create_user', method='POST', url='users')