diff --git a/applications/api.moon b/applications/api.moon index 2fc8593..01046e8 100644 --- a/applications/api.moon +++ b/applications/api.moon @@ -4,7 +4,7 @@ import unescape from require "lapis.util" import APIKeys, Users, Tasks from require "models" import locate from require "locator" -import api_request, abort, assert_model from locate "helpers.api" +import request, abort, assert_model from locate "helpers.api" -- import random from locate "calc" -- import escape_similar_to from locate "db" @@ -43,7 +43,7 @@ class API extends Application @path: "/v1" @name: "api_" - @before_filter( api_request => + @before_filter( request => return if @user if auth = @req.headers["authorization"] if auth\len! > 0 @@ -55,7 +55,7 @@ class API extends Application abort "Auth: Invalid api_key." unless @user -- NOTE this should also delete the api_key and error (this should never happen!) ) - [action: "/:action(/:id)"]: api_request => + [action: "/:action(/:id)"]: request => switch @params.action when "new" unless @params.content or tonumber @params.id @@ -89,7 +89,7 @@ class API extends Application - [list: "/list"]: api_request => + [list: "/list"]: request => assert_valid @params, { {"count", exists: true, is_integer: true, optional: true, "Count is not an integer."} {"done", exists: true, one_of: {true, false}, optional: true, "Done is not a boolean."} @@ -120,7 +120,7 @@ class API extends Application - [random: "/random"]: api_request => + [random: "/random"]: request => -- assert_valid @params, { -- {"count", exists: true, is_integer: true, optional: true, "Count is not an integer."} -- {"done", exists: true, one_of: {true, false}, optional: true, "Done is not a boolean."} @@ -146,11 +146,11 @@ class API extends Application -- else -- abort! - [new_key: "/key/new"]: api_request => + [new_key: "/key/new"]: request => api_key = assert_model APIKeys\create(@user) return json: { success: true, :api_key } - [delete_key: "/key/delete(/:key)"]: api_request => + [delete_key: "/key/delete(/:key)"]: request => if @params.id abort "api_key IDs do not exist anymore (sorry!)." -- no one should ever run into this elseif @params.key diff --git a/helpers/api.moon b/helpers/api.moon index 4395bf0..1552451 100644 --- a/helpers/api.moon +++ b/helpers/api.moon @@ -2,7 +2,7 @@ import json_params, capture_errors, yield_error from require "lapis.application" import insert, remove from table import max from math -api_request = (fn) -> +request = (fn) -> json_params capture_errors { fn, on_error: => @@ -28,7 +28,7 @@ assert_model = (result, err) -> return result { - :api_request + :request :abort :assert_model }