diff options
| author | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2022-09-12 21:34:19 +0200 | 
|---|---|---|
| committer | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2022-09-12 21:34:19 +0200 | 
| commit | f5697f658cd8cbd608da36acf5d24850966831b7 (patch) | |
| tree | 07769a33e22c11f574c88bb79cfe38f4bb2c162d /lisp | |
| parent | c4ffff95371c25937bc61c86e72011a69fa3c078 (diff) | |
factor out http--build-query-string for use PATCH reqs also
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/mastodon-http.el | 32 | 
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)))))  | 
