aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-http.el
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-05-10 09:22:25 +0200
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-05-10 09:22:25 +0200
commit8520659c0908a553a7c646fe788bbc64deea903b (patch)
tree2cf34a90430c7ce5647ec7d41973e818dfa415d1 /lisp/mastodon-http.el
parent2e4ec6b3bb98d18eff6a6d2048cab82eb517fb20 (diff)
refactor concat-params-to-url, replace append-query string
Diffstat (limited to 'lisp/mastodon-http.el')
-rw-r--r--lisp/mastodon-http.el56
1 files changed, 20 insertions, 36 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el
index 49ffbf8..9d9b6e4 100644
--- a/lisp/mastodon-http.el
+++ b/lisp/mastodon-http.el
@@ -147,19 +147,21 @@ Authorization header is included by default unless UNAUTHENTICATED-P is non-nil.
(with-temp-buffer
(mastodon-http--url-retrieve-synchronously url)))
unauthenticated-p))
+(defun mastodon-http--concat-params-to-url (url params)
+ "Build a query string with PARAMS and concat to URL."
+ (if params
+ (concat url "?"
+ (mastodon-http--build-params-string params))
+ url))
(defun mastodon-http--get (url &optional params silent)
"Make synchronous GET request to URL.
PARAMS is an alist of any extra parameters to send with the request.
SILENT means don't message."
- (mastodon-http--authorized-request
- "GET"
- ;; url-request-data doesn't seem to work with GET requests:
- (let ((url (if params
- (concat url "?"
- (mastodon-http--build-params-string params))
- url)))
- (mastodon-http--url-retrieve-synchronously url silent))))
+ (mastodon-http--authorized-request "GET"
+ ;; url-request-data doesn't seem to work with GET requests?:
+ (let ((url (mastodon-http--concat-params-to-url url params)))
+ (mastodon-http--url-retrieve-synchronously url silent))))
(defun mastodon-http--get-response (url &optional params no-headers silent vector)
"Make synchronous GET request to URL. Return JSON and response headers.
@@ -232,15 +234,10 @@ Callback to `mastodon-http--get-response-async', usually
"Make DELETE request to URL.
PARAMS is an alist of any extra parameters to send with the request."
;; url-request-data only works with POST requests?
- (let ((url
- (if params
- (concat url "?"
- (mastodon-http--build-params-string params))
- url)))
- (mastodon-http--authorized-request
- "DELETE"
- (with-temp-buffer
- (mastodon-http--url-retrieve-synchronously url)))))
+ (let ((url (mastodon-http--concat-params-to-url url params)))
+ (mastodon-http--authorized-request "DELETE"
+ (with-temp-buffer
+ (mastodon-http--url-retrieve-synchronously url)))))
(defun mastodon-http--put (url &optional params headers)
"Make PUT request to URL.
@@ -258,12 +255,6 @@ HEADERS is an alist of any extra headers to send with the request."
headers)))
(with-temp-buffer (mastodon-http--url-retrieve-synchronously url)))))
-(defun mastodon-http--append-query-string (url params)
- "Append PARAMS to URL as query strings and return it.
-PARAMS should be an alist as required by `url-build-query-string'."
- (let ((query-string (url-build-query-string params)))
- (concat url "?" query-string)))
-
;; profile update functions
(defun mastodon-http--patch-json (url &optional params)
@@ -275,12 +266,9 @@ Optionally specify the PARAMS to send."
(defun mastodon-http--patch (base-url &optional params)
"Make synchronous PATCH request to BASE-URL.
Optionally specify the PARAMS to send."
- (mastodon-http--authorized-request
- "PATCH"
- (let ((url
- (concat base-url "?"
- (mastodon-http--build-params-string params))))
- (mastodon-http--url-retrieve-synchronously url))))
+ (mastodon-http--authorized-request "PATCH"
+ (let ((url (mastodon-http--concat-params-to-url base-url params)))
+ (mastodon-http--url-retrieve-synchronously url))))
;; Asynchronous functions
@@ -288,13 +276,9 @@ Optionally specify the PARAMS to send."
"Make GET request to URL.
Pass response buffer to CALLBACK function with args CBARGS.
PARAMS is an alist of any extra parameters to send with the request."
- (let ((url (if params
- (concat url "?"
- (mastodon-http--build-params-string params))
- url)))
- (mastodon-http--authorized-request
- "GET"
- (url-retrieve url callback cbargs))))
+ (let ((url (mastodon-http--concat-params-to-url url params)))
+ (mastodon-http--authorized-request "GET"
+ (url-retrieve url callback cbargs))))
(defun mastodon-http--get-response-async (url &optional params callback &rest cbargs)
"Make GET request to URL. Call CALLBACK with http response and CBARGS.