From 13d628d008584dff9465a9fb48e4e57e74bf7643 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Fri, 18 Feb 2022 17:00:55 -0600 Subject: working on invite functions --- build-app.lisp | 2 ++ src/lib.lisp | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/build-app.lisp b/build-app.lisp index bd51d54..c2f79ba 100644 --- a/build-app.lisp +++ b/build-app.lisp @@ -102,6 +102,8 @@ than the users." ((getopt :long-name "login") (destructuring-bind (user pass) arguments (cli::login user pass))) + ((getopt :long-name "invite") + (cli::request-invite-code)) (arguments ;; when the first argument is a number, try run a oneliner (a:when-let (hist-number (parse-integer (first arguments) :junk-allowed t)) diff --git a/src/lib.lisp b/src/lib.lisp index 720ff85..a54cf7f 100644 --- a/src/lib.lisp +++ b/src/lib.lisp @@ -63,8 +63,28 @@ (when (uiop:file-exists-p (last-search-file)) (nth n (uiop:read-file-form (last-search-file))))) +(defun make-cookie-from-api-token () + (a:when-let (token (api-token)) + (let ((cookies (cl-cookie:make-cookie-jar))) + (cl-cookie:merge-cookies + cookies + (list + (cl-cookie:make-cookie + :name "olauthtoken" + :value token + :path "/" + :domain "localhost"))) + cookies))) + ;;; API REQUEST FUNCTIONS +(defun request-invite-code () + (ensure-config) + (api:request-with + (:host (host) + :cookies (make-cookie-from-api-token)) + (format t "Invite Code: ~a~%" (getf (jonathan:parse (api:post--make-invite)) :code)))) + (defun login (user pass) (ensure-config) (a:when-let (response (jonathan:parse -- cgit v1.2.3