api: Generically convert non-string values to JSON in python bindings

(imported from commit 820bc20d469832b5785b434726c81e59a3f67ea5)
This commit is contained in:
Zev Benjamin 2012-11-07 17:22:19 -05:00
parent c38587191e
commit 18cefd37a8

View file

@ -27,6 +27,11 @@ class HumbugAPI():
request["api-key"] = self.api_key request["api-key"] = self.api_key
request["client"] = self.client_name request["client"] = self.client_name
request["failures"] = 0 request["failures"] = 0
for (key, val) in request.iteritems():
if not (isinstance(val, str) or isinstance(val, unicode)):
request[key] = simplejson.dumps(val)
while True: while True:
try: try:
res = requests.post(urlparse.urljoin(self.base_url, url), data=request, res = requests.post(urlparse.urljoin(self.base_url, url), data=request,
@ -101,8 +106,7 @@ class HumbugAPI():
return self.do_api_query(request, "/api/v1/get_subscriptions") return self.do_api_query(request, "/api/v1/get_subscriptions")
def subscribe(self, streams): def subscribe(self, streams):
request = {} request = {'streams': streams}
request["streams"] = simplejson.dumps(streams)
return self.do_api_query(request, "/api/v1/subscribe") 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 = {}):