bbj/src/schema.py

118 lines
2.8 KiB
Python
Raw Normal View History

2017-03-01 16:59:33 +00:00
def base():
return {
"error": False
}
2017-04-02 07:35:58 +00:00
def response(dictionary):
2017-03-01 16:59:33 +00:00
result = base()
result.update(dictionary)
return result
def error(code, description):
result = base()
result.update({
"error": {
2017-03-03 06:08:32 +00:00
"description": description, # string
"code": code # integer
2017-03-01 16:59:33 +00:00
}
})
return result
2017-04-02 07:35:58 +00:00
def user_internal(
user_id, # string (uuid1)
user_name, # string
auth_hash, # string (sha256 hash)
quip, # string (possibly empty)
bio, # string (possibly empty)
color, # int from 0 to 8
is_admin, # bool (supply as either False/True or 0/1)
created): # floating point unix timestamp (when user registered)
2017-03-06 00:03:58 +00:00
if not quip:
quip = ""
if not bio:
2017-03-06 00:30:18 +00:00
bio = ""
2017-03-06 00:03:58 +00:00
2017-04-02 07:35:58 +00:00
if not color:
color = 0
2017-03-01 16:59:33 +00:00
return {
2017-04-02 07:35:58 +00:00
"user_id": user_id,
"user_name": user_name,
"auth_hash": auth_hash,
"quip": quip,
"bio": bio,
"color": color,
"is_admin": bool(is_admin),
"created": created
2017-03-01 16:59:33 +00:00
}
2017-04-02 07:35:58 +00:00
def user_external(
user_id, # string (uuid1)
user_name, # string
quip, # string (possibly empty)
bio, # string (possibly empty)
color, # int from 0 to 8
admin, # bool (can be supplied as False/True or 0/1)
created): # floating point unix timestamp (when user registered)
2017-03-06 00:03:58 +00:00
if not quip:
quip = ""
if not bio:
2017-03-06 00:30:18 +00:00
bio = ""
2017-03-06 00:03:58 +00:00
2017-04-02 07:35:58 +00:00
if not color:
color = 0
2017-03-01 16:59:33 +00:00
return {
2017-04-02 07:35:58 +00:00
"user_id": user_id,
"user_name": user_name,
"quip": quip,
"bio": bio,
"color": color,
"is_admin": admin,
"created": created
2017-03-01 16:59:33 +00:00
}
2017-04-02 07:35:58 +00:00
def thread(
thread_id, # uuid string
author, # string (uuid1, user.user_id)
title, # string
last_mod, # floating point unix timestamp (of last post or post edit)
created, # floating point unix timestamp (when thread was made)
reply_count): # integer (incremental, starting with 0)
2017-03-06 00:03:58 +00:00
2017-03-01 16:59:33 +00:00
return {
2017-04-02 07:35:58 +00:00
"thread_id": thread_id,
"author": author,
"title": title,
"last_mod": last_mod,
"created": created,
"reply_count": reply_count,
2017-03-01 16:59:33 +00:00
}
2017-04-02 07:35:58 +00:00
def message(
thread_id, # string (uuid1 of parent thread)
post_id, # integer (incrementing from 1)
author, # string (uuid1, user.user_id)
created, # floating point unix timestamp (when reply was posted)
edited, # bool
body): # string
2017-03-06 00:03:58 +00:00
2017-03-01 16:59:33 +00:00
return {
2017-04-02 07:35:58 +00:00
"thread_id": thread_id,
"post_id": post_id,
"author": author,
"created": created,
"edited": bool(edited),
"body": body
2017-03-01 16:59:33 +00:00
}