I propose adding client APIs in multiple languages that wrap the details
of making the HTTP request to the hookbox server.
Here is an example of how it could be used in Python:
--------------------------------------------------------------
import hookbox
server_ip, server_port = '127.0.0.1', 50000
client = hookbox.Client(server_ip, server_port)
channel_data = { "channel_name": "foo", "security_token": "bar":
"payload": "baz" }
response = client.publish(channel_data)
if response[0] == True:
log.info("publish on channel foo succeeded.")
else:
log.info("publish on channel foo failed.")
----------------------------------------------------------------
Here is a snippet that shows how this client class would be implemented:
----------------------------------------------------------------
class Client (object):
""" Hookbox REST api client.
"""
def __init__ (self, server_ip, server_port):
""" Open an HTTP connection to the hookbox server.
"""
self.conn = httplib.HTTPConnection(server_ip, server_port)
def publish (self, data):
""" POST the channel data dictionary to the server.
"""
enc_data = urllib.urlencode(data)
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"}
self.conn.request('POST', '/web/publish', enc_data, headers)
resp = self.conn.getresponse()
return resp.read()
----------------------------------------------------------------
I already have this almost ready to go for Python and can quickly add
something like this for Ruby and a few other languages. Additionally, in
Python I can add Twisted, Eventlet, and gevent versions of the client so
it can be integrated easily with whatever framework your Python
application happens to be using.
I have found it tremendously useful to work with. Let me know if other
developers have better ideas.
Thanks,
Salman