diff --git a/applications/api.moon b/applications/api.moon index b5403ec..037b92e 100644 --- a/applications/api.moon +++ b/applications/api.moon @@ -13,12 +13,14 @@ get_task = => {"id", exists: true, min_length: 1, "Attempted to select by task id, but no id specified."} {"id", is_integer: true, "Task id is not an integer."} } - @task = Tasks\find id: @params.id, user_id: @user.id + @task, err = Tasks\find id: @params.id, user_id: @user.id + abort 500, err if err elseif @params.content assert_valid @params, { {"content", exists: true, min_length: 1, "Attempted to select by task content, but no content specified."} } - @task = Tasks\find content: @params.content, user_id: @user.id + @task, err = Tasks\find content: @params.content, user_id: @user.id + abort 500, err if err else abort "Task id or content not specified." @@ -55,8 +57,7 @@ class API extends Application [get: "/get"]: api_request => get_task(@) - -- return json: { success: true, :task } - abort 501, "Not implemented." + return json: { success: true, :task } [do: "/do"]: api_request => get_task(@) @@ -143,12 +144,14 @@ class API extends Application {"id", exists: true, min_length: 1, "Attempted to select by API key id, but no id specified."} {"id", is_integer: true, "API key id is not an integer."} } - @key_to_delete = APIKeys\find id: @params.id, user_id: @user.id + @key_to_delete, err = APIKeys\find id: @params.id, user_id: @user.id + abort 500, err if err elseif @params.key assert_valid @params, { {"key", exists: true, min_length: 32, max_length: 32, "Invalid api_key specified."} } - @key_to_delete = APIKeys\find key: @params.key, user_id: @user.id + @key_to_delete, err = APIKeys\find key: @params.key, user_id: @user.id + abort 500, err if err else abort 400, "No api_key specified." diff --git a/views/docs/v1.moon b/views/docs/v1.moon index c5069f8..9ab84de 100644 --- a/views/docs/v1.moon +++ b/views/docs/v1.moon @@ -32,7 +32,10 @@ class Docs_1 extends Widget a href: "#random", "/random" text " { count: integer, done: boolean }" - style -> raw "h3 { font-family: monospace; }" + style -> raw " + h3 { font-family: monospace; } + .top { font-size: 1.33rem; } + " a name: "top" ol style: "font-family: monospace;", -> @@ -77,7 +80,7 @@ class Docs_1 extends Widget a href: "#errors", "Errors" text " below for more info on that." - a href: "#top", "back to top" + a class: ".top", href: "#top", "back to top" a name: "auth" h2 "Authorization" @@ -98,7 +101,7 @@ class Docs_1 extends Widget a href: @url_for("index"), "the web interface" text " to get started. You can also delete existing API keys there." - a href: "#top", "back to top" + a class: ".top", href: "#top", "back to top" a name: "tasks" h2 "Tasks" @@ -129,7 +132,7 @@ class Docs_1 extends Widget task_list! - a href: "#top", "back to top" + a class: ".top", href: "#top", "back to top" a name: "new" h3 "/new" @@ -148,7 +151,7 @@ class Docs_1 extends Widget code "/random" text "." - a href: "#top", "back to top" + a class: ".top", href: "#top", "back to top" a name: "get" h3 "/get" @@ -167,7 +170,7 @@ class Docs_1 extends Widget a href: "#new", "/new" text " for an example response." - a href: "#top", "back to top" + a class: ".top", href: "#top", "back to top" a name: "do" h3 "/do" @@ -181,7 +184,7 @@ class Docs_1 extends Widget a href: "#new", "/new" text " for an example response." - a href: "#top", "back to top" + a class: ".top", href: "#top", "back to top" a name: "undo" h3 "/undo" @@ -190,7 +193,7 @@ class Docs_1 extends Widget a href: "#new", "/new" text " for an example response." - a href: "#top", "back to top" + a class: ".top", href: "#top", "back to top" a name: "delete" h3 "/delete" @@ -199,7 +202,7 @@ class Docs_1 extends Widget code '{ "success": true }' text " if successful." - a href: "#top", "back to top" + a class: ".top", href: "#top", "back to top" a name: "list" h3 "/list" @@ -244,30 +247,67 @@ class Docs_1 extends Widget blockquote -> code '{ "success": true, page: 5, pages: 10, tasks: [ /* task list omitted */ ] }' - a href: "#top", "back to top" + a class: ".top", href: "#top", "back to top" a name: "random" h3 "/random" - a href: "#top", "back to top" + p "This is the only endpoint not currently implemented. This documentation will be updated once it is finished." + -- TODO /random { count: #, done: bool } (both args optional, defaults count 1, done false) + + a class: ".top", href: "#top", "back to top" a name: "keys" h2 "API Keys" - a href: "#top", "back to top" + p "The API can be used to request new API keys and delete API keys, but cannot be used to look up API keys, or perform any other actions with API keys." + + a class: ".top", href: "#top", "back to top" a name: "new-key" h3 "/key/new" - a href: "#top", "back to top" + p "Send an empty request. Receive the following:" + + blockquote -> + code '{ "success": true, "api_key": { "id": 4, "user_id": 1, "key": "", "created_at": "2018-04-25 06:05:53", "updated_at": "2018-04-25 06:05:53" } }' + + p "NOTE: For some reason, API key IDs are not being returned with API keys currently." + + a class: ".top", href: "#top", "back to top" a name: "delete-key" h3 "/key/delete" - a href: "#top", "back to top" + p -> + text "Send a POST request with " + code "id" + text " or " + code "key" + text " defined to delete an API key. Note: You can delete the API key you are currently using with this endpoint, so be careful!" + + p -> + text "Returns just the " + code '{ "success": true }' + text " JSON if successful." + + a class: ".top", href: "#top", "back to top" a name: "errors" h2 "Errors" - a href: "#top", "back to top" + p "In addition to an array of errors (usually only consisting of one error message), the HTTP status returned will indicate errors:" + + ul -> + li "400: Bad Request. This means something on the client-side did not call the API correctly." + li "404: Not Found. This means the requested item doesn't exist." + li "500: Internal Server Error. Something went wrong with the server while processing your request." + li -> + text "501: Not Implemented. This error should only exist for the next few hours/days as I finish implementing " + code "/random" + text ", the only part of the API not already implemented." + + p "Right now, please report any 500 errors you encounter. In the future, these will be logged automatically." + + a class: ".top", href: "#top", "back to top" a name: "rate-limit" h2 "Rate Limiting" p "At this time there is no rate limiting. This will be developed when needed, and the API documentation updated to reflect that, with at least 2 months' warning." --- /random { count: #, done: bool } (both args optional, defaults count 1, done false) + a class: ".top", href: "#top", "back to top"