From c2475ad2a120f67a2dd373d1e720e4dac77d1d7e Mon Sep 17 00:00:00 2001
From: Colin Okay <okay@toyful.space>
Date: Fri, 18 Feb 2022 18:51:47 -0600
Subject: added paramater token to api client functions

---
 oneliners.api-client.lisp | 70 +++++++++++++++++++++++++++++++++++++----------
 src/lib.lisp              | 19 ++-----------
 2 files changed, 59 insertions(+), 30 deletions(-)

diff --git a/oneliners.api-client.lisp b/oneliners.api-client.lisp
index 8d43eae..d66ce65 100644
--- a/oneliners.api-client.lisp
+++ b/oneliners.api-client.lisp
@@ -89,11 +89,17 @@ Result](#search-result) object."
      LAZYBONES-CLIENT.SHARED:*HEADERS*))) 
 
 
-(DEFUN PATCH--FLAG-ONELINER (ONELINER)
+(DEFUN PATCH--FLAG-ONELINER (ONELINER &KEY TOKEN)
   "Flag the oneliner for review. Open to anyone."
   (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING
          (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST*
-                (FORMAT NIL "/flag/~a" ONELINER) NIL)))
+                (FORMAT NIL "/flag/~a" ONELINER)
+                (WHEN (OR TOKEN)
+                  (LIST "?"
+                        (IF TOKEN
+                            (CONCATENATE 'STRING (SYMBOL-NAME 'TOKEN) "="
+                                         (FORMAT NIL "~a" TOKEN))
+                            ""))))))
     (IF LAZYBONES-CLIENT.SHARED:*BODY*
         (DEXADOR:PATCH LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT
          LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR
@@ -104,11 +110,17 @@ Result](#search-result) object."
          LAZYBONES-CLIENT.SHARED:*HEADERS*)))) 
 
 
-(DEFUN PATCH--EDIT-ONELINER (ONELINER)
+(DEFUN PATCH--EDIT-ONELINER (ONELINER &KEY TOKEN)
   "Edit the fields of a oneliner."
   (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING
          (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST*
-                (FORMAT NIL "/edit/~a" ONELINER) NIL)))
+                (FORMAT NIL "/edit/~a" ONELINER)
+                (WHEN (OR TOKEN)
+                  (LIST "?"
+                        (IF TOKEN
+                            (CONCATENATE 'STRING (SYMBOL-NAME 'TOKEN) "="
+                                         (FORMAT NIL "~a" TOKEN))
+                            ""))))))
     (IF LAZYBONES-CLIENT.SHARED:*BODY*
         (DEXADOR:PATCH LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT
          LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR
@@ -119,11 +131,17 @@ Result](#search-result) object."
          LAZYBONES-CLIENT.SHARED:*HEADERS*)))) 
 
 
-(DEFUN PATCH--UNLOCK-ONELINER (ONELINER)
+(DEFUN PATCH--UNLOCK-ONELINER (ONELINER &KEY TOKEN)
   "Unlocks a oneliner."
   (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING
          (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST*
-                (FORMAT NIL "/unlock/~a" ONELINER) NIL)))
+                (FORMAT NIL "/unlock/~a" ONELINER)
+                (WHEN (OR TOKEN)
+                  (LIST "?"
+                        (IF TOKEN
+                            (CONCATENATE 'STRING (SYMBOL-NAME 'TOKEN) "="
+                                         (FORMAT NIL "~a" TOKEN))
+                            ""))))))
     (IF LAZYBONES-CLIENT.SHARED:*BODY*
         (DEXADOR:PATCH LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT
          LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR
@@ -134,11 +152,17 @@ Result](#search-result) object."
          LAZYBONES-CLIENT.SHARED:*HEADERS*)))) 
 
 
