diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.lisp | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/src/lib.lisp b/src/lib.lisp index d174c6a..332dd07 100644 --- a/src/lib.lisp +++ b/src/lib.lisp @@ -92,15 +92,22 @@ 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) + (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)))) + ;;; API REQUEST FUNCTIONS -;; (defun flag-item (item-number) -;; (ensure-config) -;; (api:request-with -;; (:host (host)) -;; (a:if-let ((token (api-token)) -;; (oneliner (history item-number))) -;; (api:patch--flag-oneliner (getf oneliner :id) :token token)))) +(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))))) (defun add-new-oneliner () (ensure-config) @@ -126,22 +133,26 @@ the directories that appear in the value of that variable." :brief brief :explanation explanation)) :content-type "application/json") - (api:post--add-oneliner :token (api-token)) + (api:post--oneliner :token (api-token)) (format t "Added~%")))) (defun request-invite-code () (ensure-config) (api:request-with (:host (host)) - (format t "Invite Code: ~a~%" - (getf (jonathan:parse (api:post--make-invite :token (api-token))) :code)))) + (let ((invite (api:post--invite :token (api-token)))) + (format t "Invite Code: ~a~%Expires: ~a~%" + (getf invite :code) + (getf invite :expires))))) (defun login (user pass) (ensure-config) (a:when-let (response (jonathan:parse (api:request-with - (:host (host)) - (api:post--token-contributor user :password pass)))) + (:host (host) + :body (jonathan:to-json (list :password pass :handle user)) + :content-type "application/json") + (api:post--access)))) (setf (api-token) (getf response :token)) (write-config-to-disk) (format t "Access token written to ~a~%" (config-file)))) @@ -149,11 +160,11 @@ the directories that appear in the value of that variable." (defun redeem-invite (token name pass) (ensure-config ) (api:request-with - (:host (host)) - (api:post--redeem-invite token - :username name - :password1 pass - :password2 pass))) + (:host (host) + :body (jonathan:to-json (list :handle name :password1 pass :password2 pass)) + :content-type "application/json") + (api:post--invite-redeem-code token) + (format t "Account made for ~a. You may log in now~%" name))) (defun cache-search-results-to-last-search-file (results) (with-open-file (output (last-search-file) :direction :output :if-exists :supersede) @@ -175,9 +186,9 @@ the directories that appear in the value of that variable." (let ((response (api:request-with (:host (host)) - (api:get--search :tags (str:join "," terms) - :limit limit - :notflagged (if not-flagged-p "true" "false"))))) + (api:get--oneliners :tags (str:join "," terms) + :limit limit + :notflagged (if not-flagged-p "true" "false"))))) (handler-case (a:when-let (oneliners (getf (jonathan:parse response) :oneliners)) |