aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2022-02-18 18:51:47 -0600
committerColin Okay <okay@toyful.space>2022-02-18 18:51:47 -0600
commitc2475ad2a120f67a2dd373d1e720e4dac77d1d7e (patch)
tree8d063a1bb94b1c79cd68d3f7e222047e5366761b
parent13d628d008584dff9465a9fb48e4e57e74bf7643 (diff)
added paramater token to api client functions
-rw-r--r--oneliners.api-client.lisp70
-rw-r--r--src/lib.lisp19
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)