From 04d6c58cc468633613805a9c6d206675c0e475f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20Gonz=C3=A1lez?= Date: Thu, 12 Jul 2018 20:53:37 +0530 Subject: [PATCH] api: Add example for managing alert words. This example makes use of get_alert_words, add_alert_words and remove_alert_words, three methods that interact with the /users/me/alert_words REST API endpoint. --- zulip/zulip/__init__.py | 9 +++++++++ zulip/zulip/examples/alert-words | 31 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 zulip/zulip/examples/alert-words diff --git a/zulip/zulip/__init__.py b/zulip/zulip/__init__.py index f632cf3..2941e4c 100644 --- a/zulip/zulip/__init__.py +++ b/zulip/zulip/__init__.py @@ -897,6 +897,9 @@ class Client(object): def get_alert_words(self): # type: () -> Dict[str, Any] + ''' + See examples/alert-words for example usage. + ''' return self.call_endpoint( url='users/me/alert_words', method='GET' @@ -904,6 +907,9 @@ class Client(object): def add_alert_words(self, alert_words): # type: (List[str]) -> Dict[str, Any] + ''' + See examples/alert-words for example usage. + ''' return self.call_endpoint( url='users/me/alert_words', method='POST', @@ -914,6 +920,9 @@ class Client(object): def remove_alert_words(self, alert_words): # type: (List[str]) -> Dict[str, Any] + ''' + See examples/alert-words for example usage. + ''' return self.call_endpoint( url='users/me/alert_words', method='DELETE', diff --git a/zulip/zulip/examples/alert-words b/zulip/zulip/examples/alert-words new file mode 100755 index 0000000..b1e6d1c --- /dev/null +++ b/zulip/zulip/examples/alert-words @@ -0,0 +1,31 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import argparse + +import zulip + +usage = """alert-words (get | add | remove) [words] [options] + + +Example: alert-words get +Example: alert-words add foo bar +Example: alert-words remove banana +""" + + +parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage)) +parser.add_argument('operation', choices=['get', 'add', 'remove'], type=str) +parser.add_argument('words', type=str, nargs='*') +options = parser.parse_args() + +client = zulip.init_from_options(options) + +if options.operation == 'get': + result = client.get_alert_words() +elif options.operation == 'add': + result = client.add_alert_words(options.words) +elif options.operation == 'remove': + result = client.remove_alert_words(options.words) + +print(result)