diff idavoll/gateway.py @ 191:48245777acea

Return proper HTTP status codes on failed un-/subscription.
author Ralph Meijer <ralphm@ik.nu>
date Sat, 17 May 2008 18:31:31 +0000
parents 69cdd8c6a431
children e404775b12df
line wrap: on
line diff
--- a/idavoll/gateway.py	Sat May 17 18:30:39 2008 +0000
+++ b/idavoll/gateway.py	Sat May 17 18:31:31 2008 +0000
@@ -491,6 +491,12 @@
                          request to this resource.
     """
     serviceMethod = None
+    errorMap = {
+            error.NodeNotFound:
+                (responsecode.FORBIDDEN, "Node not found"),
+            error.NotSubscribed:
+                (responsecode.FORBIDDEN, "No such subscription found"),
+    }
 
     def __init__(self, service):
         self.service = service
@@ -502,9 +508,9 @@
 
     def http_POST(self, request):
         def trapNotFound(failure):
-            failure.trap(error.NodeNotFound)
-            return http.StatusResponse(responsecode.NOT_FOUND,
-                                       "Node not found")
+            err = failure.trap(*self.errorMap.keys())
+            code, msg = self.errorMap[err]
+            return http.StatusResponse(code, msg)
 
         def respond(result):
             return http.Response(responsecode.NO_CONTENT)
@@ -734,6 +740,18 @@
         return f.deferred
 
 
+    def unsubscribe(self, xmppURI):
+        params = {'uri': xmppURI,
+                  'callback': 'http://%s:%s/callback' % (self.callbackHost,
+                                                         self.callbackPort)}
+        f = getPageWithFactory(self._makeURI('unsubscribe'),
+                    method='POST',
+                    postdata=simplejson.dumps(params),
+                    headers={'Content-Type': MIME_JSON},
+                    agent=self.agent)
+        return f.deferred
+
+
     def items(self, xmppURI, maxItems=None):
         query = {'uri': xmppURI}
         if maxItems: