diff options
author | Colin Okay <colin@cicadas.surf> | 2022-08-23 20:16:42 -0500 |
---|---|---|
committer | Colin Okay <colin@cicadas.surf> | 2022-08-23 20:16:42 -0500 |
commit | 5a16537d72931db14ca9f7a67c7b8def7d3f51bb (patch) | |
tree | 84c551fd2f5ad0e11228b68d50dd71676e4dbc5a | |
parent | a371f89f8fefa20a823ce77e1c6a9ffc4a2f5cfd (diff) |
[add] new generated api client code; updated client.lisp
-rw-r--r-- | lib/client.lisp | 141 | ||||
-rw-r--r-- | lib/state.lisp | 9 | ||||
-rw-r--r-- | oneliners.api-client.lisp | 552 |
3 files changed, 216 insertions, 486 deletions
diff --git a/lib/client.lisp b/lib/client.lisp index ae5534f..a526b5c 100644 --- a/lib/client.lisp +++ b/lib/client.lisp @@ -30,11 +30,10 @@ (defun search-for-oneliners (terms limit &optional not-flagged-p all-flagged-p newestp) (assert (loop for term in terms never (find #\, term)) () "Search terms may not contain commas.") (let ((json - (api:get--oneliners :tags (str:join "," terms) - :limit limit - :notflagged (true-or-false not-flagged-p) - :newest (true-or-false newestp) - :onlyflagged (true-or-false all-flagged-p)))) + (api:get-oneliners (str:join "," terms) + limit + not-flagged-p + *host*))) (cache-and-print-search-response json))) (defun the-oneliner (name-or-id) @@ -42,7 +41,7 @@ not in the local cache, try to fetch from configured server." (a:if-let ((ol (get-cached name-or-id))) ol - (let ((ol (jonathan:parse (api:get--oneliner-entry name-or-id)))) + (let ((ol (jonathan:parse (api:get-oneliner/entry name-or-id *host*)))) (merge-oneliners (list ol)) ol))) @@ -63,16 +62,12 @@ running the body. If such a oneliner can be found." (defun newest-oneliners (&optional limit) (let ((response - (if limit - (api:get--oneliners-newest :limit limit) - (api:get--oneliners-newest)))) + (api:get-oneliners/newest (or limit 10) *host*))) (cache-and-print-search-response response))) (defun all-flagged-oneliners (&optional limit) (let ((response - (if limit - (api:get--oneliners-all-flagged :limit limit) - (api:get--oneliners-all-flagged)))) + (api:get-oneliners/all-flagged (or limit 10) *host*))) (cache-and-print-search-response response))) (defun print-item-explanation (name-or-number) @@ -95,16 +90,15 @@ running the body. If such a oneliner can be found." (format t "Draft Name: ~a~%" (first draft)) (print-oneliner-result-for-user (rest draft))))) -;;; RUNNING ONELINERS +;; ;;; running ONELINERS (defvar *ol-output-timeout* 1) -(defun run-item (ident args &key force-clip (timeout nil timeout-p) draftp verbose confirm) - "Runs a oneliner identified by IDENT (if available) with arguments ARGS." - (let ((ol (if draftp (fetch-draft ident) (the-oneliner ident)))) - (when ol - (let ((*ol-output-timeout* (if timeout-p timeout *ol-output-timeout*))) - (bind-vars-and-run-oneliner ol args force-clip verbose confirm))))) +(defun handle-run-oneliner (ol &optional clip) + (if clip + (progn (trivial-clipboard:text ol) + (format t "Copied oneliner to clipboard~%")) + (run-with-shell ol :shell-name (or (shell) "bash") :await-output-p *ol-output-timeout*))) (defun bind-vars-and-run-oneliner (ol args &optional force-clip verbose confirm) (let* ((oneliner (oneliner-oneliner ol)) @@ -137,11 +131,13 @@ running the body. If such a oneliner can be found." (y-or-n-p "Proceed?")) (handle-run-oneliner oneliner (or force-clip (equalp runstyle "manual"))))))) -(defun handle-run-oneliner (ol &optional clip) - (if clip - (progn (trivial-clipboard:text ol) - (format t "Copied oneliner to clipboard~%")) - (run-with-shell ol :shell-name (or (shell) "bash") :await-output-p *ol-output-timeout*))) +(defun run-item (ident args &key force-clip (timeout nil timeout-p) draftp verbose confirm) + "Runs a oneliner identified by IDENT (if available) with arguments ARGS." + (let ((ol (if draftp (fetch-draft ident) (the-oneliner ident)))) + (when ol + (let ((*ol-output-timeout* (if timeout-p timeout *ol-output-timeout*))) + (bind-vars-and-run-oneliner ol args force-clip verbose confirm))))) + ;;; ADDING ONELINERS @@ -271,62 +267,50 @@ running the body. If such a oneliner can be found." (defun publish-draft (name) (when-draft (ol name) - (api:request-with - (:body (oneliner-to-json-body ol) - :content-type "application/json") - (let ((updated - (jonathan:parse (if (oneliner-id ol) - (api:patch--oneliner-entry-edit (oneliner-id ol) :token (api-token)) - (api:post--oneliner :token (api-token)))))) - (merge-oneliners (list updated)) - (drop-draft name) - (format t "Draft ~a published and removed from drafts.~%" name))))) - - -;;; ADMIN OF ONELINER ENTRIES + (let ((updated + (jonathan:parse + (a:if-let (id (oneliner-id ol)) + (api:patch-oneliner/entry/edit id (api-token) *host* + :%content-type "application/json" + :%body (oneliner-to-json-body ol)) + (api:post-oneliner (api-token) *host* + :%content-type "application/json" + :%body (oneliner-to-json-body ol)))))) + (merge-oneliners (list updated)) + (drop-draft name) + (format t "Draft ~a published and removed from drafts.~%" name)))) + + +;; ;;; ADMIN OF ONELINER ENTRIES (defun delete-item (ident) (when-oneliner (ol ident) - (api:delete--oneliner-oneliner - ident - :token (api-token)) + (api:delete-oneliner/oneliner ident (api-token) *host*) ;; if we've made it this far no http error has been returned, ;; hence we can delete it from the cache (remove-from-cache ident))) (defun flag-item (ident) (when-oneliner (ol ident) - (api:put--oneliner-entry-flag - ident - :token (api-token) - :value "true") + (api:put-oneliner/entry/flag ident (api-token) "true" *host*) ;; no http error, so we flag the cached version, ol. (setf (oneliner-isflagged ol) t))) (defun unflag-item (ident) (when-oneliner (ol ident) - (api:put--oneliner-entry-flag - ident - :token (api-token) - :value "false") + (api:put-oneliner/entry/flag ident (api-token) "false" *host*) ;; no http error, so we can unflag the cached version, ol (setf (oneliner-isflagged ol) nil))) (defun lock-item (ident) (when-oneliner (ol ident) - (api:put--oneliner-oneliner-locked - ident - :token (api-token) - :value "true") + (api:put-oneliner/oneliner/locked ident (api-token) "true" *host*) ;; no http error, so we can lock the cached version, ol (setf (oneliner-islocked ol) t))) (defun unlock-item (ident) (when-oneliner (ol ident) - (api:put--oneliner-oneliner-locked - ident - :token (api-token) - :value "false") + (api:put-oneliner/oneliner/locked ident (api-token) "false" *host*) ;; no http error, so we can unlock the cached version, ol (setf (oneliner-islocked ol) nil))) @@ -334,7 +318,9 @@ running the body. If such a oneliner can be found." ;;; ACCOUNT AND INVITE STUFF (defun request-invite-code () - (let ((invite (jonathan:parse (api:post--invite :token (api-token))))) + (let ((invite + (jonathan:parse + (api:post-invite (api-token) *host*)))) (format t "Invite Code: ~a~%Expires: ~a~%" (getf invite :code) (getf invite :expires)))) @@ -342,10 +328,9 @@ running the body. If such a oneliner can be found." (defun login (user pass) (let ((response (jonathan:parse - (api:request-with - (:body (jonathan:to-json (list :password pass :handle user)) - :content-type "application/json") - (api:post--access))))) + (api:post-access *host* + :%content-type "application/json" + :%body (jonathan:to-json (list :password pass :handle user)))))) (setf (api-token) (getf response :token) (handle) user) (format t "Access token written to ~a~%You may now make contributions to the wiki!.~%" @@ -354,29 +339,22 @@ running the body. If such a oneliner can be found." (defun change-pw (current new repeated) (unless (equal new repeated) (error "The new password doesn't match the repeated value. Double check.")) - (api:put--contributor-who-password (handle) - :token (api-token) - :value new - :repeated new - :current current)) + (api:put-contributor/who/password (handle) new repeated current (api-token) *host*)) (defun change-signature () (let ((new-sig (prompt-for-signature))) (ensure-config) - (api:request-with - (:host (host) - :body (jonathan:to-json (list :signature new-sig)) - :content-type "application/json") - (api:put--contributor-who-signature (handle) :token (api-token)) - (format t "Your signature was changed.~%")))) + (api:put-contributor/who/signature (handle) (api-token) *host* + :%content-type "application/json" + :%body (jonathan:to-json (list :signature new-sig))) + (format t "Your signature was changed.~%"))) (defun show-contributor (name) - (let ((contributor (api:get--contributor-who name))) + (let ((contributor (api:get-contributor/who name *host*))) (print-contributor (jonathan:parse contributor)))) - (defparameter +agree-to-the-unlicense+ "By creating this contributor account, I agree that my contributions be released into the public domain, for the benefit of the public at @@ -388,17 +366,16 @@ running the body. If such a oneliner can be found." (defun redeem-invite (token name pass) (when (yes-or-no-p +agree-to-the-unlicense+) - (api:request-with - (:body (jonathan:to-json (list :handle name + (api:post-invite/redeem/code token *host* + :%content-type "application/json" + :%body (jonathan:to-json (list :handle name :password1 pass :password2 pass - :signature (prompt-for-signature))) - :content-type "application/json") - (api:post--invite-redeem-code token) - (format t "Account made for ~a. You may log in now~%" name)))) + :signature (prompt-for-signature)))) + (format t "Account made for ~a. You may log in now~%" name))) -;;TODO: check this .. shouldnt access be a username??? +;;TODO: check this .. shouldnt access be a username??? yes! (defun revoke-access () - (api:delete--access-access (api-token) :token (api-token)) + (api:delete-access/access (api-token) (api-token) *host*) (format t "You were logged out~%")) diff --git a/lib/state.lisp b/lib/state.lisp index e690f37..1f9f36b 100644 --- a/lib/state.lisp +++ b/lib/state.lisp @@ -160,6 +160,9 @@ user for some input if it does not." (read-config-file) (make-fresh-config))) +;;; HOSTS + +(defvar *host* nil) ;;; STATE LOADING MACRO @@ -169,18 +172,18 @@ sets the api's *host* variable. If BODY produces no errors, the " `(let* ((*config* (ensure-config)) (*cache* (read-cache-file)) (*drafts* (read-drafts-file)) - (api:*host* (config-host *config*)) + (*host* (config-host *config*)) (errorsp nil)) (unwind-protect (handler-case (progn - (assert api:*host* () "ol must be configured with a server host.") + (assert *host* () "ol must be configured with a server host.") (set-term-width) ,@body) (dexador.error:http-request-failed (e) (setf errorsp t) (format *error-output* "Operation failed. The server at ~a returned with ~a~%" - api:*host* + *host* (dexador.error:response-status e))) (error (e) (setf errorsp t) diff --git a/oneliners.api-client.lisp b/oneliners.api-client.lisp index e135973..f8baa8e 100644 --- a/oneliners.api-client.lisp +++ b/oneliners.api-client.lisp @@ -1,437 +1,187 @@ -(defpackage #:lazybones-client.shared - (:intern #:req-string) - (:export #:*host* #:*body* #:*headers* #:*cookies*)) +;;;; DO NOT EDIT! THIS FILE HAS BEEN GENERATED BY LAZYBONES-CLIENT + (defpackage #:ONELINERS.API-CLIENT - (:use :cl :lazybones-client.shared) - (:export #:*host* #:*body* #:*headers* #:*cookies* #:request-with - #:GET--ONELINERS -#:GET--ONELINERS-ALL-FLAGGED -#:GET--ONELINERS-NEWEST -#:PUT--ONELINER-ENTRY-FLAG -#:GET--ONELINER-ENTRY -#:PATCH--ONELINER-ENTRY-EDIT -#:PUT--ONELINER-ONELINER-LOCKED -#:POST--ONELINER -#:DELETE--ONELINER-ONELINER -#:POST--INVITE -#:DELETE--ACCESS-ACCESS -#:POST--ACCESS -#:POST--INVITE-REDEEM-CODE -#:PUT--CONTRIBUTOR-WHO-SIGNATURE -#:PUT--CONTRIBUTOR-WHO-PASSWORD -#:PUT--CONTRIBUTOR-WHO-LOCKED -#:GET--CONTRIBUTOR-WHO -#:POST--SNAPSHOT)) + (:use :cl) + (:export + #:get-oneliners + #:get-oneliners/all-flagged + #:get-oneliners/newest + #:put-oneliner/entry/flag + #:get-oneliner/entry + #:patch-oneliner/entry/edit + #:put-oneliner/oneliner/locked + #:post-oneliner + #:delete-oneliner/oneliner + #:post-invite + #:delete-access/access + #:post-access + #:post-invite/redeem/code + #:put-contributor/who/signature + #:put-contributor/who/password + #:put-contributor/who/locked + #:get-contributor/who + #:post-snapshot)) (in-package :ONELINERS.API-CLIENT) - -(defvar *host* nil - "The host to which the client will send its requests.") - - (defvar *body* nil - "Body passed to client post, put, and patch requests") - - (defvar *cookies* nil - "An instance of CL-COOKIE:COOKIE-JAR.") - - (defvar *headers* nil - "A liist of (header-name . header-value) pairs.") - - (defmacro request-with ((&key host body headers content-type cookies) &body forms) - "Make a request in a specific context. - -HOST is a string, the hostname where the request will be sent. Defaults -to *HOST*. - -BODY should be a string, an alist, or a pathname. Default to *BODY* - -HEADERS should be an ALIST of (header-name . header-value) string -pairs. Defaults to *HEADERS*. - -CONTENT-TYPE is a convenience for supplying just the Content-Type -header. - -COOKIES should be an instance of CL-COOKIE:COOKIE-JAR. Defaults to -*COOKIES*. -" - (let ((content-type-var (gensym)) - (http-error-var (gensym))) - `(let ((*host* (or ,host *host*)) - (*body* (or ,body *body*)) - (*headers* (or ,headers *headers*)) - (*cookies* (or ,cookies *cookies*)) - (,content-type-var ,content-type)) - (when ,content-type-var - (push (cons "Content-Type" ,content-type-var) *headers*)) - (handler-case (progn ,@forms) - (dex:http-request-failed (,http-error-var) - (format *error-output* "~a -- ~a" - (dex:response-status ,http-error-var) - (dex:response-body ,http-error-var))))))) - - -(DEFUN GET--ONELINERS (&KEY TAGS LIMIT NOTFLAGGED NEWEST ONLYFLAGGED) +(defun get-oneliners + (TAGS LIMIT NOTFLAGGED %host &key %headers %cookies) "A search endpoint returning a JSON encoded array of Oneliner Entries. TAGS cannot be empty. Returns a [Search Result](#search-result) object." - (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING - (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/oneliners") - (WHEN (OR TAGS LIMIT NOTFLAGGED NEWEST ONLYFLAGGED) - (LIST "?" - (IF TAGS - (CONCATENATE 'STRING (SYMBOL-NAME 'TAGS) "=" - (FORMAT NIL "~a" TAGS)) - "") - (IF LIMIT - (CONCATENATE 'STRING "&" (SYMBOL-NAME 'LIMIT) "=" - (FORMAT NIL "~a" LIMIT)) - "") - (IF NOTFLAGGED - (CONCATENATE 'STRING "&" (SYMBOL-NAME 'NOTFLAGGED) - "=" (FORMAT NIL "~a" NOTFLAGGED)) - "") - (IF NEWEST - (CONCATENATE 'STRING "&" (SYMBOL-NAME 'NEWEST) "=" - (FORMAT NIL "~a" NEWEST)) - "") - (IF ONLYFLAGGED - (CONCATENATE 'STRING "&" (SYMBOL-NAME 'ONLYFLAGGED) - "=" (FORMAT NIL "~a" ONLYFLAGGED)) - "")))))) - (DEXADOR:GET LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*))) + (dexador:get + (format nil "~a/api/oneliners?~@[TAGS=~a~]~@[&LIMIT=~a~]~@[&NOTFLAGGED=~a~]" %host TAGS LIMIT NOTFLAGGED) + :cookie-jar %cookies + :headers %headers)) - -(DEFUN GET--ONELINERS-ALL-FLAGGED (&KEY LIMIT) +(defun get-oneliners/all-flagged + (LIMIT %host &key %headers %cookies) "A search endpoint returning all of the flagged oneliners. If LIMIT is present, only that many are returned." - (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING - (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/oneliners/all-flagged") - (WHEN (OR LIMIT) - (LIST "?" - (IF LIMIT - (CONCATENATE 'STRING (SYMBOL-NAME 'LIMIT) "=" - (FORMAT NIL "~a" LIMIT)) - "")))))) - (DEXADOR:GET LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*))) - + (dexador:get + (format nil "~a/api/oneliners/all-flagged?~@[LIMIT=~a~]" %host LIMIT) + :cookie-jar %cookies + :headers %headers)) -(DEFUN GET--ONELINERS-NEWEST (&KEY LIMIT) +(defun get-oneliners/newest + (LIMIT %host &key %headers %cookies) "A search endpoint returning the LIMIT newest oneliners." - (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING - (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/oneliners/newest") - (WHEN (OR LIMIT) - (LIST "?" - (IF LIMIT - (CONCATENATE 'STRING (SYMBOL-NAME 'LIMIT) "=" - (FORMAT NIL "~a" LIMIT)) - "")))))) - (DEXADOR:GET LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*))) + (dexador:get + (format nil "~a/api/oneliners/newest?~@[LIMIT=~a~]" %host LIMIT) + :cookie-jar %cookies + :headers %headers)) - -(DEFUN PUT--ONELINER-ENTRY-FLAG (ENTRY &KEY TOKEN VALUE) +(defun put-oneliner/entry/flag + (ENTRY TOKEN VALUE %host &key %content-type %body %headers %cookies) "Flag / Unflag the oneliner for review." - (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING - (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/oneliner/~a/flag" ENTRY) - (WHEN (OR TOKEN VALUE) - (LIST "?" - (IF TOKEN - (CONCATENATE 'STRING (SYMBOL-NAME 'TOKEN) "=" - (FORMAT NIL "~a" TOKEN)) - "") - (IF VALUE - (CONCATENATE 'STRING "&" (SYMBOL-NAME 'VALUE) "=" - (FORMAT NIL "~a" VALUE)) - "")))))) - (IF LAZYBONES-CLIENT.SHARED:*BODY* - (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) - (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) - - -(DEFUN GET--ONELINER-ENTRY (ENTRY) + (dexador:put + (format nil "~a/api/oneliner/~a/flag?~@[TOKEN=~a~]~@[&VALUE=~a~]" %host ENTRY TOKEN VALUE) + :content %body + :cookie-jar %cookies + :headers (if %content-type (cons (cons "Content-Type" %content-type) %headers) %headers))) + +(defun get-oneliner/entry + (ENTRY %host &key %headers %cookies) "Gets a oneliner by id." - (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING - (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/oneliner/~a" ENTRY) NIL))) - (DEXADOR:GET LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*))) + (dexador:get + (format nil "~a/api/oneliner/~a?" %host ENTRY ) + :cookie-jar %cookies + :headers %headers)) - -(DEFUN PATCH--ONELINER-ENTRY-EDIT (ENTRY &KEY TOKEN) +(defun patch-oneliner/entry/edit + (ENTRY TOKEN %host &key %content-type %body %headers %cookies) "Edit the fields of a oneliner." - (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING - (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/oneliner/~a/edit" ENTRY) - (WHEN (OR TOKEN) - (LIST "?" - (IF TOKEN - (CONCATENATE 'STRING (SYMBOL-NAME 'TOKEN) "=" - (FORMAT NIL "~a" TOKEN)) - "")))))) - (IF LAZYBONES-CLIENT.SHARED:*BODY* - (DEXADOR:PATCH LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) - (DEXADOR:PATCH LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) - - -(DEFUN PUT--ONELINER-ONELINER-LOCKED (ONELINER &KEY TOKEN VALUE) + (dexador:patch + (format nil "~a/api/oneliner/~a/edit?~@[TOKEN=~a~]" %host ENTRY TOKEN) + :content %body + :cookie-jar %cookies + :headers (if %content-type (cons (cons "Content-Type" %content-type) %headers) %headers))) + +(defun put-oneliner/oneliner/locked + (ONELINER TOKEN VALUE %host &key %content-type %body %headers %cookies) "Sets the locked value of the specified oneliner" - (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING - (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/oneliner/~a/locked" ONELINER) - (WHEN (OR TOKEN VALUE) - (LIST "?" - (IF TOKEN - (CONCATENATE 'STRING (SYMBOL-NAME 'TOKEN) "=" - (FORMAT NIL "~a" TOKEN)) - "") - (IF VALUE - (CONCATENATE 'STRING "&" (SYMBOL-NAME 'VALUE) "=" - (FORMAT NIL "~a" VALUE)) - "")))))) - (IF LAZYBONES-CLIENT.SHARED:*BODY* - (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) - (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) - - -(DEFUN POST--ONELINER (&KEY TOKEN) + (dexador:put + (format nil "~a/api/oneliner/~a/locked?~@[TOKEN=~a~]~@[&VALUE=~a~]" %host ONELINER TOKEN VALUE) + :content %body + :cookie-jar %cookies + :headers (if %content-type (cons (cons "Content-Type" %content-type) %headers) %headers))) + +(defun post-oneliner + (TOKEN %host &key %content-type %body %headers %cookies) "Make a new [oneliner](#oneliner)." - (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING - (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/oneliner") - (WHEN (OR TOKEN) - (LIST "?" - (IF TOKEN - (CONCATENATE 'STRING (SYMBOL-NAME 'TOKEN) "=" - (FORMAT NIL "~a" TOKEN)) - "")))))) - (IF LAZYBONES-CLIENT.SHARED:*BODY* - (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) - (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) - - -(DEFUN DELETE--ONELINER-ONELINER (ONELINER &KEY TOKEN) + (dexador:post + (format nil "~a/api/oneliner?~@[TOKEN=~a~]" %host TOKEN) + :content %body + :cookie-jar %cookies + :headers (if %content-type (cons (cons "Content-Type" %content-type) %headers) %headers))) + +(defun delete-oneliner/oneliner + (ONELINER TOKEN %host &key %headers %cookies) "Delete a oneliner." - (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING - (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/oneliner/~a" ONELINER) - (WHEN (OR TOKEN) - (LIST "?" - (IF TOKEN - (CONCATENATE 'STRING (SYMBOL-NAME 'TOKEN) "=" - (FORMAT NIL "~a" TOKEN)) - "")))))) - (DEXADOR:DELETE LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*))) + (dexador:delete + (format nil "~a/api/oneliner/~a?~@[TOKEN=~a~]" %host ONELINER TOKEN) + :cookie-jar %cookies + :headers %headers)) - -(DEFUN POST--INVITE (&KEY TOKEN) +(defun post-invite + (TOKEN %host &key %content-type %body %headers %cookies) "On success, return an object containing a new [invite token](#invite-token)." - (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING - (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/invite") - (WHEN (OR TOKEN) - (LIST "?" - (IF TOKEN - (CONCATENATE 'STRING (SYMBOL-NAME 'TOKEN) "=" - (FORMAT NIL "~a" TOKEN)) - "")))))) - (IF LAZYBONES-CLIENT.SHARED:*BODY* - (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) - (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) - - -(DEFUN DELETE--ACCESS-ACCESS (ACCESS &KEY TOKEN) + (dexador:post + (format nil "~a/api/invite?~@[TOKEN=~a~]" %host TOKEN) + :content %body + :cookie-jar %cookies + :headers (if %content-type (cons (cons "Content-Type" %content-type) %headers) %headers))) + +(defun delete-access/access + (ACCESS TOKEN %host &key %headers %cookies) "Revoke access of CONTRIBUTOR" - (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING - (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/access/~a" ACCESS) - (WHEN (OR TOKEN) - (LIST "?" - (IF TOKEN - (CONCATENATE 'STRING (SYMBOL-NAME 'TOKEN) "=" - (FORMAT NIL "~a" TOKEN)) - "")))))) - (DEXADOR:DELETE LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*))) + (dexador:delete + (format nil "~a/api/access/~a?~@[TOKEN=~a~]" %host ACCESS TOKEN) + :cookie-jar %cookies + :headers %headers)) - -(DEFUN POST--ACCESS () +(defun post-access + ( %host &key %content-type %body %headers %cookies) "Authenticate a contributor and reply with an [API token](#access-token)" - (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING - (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/access") NIL))) - (IF LAZYBONES-CLIENT.SHARED:*BODY* - (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) - (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) - - -(DEFUN POST--INVITE-REDEEM-CODE (CODE) + (dexador:post + (format nil "~a/api/access?" %host ) + :content %body + :cookie-jar %cookies + :headers (if %content-type (cons (cons "Content-Type" %content-type) %headers) %headers))) + +(defun post-invite/redeem/code + (CODE %host &key %content-type %body %headers %cookies) "Redeem an [invite code](#invite-code) and create a new [contributor](#new-contributor-post-body)" - (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING - (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/invite/redeem/~a" CODE) NIL))) - (IF LAZYBONES-CLIENT.SHARED:*BODY* - (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) - (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) - - -(DEFUN PUT--CONTRIBUTOR-WHO-SIGNATURE (WHO &KEY TOKEN) + (dexador:post + (format nil "~a/api/invite/redeem/~a?" %host CODE ) + :content %body + :cookie-jar %cookies + :headers (if %content-type (cons (cons "Content-Type" %content-type) %headers) %headers))) + +(defun put-contributor/who/signature + (WHO TOKEN %host &key %content-type %body %headers %cookies) "Update a [contributor's](#contributor) signature." - (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING - (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/contributor/~a/signature" WHO) - (WHEN (OR TOKEN) - (LIST "?" - (IF TOKEN - (CONCATENATE 'STRING (SYMBOL-NAME 'TOKEN) "=" - (FORMAT NIL "~a" TOKEN)) - "")))))) - (IF LAZYBONES-CLIENT.SHARED:*BODY* - (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) - (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) - - -(DEFUN PUT--CONTRIBUTOR-WHO-PASSWORD (WHO &KEY VALUE REPEATED CURRENT TOKEN) + (dexador:put + (format nil "~a/api/contributor/~a/signature?~@[TOKEN=~a~]" %host WHO TOKEN) + :content %body + :cookie-jar %cookies + :headers (if %content-type (cons (cons "Content-Type" %content-type) %headers) %headers))) + +(defun put-contributor/who/password + (WHO VALUE REPEATED CURRENT TOKEN %host &key %content-type %body %headers %cookies) "Change a contributor's password. CURRENT is the current password. VALUE is the new password. REPEATED must match VALUE. TOKEN is an API Access token." - (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING - (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/contributor/~a/password" WHO) - (WHEN (OR VALUE REPEATED CURRENT TOKEN) - (LIST "?" - (IF VALUE - (CONCATENATE 'STRING (SYMBOL-NAME 'VALUE) "=" - (FORMAT NIL "~a" VALUE)) - "") - (IF REPEATED - (CONCATENATE 'STRING "&" (SYMBOL-NAME 'REPEATED) - "=" (FORMAT NIL "~a" REPEATED)) - "") - (IF CURRENT - (CONCATENATE 'STRING "&" (SYMBOL-NAME 'CURRENT) "=" - (FORMAT NIL "~a" CURRENT)) - "") - (IF TOKEN - (CONCATENATE 'STRING "&" (SYMBOL-NAME 'TOKEN) "=" - (FORMAT NIL "~a" TOKEN)) - "")))))) - (IF LAZYBONES-CLIENT.SHARED:*BODY* - (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) - (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) - - -(DEFUN PUT--CONTRIBUTOR-WHO-LOCKED (WHO &KEY VALUE TOKEN) + (dexador:put + (format nil "~a/api/contributor/~a/password?~@[VALUE=~a~]~@[&REPEATED=~a~]~@[&CURRENT=~a~]~@[&TOKEN=~a~]" %host WHO VALUE REPEATED CURRENT TOKEN) + :content %body + :cookie-jar %cookies + :headers (if %content-type (cons (cons "Content-Type" %content-type) %headers) %headers))) + +(defun put-contributor/who/locked + (WHO VALUE TOKEN %host &key %content-type %body %headers %cookies) "Admin users may lock a particular contributor, preventing that contributor for making edits or adding new oneliners." - (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING - (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/contributor/~a/locked" WHO) - (WHEN (OR VALUE TOKEN) - (LIST "?" - (IF VALUE - (CONCATENATE 'STRING (SYMBOL-NAME 'VALUE) "=" - (FORMAT NIL "~a" VALUE)) - "") - (IF TOKEN - (CONCATENATE 'STRING "&" (SYMBOL-NAME 'TOKEN) "=" - (FORMAT NIL "~a" TOKEN)) - "")))))) - (IF LAZYBONES-CLIENT.SHARED:*BODY* - (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) - (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) - - -(DEFUN GET--CONTRIBUTOR-WHO (WHO) + (dexador:put + (format nil "~a/api/contributor/~a/locked?~@[VALUE=~a~]~@[&TOKEN=~a~]" %host WHO VALUE TOKEN) + :content %body + :cookie-jar %cookies + :headers (if %content-type (cons (cons "Content-Type" %content-type) %headers) %headers))) + +(defun get-contributor/who + (WHO %host &key %headers %cookies) "Return a [contributor](#contributor) data object." - (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING - (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/contributor/~a" WHO) NIL))) - (DEXADOR:GET LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*))) - + (dexador:get + (format nil "~a/api/contributor/~a?" %host WHO ) + :cookie-jar %cookies + :headers %headers)) -(DEFUN POST--SNAPSHOT (&KEY TOKEN) +(defun post-snapshot + (TOKEN %host &key %content-type %body %headers %cookies) "Snapshot the datastore. Do this after upgrade" - (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING - (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/snapshot") - (WHEN (OR TOKEN) - (LIST "?" - (IF TOKEN - (CONCATENATE 'STRING (SYMBOL-NAME 'TOKEN) "=" - (FORMAT NIL "~a" TOKEN)) - "")))))) - (IF LAZYBONES-CLIENT.SHARED:*BODY* - (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) - (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) + (dexador:post + (format nil "~a/api/snapshot?~@[TOKEN=~a~]" %host TOKEN) + :content %body + :cookie-jar %cookies + :headers (if %content-type (cons (cons "Content-Type" %content-type) %headers) %headers))) |