aboutsummaryrefslogtreecommitdiff
path: root/src
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 /src
parentd7b1a2774dc1b8ab3c166c8dc0332110d653ebe9 (diff)
added flagging and locking commands
Diffstat (limited to 'src')
-rw-r--r--src/lib.lisp44
1 files changed, 37 insertions, 7 deletions
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)