def GET(self): """Add your own key in server config""" web.header('Content-Type', 'application/json') i = web.input(key="") if i.key == server['secret']: db = Db(server['paths']['db']) return db.get('analytics')
def GET (self, version, api, api_id): i = web.input(token=None) web.header('Content-Type', 'application/json') web.header('Access-Control-Allow-Origin', '*') ## Enforce https # TODO: sever SSL_ENABLED flag #if not web.ctx.protocol == "https": # raise web.seeother("/404") ## Only allow verified users # TODO: Standardize errors if not i.token and i.token != server['secret']: return json.dumps({"error": "Unauthorized access, attempt logged"}) return json.dumps({"error": "No data source available"})
def GET(self, src=None, dest=None): web.header('Content-Type', 'application/json') if not(src and dest): return json.dumps({"status": "error", "msg": "required args: src & dest", "code": "400 Bad Request", "exception": "ValueError" }) try: data = phone.directions(src, dest) except : return json.dumps({"status": "error", "msg": "JSON encoding error", "code": "424 Method Failure", "exception": "TypeError" }) return json.dumps({"status": "success", "data": data })
def inner(*args, **kwargs): web.header('Content-Type', 'application/json') return json.dumps(f(*args, **kwargs))
def GET(self): web.header('Content-Type', 'text/xml') return phone.sms("Please enter your current location.")
def GET(self): web.header('Content-Type', 'application/xml') return rss.feed(items_func())
def GET(self): web.header('Content-Type', 'application/json') return db().get('analytics')