-(DEFUN PATCH--LOCK-ONELINER (ONELINER)
+(DEFUN PATCH--LOCK-ONELINER (ONELINER &KEY TOKEN)
   "Locks a oneliner. Locked oneliners cannot be edited or flagged."
   (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING
          (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST*
-                (FORMAT NIL "/lock/~a" ONELINER) NIL)))
+                (FORMAT NIL "/lock/~a" ONELINER)
+                (WHEN (OR TOKEN)
+                  (LIST "?"
+                        (IF TOKEN
+                            (CONCATENATE 'STRING (SYMBOL-NAME 'TOKEN) "="
+                                         (FORMAT NIL "~a" TOKEN))
+                            ""))))))
     (IF LAZYBONES-CLIENT.SHARED:*BODY*
         (DEXADOR:PATCH LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT
          LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR
@@ -149,11 +173,17 @@ Result](#search-result) object."
          LAZYBONES-CLIENT.SHARED:*HEADERS*)))) 
 
 
-(DEFUN POST--ADD-ONELINER ()
+(DEFUN POST--ADD-ONELINER (&KEY TOKEN)
   "Make a new [oneliner](#oneliner)."
   (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING
          (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST*
-                (FORMAT NIL "/add-oneliner") NIL)))
+                (FORMAT NIL "/add-oneliner")
+                (WHEN (OR TOKEN)
+                  (LIST "?"
+                        (IF TOKEN
+                            (CONCATENATE 'STRING (SYMBOL-NAME 'TOKEN) "="
+                                         (FORMAT NIL "~a" TOKEN))
+                            ""))))))
     (IF LAZYBONES-CLIENT.SHARED:*BODY*
         (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT
          LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR
@@ -164,11 +194,17 @@ Result](#search-result) object."
          LAZYBONES-CLIENT.SHARED:*HEADERS*)))) 
 
 
-(DEFUN POST--MAKE-INVITE ()
+(DEFUN POST--MAKE-INVITE (&KEY TOKEN)
   "On success, return an object containing a new [invite token](#invite-token)."
   (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING
          (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST*
-                (FORMAT NIL "/make-invite") NIL)))
+                (FORMAT NIL "/make-invite")
+                (WHEN (OR TOKEN)
+                  (LIST "?"
+                        (IF TOKEN
+                            (CONCATENATE 'STRING (SYMBOL-NAME 'TOKEN) "="
+                                         (FORMAT NIL "~a" TOKEN))
+                            ""))))))
     (IF LAZYBONES-CLIENT.SHARED:*BODY*
         (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT
          LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR
@@ -179,13 +215,19 @@ Result](#search-result) object."
          LAZYBONES-CLIENT.SHARED:*HEADERS*)))) 
 
 
-(DEFUN POST--REVOKE-CONTRIBUTOR (CONTRIBUTOR)
+(DEFUN POST--REVOKE-CONTRIBUTOR (CONTRIBUTOR &KEY TOKEN)
   "A contributor can revoke their own access (if for some reason their
   API key ends up out of their control), or an admin can revoke
   anybody's access token, forcing the  to re-authenticate."
   (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING
          (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST*
-                (FORMAT NIL "/revoke/~a" CONTRIBUTOR) NIL)))
+                (FORMAT NIL "/revoke/~a" CONTRIBUTOR)
+                (WHEN (OR TOKEN)
+                  (LIST "?"
+                        (IF TOKEN
+                            (CONCATENATE 'STRING (SYMBOL-NAME 'TOKEN) "="
+                                         (FORMAT NIL "~a" TOKEN))
+                            ""))))))
     (IF LAZYBONES-CLIENT.SHARED:*BODY*
         (DEXADOR:POST LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT
          LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR
diff --git a/src/lib.lisp b/src/lib.lisp
index a54cf7f..0ae2b8b 100644
--- a/src/lib.lisp
+++ b/src/lib.lisp
@@ -63,27 +63,14 @@
   (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))))
+      (:host (host))
+    (format t "Invite Code: ~a~%"
+            (getf (jonathan:parse (api:post--make-invite :token (api-token))) :code))))
 
 (defun login (user pass)
   (ensure-config)
-- 
cgit v1.2.3