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.
This commit is contained in:
Yago González 2018-07-12 20:53:37 +05:30 committed by Eeshan Garg
parent 3070106365
commit 04d6c58cc4
2 changed files with 40 additions and 0 deletions

View file

@ -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',

View file

@ -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)