simplex/applications/api.moon

41 lines
1.3 KiB
Plaintext
Raw Normal View History

2018-04-23 12:00:42 +00:00
import Application from require "lapis"
import json_params, capture_errors_json, yield_error, assert_valid from require "lapis.application"
-- import assert_valid from require "lapis.validate"
--
import APIKeys, Tasks from require "models"
-- import Keys, Tasks from require "models"
-- import locate from require "locator"
-- import random from locate "calc"
-- import escape_similar_to from locate "db"
class API extends Application
@path: "/v1"
@name: "api_"
@before_filter( capture_errors_json json_params =>
@api_key = APIKeys\find key: @params.api_key
yield_error "api_key not specified!" unless @api_key
)
[new: "/new"]: =>
assert_valid @params, {
{"content", exists: true, min_length: 1, "Task content not specified."}
}
task, err = Tasks\create {
user_id: @api_key.user_id
content: @params.content
}
yield_error err unless task
return json: { success: true, :task }
-- /new { content: "string" }
-- /do { id: #
-- /undo { id: # }
-- /get { id: # }
-- /random { count: #, done: bool } (both args optional, defaults count 1, done false)
-- /list { count: #, done: bool, page: #, order: asc/desc } (if done not specified, returns all, default count is 50, default page is 1, default order is latest first
--
-- Add ability to send out subscription webhooks.