def request_handler(url, request, jwt_secure, parameter): query = request.query_string service_url = url_processor(url, query, parameter) data, files = data_processor(request) is_authorize, auth_header = authentication_handler(request, jwt_secure) is_save = request_validation(request, url) headers = {'Authorization': auth_header} if is_save and is_authorize: try: response = REQUEST_METHOD[request.method](service_url, data=data, files=files, headers=headers) try: return { "data": response.json(), "status_code": response.status_code } except: return {"data": "OK", "status_code": response.status_code} except Exception as error: print(str(error)) raise falcon.HTTPGatewayTimeout(title="Service Error", description=str(error))
def on_put(self, req, resp, target_name, command_name): value = req.get_param("value") blaster_attr = req.get_param("blaster_attr") blaster_value = req.get_param("blaster_value") target = get_target(target_name) if value: target.put_command(command_name, value) else: if blaster_attr is None or blaster_value is None: raise falcon.HTTPBadRequest( description= "If attempting to learn a command, you must specify blaster_attr of ip, mac, or name and corresponding blaster_value. You can also specify the IR sequence directly with the value parameter" ) else: blaster = get_blaster(blaster_attr, blaster_value) value = blaster.get_command() if value: target.put_command(command_name, value) else: raise falcon.HTTPGatewayTimeout( description= "Blaster did not receive any IR signals to learn")
def on_get(self, req, resp, attr, value): if not get_blaster(attr, value).available(): raise falcon.HTTPGatewayTimeout( "Blaster with attribute '" + attr + "' of value '" + value + "' did not respond to availability check within timeout window" )