aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-09-12 21:34:19 +0200
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-09-12 22:46:45 +0200
commit179f001697703ec88651a181d18212d17f2b6dd8 (patch)
treed7f96f9ae2637b1e1a1cc2684aee6bb474eae828 /lisp
parentd73436bd148a8c73c6a63eb65c4026b3dbfa0591 (diff)
factor out http--build-query-string for use PATCH reqs also
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mastodon-http.el32
1 files changed, 18 insertions, 14 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el
index a8b3650..f73fd6b 100644
--- a/lisp/mastodon-http.el
+++ b/lisp/mastodon-http.el
@@ -73,7 +73,7 @@
"Retrieve URL asynchronously.
This is a thin abstraction over the system
-`url-retrieve-synchronously`. Depending on which version of this
+`url-retrieve-synchronously'. Depending on which version of this
is available we will call it with or without a timeout."
(if (< (cdr (func-arity 'url-retrieve-synchronously)) 4)
(url-retrieve-synchronously url)
@@ -108,6 +108,18 @@ Unless UNAUTHENTICATED-P is non-nil."
(concat "Bearer " (mastodon-auth--access-token)))))))
,body))
+(defun mastodon-http--build-query-string (args)
+ "Build a request query string from ARGS."
+ ;; (url-build-query-string args nil))
+ ;; url-build-query-string adds 'nil' to empty params so lets stay with our
+ ;; own:
+ (mapconcat (lambda (arg)
+ (concat (url-hexify-string (car arg))
+ "="
+ (url-hexify-string (cdr arg))))
+ args
+ "&"))
+
(defun mastodon-http--post (url args headers &optional unauthenticated-p)
"POST synchronously to URL with ARGS and HEADERS.
@@ -116,12 +128,7 @@ Authorization header is included by default unless UNAUTHENTICATED-P is non-nil.
"POST"
(let ((url-request-data
(when args
- (mapconcat (lambda (arg)
- (concat (url-hexify-string (car arg))
- "="
- (url-hexify-string (cdr arg))))
- args
- "&")))
+ (mastodon-http--build-query-string args)))
(url-request-extra-headers
(append url-request-extra-headers ; auth set in macro
;; pleroma compat:
@@ -216,7 +223,9 @@ Optionally specify the PARAMS to send."
Optionally specify the PARAMS to send."
(mastodon-http--authorized-request
"PATCH"
- (let ((url (mastodon-http--append-query-string base-url params)))
+ (let ((url
+ (concat base-url "?"
+ (mastodon-http--build-query-string params))))
(mastodon-http--url-retrieve-synchronously url))))
;; Asynchronous functions
@@ -245,12 +254,7 @@ Authorization header is included by default unless UNAUTHENTICED-P is non-nil."
(let ((request-timeout 5)
(url-request-data
(when args
- (mapconcat (lambda (arg)
- (concat (url-hexify-string (car arg))
- "="
- (url-hexify-string (cdr arg))))
- args
- "&"))))
+ (mastodon-http--build-query-string args))))
(with-temp-buffer
(url-retrieve url callback cbargs)))))