Refactor. Move functions that need session back from action.py to
api.py.

api.py is getting really big and I don't know what to do about it. To be
honest, I could probably make it much better if I made it a priority.