Streaming API¶
Redshelf operates a streaming API which provides updates from our dynamic pricing system. Please contact support if you’re interested in using a push stream.
Subscribe Method¶
To use the response body subscription method make a streaming request to the following URL: http://pubsub.redshelf.com:9080/sub/pricing/
Long Polling Method¶
To use the HTTP long polling method make a streaming request to the following URL: http://pubsub.redshelf.com:9080/lp/pricing/
JSONP Method¶
To use the JSONP method make a streaming request to the following URL: http://pubsub.redshelf.com:9080/jsonp/pricing/
Websockets Method¶
To use the websockets method make a streaming request to the following URL: http://pubsub.redshelf.com:9080/ws/pricing/
Example Message¶
Example pricing message:
{ "id":6, "channel":"pricing", "data":{ "book": "ccc5a093f5ee30ec749e4909840f0f7b794066bb", "isbn": "123456789012", "id": 123, "new_price": 6.42, "limit_days": 180 }, "tag":"1", "time":"Thu, 05 Jun 2014 20:39:31 GMT", }
Example Long Polling Script¶
This script provides a basic example of making long polling requests via requests. It may not be ideal for production systems:
import simplejson import requests s = requests.Session() def streaming(): headers = {'connection': 'keep-alive', 'content-type': 'application/json', 'transfer-encoding': 'chunked'} req = requests.Request("GET", 'http://pubsub.redshelf.com:9080/lp/pricing/', headers=headers).prepare() resp = s.send(req, stream=True) for line in resp.iter_lines(): if line: yield line def read_stream(): for line in streaming(): print line while 1: try: print simplejson.loads(read_stream()) except TypeError: continue