From 2dd1e60e52cb7871467b1aade5c74c6bdd21b3aa Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Mon, 21 Feb 2022 15:54:54 -0600 Subject: added flagging and locking commands --- src/lib.lisp | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) (limited to 'src/lib.lisp') 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) -- cgit v1.2.3