Sfoglia il codice sorgente

callback template implementaion

Hal De 4 anni fa
parent
commit
47ac1b3f5f
2 ha cambiato i file con 20 aggiunte e 0 eliminazioni
  1. 16 0
      app/app.py
  2. 4 0
      app/utils.py

+ 16 - 0
app/app.py

@@ -1024,5 +1024,21 @@ class UserCalls(Resource):
                            request.args.get('order', 'ASC'))
     return successReply(cdr)
 
+@app.route('/device/<device>/callback')
+class DeviceCallback(Resource):
+  @authRequired
+  @app.param('device', 'Device to get/set the callback url for', 'path')
+  @app.param('url', 'Callback url', 'query')
+  @app.response(HTTPStatus.OK, 'JSON data {"user":user,"state":state}')
+  @app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
+  async def get(self, device):
+    '''Returns device's callback url.
+    '''
+    if (device != request.device) and (not request.admin):
+      abort(401)
+    if url is None:
+      url = 'http://127.0.0.1:65535/status'
+    return successCallbackURL(device, url)
+
 manager.connect()
 app.run(loop=main_loop, host='0.0.0.0', port=app.config['PORT'])

+ 4 - 0
app/utils.py

@@ -167,3 +167,7 @@ def successfullyUnbound(user, device):
 def successfullySetState(user, state):
   return successReply({'user':user,'state':state},
                       'State "{}" was successfully set for user {}'.format(state, user))
+
+def successCallbackURL(device, url):
+  return successReply({'device':device,'url':url},
+                      'Device {} callback url is: {}'.format(device, url))