Add an API call to subscribe to a list of streams.

(imported from commit 0a5d46d5f54fb4c8ebfad8c9adb777c0b4938dfa)
This commit is contained in:
Tim Abbott 2012-10-11 15:34:17 -04:00
parent 717186a149
commit 60464f7976
2 changed files with 46 additions and 0 deletions

View file

@ -56,6 +56,11 @@ class HumbugAPI():
def get_subscriptions(self, request = {}): def get_subscriptions(self, request = {}):
return self.do_api_query(request, "/api/v1/get_subscriptions") 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 = {}): def call_on_each_message(self, callback, options = {}):
max_message_id = None max_message_id = None
while True: while True:

41
examples/subscribe Normal file
View file

@ -0,0 +1,41 @@
#!/usr/bin/python
import sys
import os
import optparse
usage = """subscribe --user=<email address> [options] --streams=<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())