- poster.streaminghttp.register_openers()
-
- # send request to WL
- http = httplib2.Http()
- http.add_credentials("test", "test")
- http.follow_all_redirects = True
- datagen, headers = poster.encode.multipart_encode({name: document.plain_text})
-
- for key, value in headers.items():
- headers[key] = unicode(value)
-
- try:
- resp, data = http.request("http://localhost:8000/api/books.json",
- method = "POST", body = ''.join(datagen), headers = headers)
-
- print resp, data
-
- if resp.status == 201: # success
- result = {"success": True}
- else:
- result = {"success": False, "errno": resp.status, "reason": resp.reason}
- except Exception, e:
- result = {"success": False, "errno": 500, "reason": unicode(e)}
+ api = wlapi.WLAPI(settings.WL_API_CONFIG)
+ try:
+ result = {"success": True, "result": api.publish_book(document)}
+ except wlapi.APICallException, e:
+ result = {"success": False, "reason": str(e)}