aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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)