2018-04-25 05:02:41 +00:00
|
|
|
import Widget from require "lapis.html"
|
|
|
|
|
|
|
|
class Docs_1 extends Widget
|
|
|
|
content: =>
|
|
|
|
task_list = ->
|
|
|
|
ul ->
|
|
|
|
li ->
|
2018-04-25 05:20:16 +00:00
|
|
|
a href: "#new", "/v1/new"
|
2018-04-25 05:02:41 +00:00
|
|
|
text " { content: string }"
|
|
|
|
li ->
|
2018-04-25 05:20:16 +00:00
|
|
|
a href: "#get", "/v1/get"
|
2018-04-25 05:02:41 +00:00
|
|
|
text " { id: integer, content: string }"
|
|
|
|
li ->
|
2018-04-25 05:20:16 +00:00
|
|
|
a href: "#do", "/v1/do"
|
2018-04-25 05:02:41 +00:00
|
|
|
text " { id: integer, content: string }"
|
|
|
|
li ->
|
2018-04-25 05:20:16 +00:00
|
|
|
a href: "#undo", "/v1/undo"
|
2018-04-25 05:02:41 +00:00
|
|
|
text " { id: integer, content: string }"
|
|
|
|
li ->
|
2018-04-25 05:20:16 +00:00
|
|
|
a href: "#delete", "/v1/delete"
|
2018-04-25 05:02:41 +00:00
|
|
|
text " { id: integer, content: string }"
|
|
|
|
li ->
|
2018-04-25 05:20:16 +00:00
|
|
|
a href: "#list", "/v1/list"
|
2018-04-25 05:02:41 +00:00
|
|
|
text " { count: integer, done: boolean, page: integer, order: 'asc'/'desc' }"
|
|
|
|
li ->
|
2018-04-25 05:20:16 +00:00
|
|
|
a href: "#random", "/v1/random"
|
2018-04-25 05:02:41 +00:00
|
|
|
text " { count: integer, done: boolean }"
|
|
|
|
|
|
|
|
style -> raw "h3 { font-family: monospace; }"
|
|
|
|
|
|
|
|
ol style: "font-family: monospace;", ->
|
|
|
|
li ->
|
|
|
|
a href: "#auth", "Authorization"
|
|
|
|
li ->
|
|
|
|
a href: "#tasks", "Tasks"
|
|
|
|
task_list!
|
|
|
|
li ->
|
|
|
|
a href: "#keys", "API Keys"
|
|
|
|
ul ->
|
|
|
|
li ->
|
2018-04-25 05:20:16 +00:00
|
|
|
a href: "#new-key", "/v1/key/new"
|
2018-04-25 05:02:41 +00:00
|
|
|
li ->
|
2018-04-25 05:20:16 +00:00
|
|
|
a href: "#delete-key", "/v1/key/delete"
|
2018-04-25 05:02:41 +00:00
|
|
|
text " { id: integer, key: string }"
|
|
|
|
|
|
|
|
a name: "auth"
|
|
|
|
h2 "Authorization"
|
|
|
|
|
|
|
|
p "Authorization is done using a session cookie on the web interface, or an API key sent along with API requests."
|
|
|
|
p ->
|
|
|
|
text "API keys can be sent in an Authorization header or as an "
|
|
|
|
code "api_key"
|
|
|
|
text " field in JSON."
|
|
|
|
|
|
|
|
blockquote ->
|
|
|
|
code "Authorization: JDJiJDEyJFRPaG0wOW16VXhoUTd3dElB"
|
|
|
|
|
|
|
|
blockquote ->
|
|
|
|
code '{ "api_key": "JDJiJDEyJFRPaG0wOW16VXhoUTd3dElB" }'
|
|
|
|
|
|
|
|
p ->
|
|
|
|
text "Grab an API key from "
|
|
|
|
a href: @url_for("index"), "the web interface"
|
|
|
|
text " to get started. You can also delete existing API keys there."
|
|
|
|
|
|
|
|
a name: "tasks"
|
|
|
|
h2 "Tasks"
|
|
|
|
|
|
|
|
p ->
|
|
|
|
text "Version 1 of this API is extremely simple. POST "
|
|
|
|
code '{ "content": "this is a todo item" }'
|
|
|
|
text " with valid authorization to "
|
2018-04-25 05:20:16 +00:00
|
|
|
code "/v1/new"
|
2018-04-25 05:02:41 +00:00
|
|
|
text " to add tasks. The next four endpoints ("
|
2018-04-25 05:20:16 +00:00
|
|
|
code "/v1/get"
|
2018-04-25 05:02:41 +00:00
|
|
|
text ","
|
2018-04-25 05:20:16 +00:00
|
|
|
code "/v1/do"
|
2018-04-25 05:02:41 +00:00
|
|
|
text ","
|
2018-04-25 05:20:16 +00:00
|
|
|
code "/v1/undo"
|
2018-04-25 05:02:41 +00:00
|
|
|
text ","
|
2018-04-25 05:20:16 +00:00
|
|
|
code "/v1/delete"
|
2018-04-25 05:02:41 +00:00
|
|
|
text ") all use the same input to complete their operations (an "
|
|
|
|
code "id"
|
|
|
|
text " integer or "
|
|
|
|
code "content"
|
|
|
|
text " boolean)."
|
|
|
|
|
|
|
|
p ->
|
2018-04-25 05:20:16 +00:00
|
|
|
code "/v1/list"
|
2018-04-25 05:02:41 +00:00
|
|
|
text " and "
|
2018-04-25 05:20:16 +00:00
|
|
|
code "/v1/random"
|
2018-04-25 05:02:41 +00:00
|
|
|
text " are a little more complex, and explained further below."
|
|
|
|
|
|
|
|
task_list!
|
|
|
|
|
|
|
|
a name: "new"
|
2018-04-25 05:20:16 +00:00
|
|
|
h3 "/v1/new"
|
|
|
|
|
|
|
|
p ->
|
|
|
|
text "As stated above, just POST a "
|
|
|
|
code "content"
|
|
|
|
text " string with valid authorization and a task item will be returned. Here's an example item:"
|
|
|
|
|
|
|
|
blockquote ->
|
|
|
|
code '{ "id": 4, "user_id": 2, "content": "Get a new API key.", "done": false, "created_at": "", "updated_at": "" }'
|
|
|
|
|
|
|
|
|
|
|
|
-- "id", types.serial primary_key: true}
|
|
|
|
-- {"user_id", types.foreign_key}
|
|
|
|
-- {"content", types.text}
|
|
|
|
-- {"done", types.boolean default: false}
|
|
|
|
--
|
|
|
|
-- {"created_at", types.time}
|
|
|
|
-- {"updated_at", types.time}
|
2018-04-25 05:02:41 +00:00
|
|
|
|
|
|
|
a name: "get"
|
2018-04-25 05:20:16 +00:00
|
|
|
h3 "/v1/get"
|
2018-04-25 05:02:41 +00:00
|
|
|
|
|
|
|
a name: "do"
|
2018-04-25 05:20:16 +00:00
|
|
|
h3 "/v1/do"
|
2018-04-25 05:02:41 +00:00
|
|
|
|
|
|
|
a name: "undo"
|
2018-04-25 05:20:16 +00:00
|
|
|
h3 "/v1/undo"
|
2018-04-25 05:02:41 +00:00
|
|
|
|
|
|
|
a name: "delete"
|
2018-04-25 05:20:16 +00:00
|
|
|
h3 "/v1/delete"
|
2018-04-25 05:02:41 +00:00
|
|
|
|
|
|
|
a name: "list"
|
2018-04-25 05:20:16 +00:00
|
|
|
h3 "/v1/list"
|
2018-04-25 05:02:41 +00:00
|
|
|
|
|
|
|
a name: "random"
|
2018-04-25 05:20:16 +00:00
|
|
|
h3 "/v1/random"
|
2018-04-25 05:02:41 +00:00
|
|
|
|
|
|
|
a name: "keys"
|
|
|
|
h2 "API Keys"
|
|
|
|
|
|
|
|
a name: "new-key"
|
2018-04-25 05:20:16 +00:00
|
|
|
h3 "/v1/key/new"
|
2018-04-25 05:02:41 +00:00
|
|
|
|
|
|
|
a name: "delete-key"
|
2018-04-25 05:20:16 +00:00
|
|
|
h3 "/v1/key/delete"
|
2018-04-25 05:02:41 +00:00
|
|
|
|
|
|
|
-- /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
|
2018-04-25 05:20:16 +00:00
|
|
|
-- also returns page: #, pages: #, tasks: []
|
2018-04-25 05:02:41 +00:00
|
|
|
-- /random { count: #, done: bool } (both args optional, defaults count 1, done false)
|