rename api helper
This commit is contained in:
parent
0433e71560
commit
c28c4a00b7
@ -4,7 +4,7 @@ import unescape from require "lapis.util"
|
|||||||
|
|
||||||
import APIKeys, Users, Tasks from require "models"
|
import APIKeys, Users, Tasks from require "models"
|
||||||
import locate from require "locator"
|
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 random from locate "calc"
|
||||||
-- import escape_similar_to from locate "db"
|
-- import escape_similar_to from locate "db"
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ class API extends Application
|
|||||||
@path: "/v1"
|
@path: "/v1"
|
||||||
@name: "api_"
|
@name: "api_"
|
||||||
|
|
||||||
@before_filter( api_request =>
|
@before_filter( request =>
|
||||||
return if @user
|
return if @user
|
||||||
if auth = @req.headers["authorization"]
|
if auth = @req.headers["authorization"]
|
||||||
if auth\len! > 0
|
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!)
|
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
|
switch @params.action
|
||||||
when "new"
|
when "new"
|
||||||
unless @params.content or tonumber @params.id
|
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, {
|
assert_valid @params, {
|
||||||
{"count", exists: true, is_integer: true, optional: true, "Count is not an integer."}
|
{"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."}
|
{"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, {
|
-- assert_valid @params, {
|
||||||
-- {"count", exists: true, is_integer: true, optional: true, "Count is not an integer."}
|
-- {"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."}
|
-- {"done", exists: true, one_of: {true, false}, optional: true, "Done is not a boolean."}
|
||||||
@ -146,11 +146,11 @@ class API extends Application
|
|||||||
-- else
|
-- else
|
||||||
-- abort!
|
-- abort!
|
||||||
|
|
||||||
[new_key: "/key/new"]: api_request =>
|
[new_key: "/key/new"]: request =>
|
||||||
api_key = assert_model APIKeys\create(@user)
|
api_key = assert_model APIKeys\create(@user)
|
||||||
return json: { success: true, :api_key }
|
return json: { success: true, :api_key }
|
||||||
|
|
||||||
[delete_key: "/key/delete(/:key)"]: api_request =>
|
[delete_key: "/key/delete(/:key)"]: request =>
|
||||||
if @params.id
|
if @params.id
|
||||||
abort "api_key IDs do not exist anymore (sorry!)." -- no one should ever run into this
|
abort "api_key IDs do not exist anymore (sorry!)." -- no one should ever run into this
|
||||||
elseif @params.key
|
elseif @params.key
|
||||||
|
@ -2,7 +2,7 @@ import json_params, capture_errors, yield_error from require "lapis.application"
|
|||||||
import insert, remove from table
|
import insert, remove from table
|
||||||
import max from math
|
import max from math
|
||||||
|
|
||||||
api_request = (fn) ->
|
request = (fn) ->
|
||||||
json_params capture_errors {
|
json_params capture_errors {
|
||||||
fn,
|
fn,
|
||||||
on_error: =>
|
on_error: =>
|
||||||
@ -28,7 +28,7 @@ assert_model = (result, err) ->
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
{
|
{
|
||||||
:api_request
|
:request
|
||||||
:abort
|
:abort
|
||||||
:assert_model
|
:assert_model
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user