aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2022-02-21 15:54:54 -0600
committerColin Okay <okay@toyful.space>2022-02-21 15:54:54 -0600
commit2dd1e60e52cb7871467b1aade5c74c6bdd21b3aa (patch)
tree59988020f5e683ee07a19f92279f6e25c3a47b52
parentd7b1a2774dc1b8ab3c166c8dc0332110d653ebe9 (diff)
added flagging and locking commands
-rw-r--r--build-app.lisp28
-rw-r--r--build.lisp3
-rw-r--r--oneliners.api-client.lisp50
-rw-r--r--src/lib.lisp44
4 files changed, 86 insertions, 39 deletions
diff --git a/build-app.lisp b/build-app.lisp
index 5d4f069..c95d163 100644
--- a/build-app.lisp
+++ b/build-app.lisp
@@ -56,10 +56,18 @@ my1337pw.")
(flag :long-name "add"
:description "Intaractively add a oneliner and update the wiki.")
(flag :long-name "update"
- :description "Interactively edit a oneliner and update the wiki."))
+ :description "Interactively edit a oneliner and update the wiki.")
+ (flag :long-name "flag"
+ :description "Flag a oneliner for review.")
+ (flag :long-name "unflag"
+ :description "If you have admin priviliges, unflag a oneliner.")
+ (flag :long-name "lock"
+ :description "If you have admin priviliges, lock a oneliner from being edited.")
+ (flag :long-name "unlock"
+ :description "If you have admin priviliges, unlock a oneliner."))
(group (:header "Access" :hidden t)
(flag :long-name "login"
- :description "Attempt to login to your contributor account. ARGS are interpreted as USERNAME PASSWORD. Success will return ab API token, writing it automatically into your config file.")
+ :description "Attempt to login to your contributor account. ARGS are interpreted as USERNAME PASSWORD.")
(flag :long-name "revoke"
:description "Revoke your own access token."))
(group (:header "Invites" :hidden t)
@@ -117,10 +125,18 @@ than the users."
(arguments
;; when the first argument is a number, try run a oneliner
(a:when-let (hist-number (parse-integer (first arguments) :junk-allowed t))
- (if (getopt :long-name "flag")
- (format t "TBD: going to flag a command~%") ;(cli::flag-item hist-number)
- (format t "TBD: Going to run command ~a with arguments ~a~%"
- hist-number (rest arguments)))
+ (cond
+ ((getopt :long-name "flag")
+ (cli::flag-item hist-number))
+ ((getopt :long-name "unflag")
+ (cli::unflag-item hist-number))
+ ((getopt :long-name "lock")
+ (cli::lock-item hist-number))
+ ((getopt :long-name "unlock")
+ (cli::unlock-item hist-number))
+ (t
+ (format t "TBD: Going to run command ~a with arguments ~a~%"
+ hist-number (rest arguments))))
(uiop:quit))
;; otherwise search for oneliners
(cli::search-for-oneliners arguments
diff --git a/build.lisp b/build.lisp
deleted file mode 100644
index f8e4227..0000000
--- a/build.lisp
+++ /dev/null
@@ -1,3 +0,0 @@
-
-(asdf:load-system "oneliners.cli")
-(sb-ext:save-lisp-and-die "ol" :toplevel 'oneliners.cli::main :executable t)
diff --git a/oneliners.api-client.lisp b/oneliners.api-client.lisp
index 563d088..19ca89f 100644
--- a/oneliners.api-client.lisp
+++ b/oneliners.api-client.lisp
@@ -5,9 +5,9 @@
(defpackage #:ONELINERS.API-CLIENT
(:use :cl :lazybones-client.shared)
(:export #:*host* #:*body* #:*headers* #:*cookies* #:request-with
- #:GET--ONELINERS
+ #:PUT--ONELINER-ENTRY-FLAG
+#:GET--ONELINERS
#:GET--ONELIERS
-#:PUT--ONELINER-ENTRY-FLAG
#:PATCH--ONELINER-ENTRY-EDIT
#:PUT--ONELINER-ONELINER-LOCKED
#:POST--ONELINER
@@ -63,6 +63,31 @@ COOKIES should be an instance of CL-COOKIE:COOKIE-JAR. Defaults to
(dex:response-body ,http-error-var)))))))
+(DEFUN PUT--ONELINER-ENTRY-FLAG (ENTRY &KEY TOKEN VALUE)
+ "Flag the oneliner for review."
+ (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING
+ (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST*
+ (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--ONELINERS (&KEY TAGS LIMIT NOTFLAGGED)
"A search endpoint returning a JSON encoded array of Oneliner
Entries. TAGS cannot be empty. Returns a [Search
@@ -115,27 +140,6 @@ Result](#search-result) object."
LAZYBONES-CLIENT.SHARED:*HEADERS*)))
-(DEFUN PUT--ONELINER-ENTRY-FLAG (ENTRY &KEY TOKEN)
- "Flag the oneliner for review."
- (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING
- (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST*
- (FORMAT NIL "/oneliner/~a/flag" ENTRY)
- (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 PATCH--ONELINER-ENTRY-EDIT (ENTRY &KEY TOKEN)
"Edit the fields of a oneliner."
(LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING
diff --git a/src/lib.lisp b/src/lib.lisp
index 3dd6e7d..750dfea 100644
--- a/src/lib.lisp
+++ b/src/lib.lisp
@@ -92,22 +92,52 @@ the directories that appear in the value of that variable."
(princ prompt out-stream) (force-output out-stream)
(read-line in-stream))
-(defun history (&optional n)
+(defun cached-result (&optional n)
(when (uiop:file-exists-p (last-search-file))
(let ((contents (with-open-file (input (last-search-file)) (read input))))
(if n
(nth n contents)
contents))))
+(defmacro with-cached-result ((olvar n) &body body)
+ (a:with-gensyms (nvar)
+ `(let ((,nvar ,n))
+ (assert (plusp ,nvar) () "Item number must be 1 or greater")
+ (a:if-let (,olvar (cached-result (1- ,nvar)))
+ (progn ,@body)
+ (format t "The last search was shorter than ~a" ,nvar)))))
+
;;; API REQUEST FUNCTIONS
(defun flag-item (item-number)
- (assert (plusp item-number) () "Item number must be ")
- (ensure-config)
- (api:request-with
- (:host (host))
- (a:when-let (oneliner (history (1- item-number)))
- (api:put--oneliner-entry-flag (getf oneliner :id) :token (api-token)))))
+ (with-cached-result (ol item-number)
+ (ensure-config)
+ (api:request-with
+ (:host (host))
+ (api:put--oneliner-entry-flag (getf ol :id) :token (api-token) :value "true"))))
+
+(defun unflag-item (item-number)
+ (with-cached-result (ol item-number)
+ (ensure-config)
+ (api:request-with
+ (:host (host))
+ (api:put--oneliner-entry-flag (getf ol :id) :token (api-token) :value "false"))))
+
+(defun lock-item (item-number)
+ (with-cached-result (ol item-number)
+ (ensure-config)
+ (api:request-with
+ (:host (host))
+ (api:put--oneliner-oneliner-locked (getf ol :id) :token (api-token) :value "true"))))
+
+(defun unlock-item (item-number)
+ (with-cached-result (ol item-number)
+ (ensure-config)
+ (api:request-with
+ (:host (host))
+ (api:put--oneliner-oneliner-locked (getf ol :id) :token (api-token) :value "false"))))
+
+
(defun add-new-oneliner ()
(ensure-config)