def put_head(request): storage = get_storage(request) userid = request.matchdict["userid"] new_head = json.loads(request.body)["head"] storage.set_head(userid, new_head) request.response.status = 204 return request.response
def put_chunk(request): storage = get_storage(request) userid = request.matchdict["userid"] chunk = request.matchdict["chunk"] storage.create_chunk(userid, chunk, request.body) request.response.status = 201 return request.response
def put_transaction(request): storage = get_storage(request) userid = request.matchdict["userid"] trnid = request.matchdict["transaction"] params = json.loads(request.body) parent = params["parent"] chunks = params["chunks"] storage.create_transaction(userid, trnid, parent, chunks) request.response.status = 201 return request.response
def get_transactions(request): storage = get_storage(request) userid = request.matchdict["userid"] frm = request.GET.get("from", ROOT_TRANSACTION) limit = int(request.GET.get("limit", "100")) return { "from": frm, "limit": limit, "transactions": list(storage.get_transactions(userid, frm, limit)), }
def get_transaction(request): storage = get_storage(request) userid = request.matchdict["userid"] trnid = request.matchdict["transaction"] trn = storage.get_transaction(userid, trnid) return { "id": trn["id"], "seq": trn["seq"], "parent": trn["parent"], "chunks": trn["chunks"] }
def delete_root(request): storage = get_storage(request) userid = request.matchdict["userid"] storage.reset(userid) request.response.status = 204 return request.response
def get_chunk(request): storage = get_storage(request) userid = request.matchdict["userid"] chunk = request.matchdict["chunk"] payload = storage.get_chunk(userid, chunk) return Response(payload)
def get_head(request): storage = get_storage(request) userid = request.matchdict["userid"] return {"head": storage.get_head(userid)}