From 1d59c9675341b1e962f9c79e1fd1b5ce52cd9cbf Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Mon, 14 Feb 2022 11:27:28 -0600 Subject: added autogenerated client code --- clpmfile | 1 + clpmfile.lock | 11 +++- oneliners.api-client.asd | 3 + oneliners.api-client.lisp | 149 ++++++++++++++++++++++++++++++++++++++++++++++ oneliners.cli.asd | 3 +- 5 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 oneliners.api-client.asd create mode 100644 oneliners.api-client.lisp diff --git a/clpmfile b/clpmfile index e2dae29..f770b09 100644 --- a/clpmfile +++ b/clpmfile @@ -4,3 +4,4 @@ (:source "quicklisp" :url "https://beta.quicklisp.org/dist/quicklisp.txt" :type :quicklisp) (:asd "oneliners.cli.asd") +(:asd "oneliners.api-client.asd") diff --git a/clpmfile.lock b/clpmfile.lock index c490373..0521d30 100644 --- a/clpmfile.lock +++ b/clpmfile.lock @@ -9,6 +9,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; :sources +(:implicit-file :type :file-system :system-files ("oneliners.api-client.asd")) (:implicit-file :type :file-system :system-files ("oneliners.cli.asd")) ("quicklisp" :url "https://beta.quicklisp.org/dist/quicklisp.txt" :type :quicklisp) @@ -19,6 +20,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; :requirements +(:asd-file :name "oneliners.api-client.asd") (:asd-file :name "oneliners.cli.asd") @@ -47,6 +49,8 @@ ("flexi-streams" :version "2021-08-07" :source "quicklisp" :systems ("flexi-streams")) ("local-time" :version "2021-01-24" :source "quicklisp" :systems ("local-time")) +("oneliners.api-client.asd" :version :newest :source :implicit-file :systems + ("oneliners.api-client")) ("oneliners.cli.asd" :version :newest :source :implicit-file :systems ("oneliners.cli")) ("osicat" :version "2021-12-09" :source "quicklisp" :systems ("osicat")) @@ -127,7 +131,8 @@ ("cl-utilities" ((:system :name "quri") (:system :name "cl-utilities")) ((:system :name "fast-http") (:system :name "cl-utilities"))) -("dexador" ((:system :name "oneliners.cli") (:system :name "dexador"))) +("dexador" ((:system :name "oneliners.cli") (:system :name "dexador")) + ((:system :name "oneliners.api-client") (:system :name "dexador"))) ("fast-http" ((:system :name "dexador") (:system :name "fast-http"))) @@ -139,6 +144,10 @@ ("local-time" ((:system :name "cl-cookie") (:system :name "local-time"))) +("oneliners.api-client.asd" + ((:system :name "oneliners.cli") (:system :name "oneliners.api-client")) + (t (:asd-file :name "oneliners.api-client.asd"))) + ("oneliners.cli.asd" (t (:asd-file :name "oneliners.cli.asd"))) ("osicat" ((:system :name "oneliners.cli") (:system :name "osicat"))) diff --git a/oneliners.api-client.asd b/oneliners.api-client.asd new file mode 100644 index 0000000..3b75288 --- /dev/null +++ b/oneliners.api-client.asd @@ -0,0 +1,3 @@ +(asdf:defsystem #:ONELINERS.API-CLIENT + :depends-on (#:dexador) + :components ((:file "oneliners.api-client"))) \ No newline at end of file diff --git a/oneliners.api-client.lisp b/oneliners.api-client.lisp new file mode 100644 index 0000000..d3142fb --- /dev/null +++ b/oneliners.api-client.lisp @@ -0,0 +1,149 @@ + +(defpackage #:lazybones-client.shared + (:intern #:req-string) + (:export #:*host* #:*body* #:*headers* #:*cookies*)) +(defpackage #:ONELINERS.API-CLIENT + (:use :cl :lazybones-client.shared) + (:export #:*host* #:*body* #:*headers* #:*cookies* #:request-with + #:POST--AUTH + #:POST--ONELINER + #:PUT--ONELINER-ONELINER + #:GET--SEARCH)) +(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))) + `(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*)) + ,@forms))) + + +(DEFUN POST--AUTH () + "Requests an authorization token" + (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING + (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* + (FORMAT NIL "/auth") (WHEN (OR) (LIST "?"))))) + (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--ONELINER () + "Adds a new oneliner entry to the wiki database." + (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING + (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* + (FORMAT NIL "/oneliner") (WHEN (OR) (LIST "?"))))) + (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--ONELINER-ONELINER (ONELINER) + "Updates a oneliner entry in the wiki database." + (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING + (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* + (FORMAT NIL "/oneliner/~a" ONELINER) (WHEN (OR) (LIST "?"))))) + (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--SEARCH + (&KEY COMMANDS KEYWORDS LIMIT PAGE NEXTPAGE NOTFLAGGED ONLYAUDITED) + "A search endpoint returning a JSON encoded array of Oneliner Entries. + +**Note**: either command or keywords are required. +" + (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING + (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* + (FORMAT NIL "/search") + (WHEN + (OR COMMANDS KEYWORDS LIMIT PAGE NEXTPAGE NOTFLAGGED + ONLYAUDITED) + (LIST "?" + (IF COMMANDS + (CONCATENATE 'STRING (SYMBOL-NAME 'COMMANDS) "=" + (FORMAT NIL "~a" COMMANDS)) + "") + (IF KEYWORDS + (CONCATENATE 'STRING "&" (SYMBOL-NAME 'KEYWORDS) + "=" (FORMAT NIL "~a" KEYWORDS)) + "") + (IF LIMIT + (CONCATENATE 'STRING "&" (SYMBOL-NAME 'LIMIT) "=" + (FORMAT NIL "~a" LIMIT)) + "") + (IF PAGE + (CONCATENATE 'STRING "&" (SYMBOL-NAME 'PAGE) "=" + (FORMAT NIL "~a" PAGE)) + "") + (IF NEXTPAGE + (CONCATENATE 'STRING "&" (SYMBOL-NAME 'NEXTPAGE) + "=" (FORMAT NIL "~a" NEXTPAGE)) + "") + (IF NOTFLAGGED + (CONCATENATE 'STRING "&" (SYMBOL-NAME 'NOTFLAGGED) + "=" (FORMAT NIL "~a" NOTFLAGGED)) + "") + (IF ONLYAUDITED + (CONCATENATE 'STRING "&" (SYMBOL-NAME 'ONLYAUDITED) + "=" (FORMAT NIL "~a" ONLYAUDITED)) + "")))))) + (IF LAZYBONES-CLIENT.SHARED:*BODY* + (DEXADOR:GET LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT + LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*) + (DEXADOR:GET LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*)))) + diff --git a/oneliners.cli.asd b/oneliners.cli.asd index f8c2fa8..b072e32 100644 --- a/oneliners.cli.asd +++ b/oneliners.cli.asd @@ -5,7 +5,8 @@ :depends-on ("trivial-clipboard" "dexador" "osicat" - "unix-opts") + "unix-opts" + "oneliners.api-client") :components ((:module "src" :components ((:file "main")))) -- cgit v1.2.3