From 60464f797607ac92542d491559dec01946421e2f Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Thu, 11 Oct 2012 15:34:17 -0400 Subject: [PATCH] Add an API call to subscribe to a list of streams. (imported from commit 0a5d46d5f54fb4c8ebfad8c9adb777c0b4938dfa) --- common.py | 5 +++++ examples/subscribe | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 examples/subscribe diff --git a/common.py b/common.py index 3b4d5ba..425a7e1 100644 --- a/common.py +++ b/common.py @@ -56,6 +56,11 @@ class HumbugAPI(): def get_subscriptions(self, request = {}): return self.do_api_query(request, "/api/v1/get_subscriptions") + def subscribe(self, streams): + request = {} + request["streams"] = simplejson.dumps(streams) + return self.do_api_query(request, "/api/v1/subscribe") + def call_on_each_message(self, callback, options = {}): max_message_id = None while True: diff --git a/examples/subscribe b/examples/subscribe new file mode 100644 index 0000000..0615fcd --- /dev/null +++ b/examples/subscribe @@ -0,0 +1,41 @@ +#!/usr/bin/python +import sys +import os +import optparse + +usage = """subscribe --user= [options] --streams= + +Ensures the user is subscribed to the listed streams. + +Example: subscribe --user=tabbott@humbughq.com --site=http://127.0.0.1:8000 +""" +parser = optparse.OptionParser(usage=usage) +parser.add_option('--site', + dest='site', + default="https://app.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.subscribe(options.streams.split())