From 5689e99a0d09443e6a17f18676a029806bbf0c84 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 16 Nov 2012 14:15:03 -0500 Subject: [PATCH] API: Add unsubscribe function. (imported from commit 6dc55e9030770500770ce3921a4e77499d64f2d6) --- common.py | 4 ++++ examples/unsubscribe | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 examples/unsubscribe diff --git a/common.py b/common.py index 8902748..8bfc0e7 100644 --- a/common.py +++ b/common.py @@ -110,6 +110,10 @@ class HumbugAPI(): request = {'subscriptions': streams} return self.do_api_query(request, "/api/v1/subscriptions/add") + def remove_subscriptions(self, streams): + request = {'subscriptions': streams} + return self.do_api_query(request, "/api/v1/subscriptions/remove") + def call_on_each_message(self, callback, options = {}): max_message_id = None while True: diff --git a/examples/unsubscribe b/examples/unsubscribe new file mode 100755 index 0000000..2b8ad1c --- /dev/null +++ b/examples/unsubscribe @@ -0,0 +1,41 @@ +#!/usr/bin/python +import sys +import os +import optparse + +usage = """unsubscribe --user= [options] --streams= + +Ensures the user is not subscribed to the listed streams. + +Example: unsubscribe --user=tabbott@humbughq.com --site=http://127.0.0.1:8000 +""" +parser = optparse.OptionParser(usage=usage) +parser.add_option('--site', + dest='site', + default="https://humbughq.com", + action='store') +parser.add_option('--api-key', + dest='api_key', + default="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + action='store') +parser.add_option('--streams', + dest='streams', + default="", + action='store') +parser.add_option('--user', + dest='user', + action='store') +(options, args) = parser.parse_args() + +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) +import api.common +client = api.common.HumbugAPI(email=options.user, + api_key=options.api_key, + verbose=True, + site=options.site) + +if options.streams == "": + print >>sys.stderr, "Usage:", parser.usage + sys.exit(1) + +print client.remove_subscriptions(options.streams.split())