aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorHolger Dürer <me@hdurer.net>2021-11-02 20:43:11 +0100
committerHolger Dürer <me@hdurer.net>2021-11-06 16:09:19 +0100
commit64bfd211fd48b674c1fa4d65d5b61ac86331d8e5 (patch)
tree105f1287f8c68f251fdff4427380033bfc9961d5 /lisp
parent93950dbee4165c733fd8e0a4938fd7d0f462d908 (diff)
Clean up uses of `url-retrieve-synchronously`.
We recently introduced a new thin abstraction `mastodon-http--url-retrieve-synchronously` but did not make use of it everywhere. This also moves its definition to the top above its first use. This also removes some dead, commented-out code.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mastodon-http.el40
1 files changed, 12 insertions, 28 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el
index a183ed7..3e27e13 100644
--- a/lisp/mastodon-http.el
+++ b/lisp/mastodon-http.el
@@ -67,15 +67,15 @@
(string-match "[0-9][0-9][0-9]" status-line)
(match-string 0 status-line)))
-;; (defun mastodon-http--triage (response success)
-;; "Determine if RESPONSE was successful. Call SUCCESS if successful.
+(defun mastodon-http--url-retrieve-synchronously (url)
+ "Retrieve URL asynchronously.
-;; Open RESPONSE buffer if unsuccessful."
-;; (let ((status (with-current-buffer response
-;; (mastodon-http--status))))
-;; (if (string-prefix-p "2" status)
-;; (funcall success)
-;; (switch-to-buffer response))))
+This is a thin abstraction over the system
+`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)
+ (url-retrieve-synchronously url nil nil mastodon-http--timeout)))
(defun mastodon-http--triage (response success)
"Determine if RESPONSE was successful. Call SUCCESS if successful.
@@ -115,9 +115,7 @@ Authorization header is included by default unless UNAUTHENTICED-P is non-nil."
`(("Authorization" . ,(concat "Bearer " (mastodon-auth--access-token)))))
headers)))
(with-temp-buffer
- (if (< (cdr (func-arity 'url-retrieve-synchronously)) 4)
- (url-retrieve-synchronously url)
- (url-retrieve-synchronously url nil nil mastodon-http--timeout)))))
+ (mastodon-http--url-retrieve-synchronously url))))
(defun mastodon-http--get (url)
"Make synchronous GET request to URL.
@@ -129,16 +127,6 @@ Pass response buffer to CALLBACK function."
(mastodon-auth--access-token))))))
(mastodon-http--url-retrieve-synchronously url)))
-(defun mastodon-http--url-retrieve-synchronously (url)
- "Retrieve URL asynchronously.
-
-This is a thin abstraction over the system
-`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)
- (url-retrieve-synchronously url nil nil mastodon-http--timeout)))
-
(defun mastodon-http--get-json (url)
"Make synchronous GET request to URL. Return JSON response."
(with-current-buffer (mastodon-http--get url)
@@ -163,7 +151,7 @@ is available we will call it with or without a timeout."
`(("Authorization" . ,(concat "Bearer "
(mastodon-auth--access-token))))))
(with-temp-buffer
- (url-retrieve-synchronously url))))
+ (mastodon-http--url-retrieve-synchronously url))))
;; search functions:
(defun mastodon-http--process-json-search ()
@@ -195,9 +183,7 @@ PARAM is a formatted request parameter, eg 'following=true'."
(url-request-extra-headers
`(("Authorization" . ,(concat "Bearer "
(mastodon-auth--access-token))))))
- (if (< (cdr (func-arity 'url-retrieve-synchronously)) 4)
- (url-retrieve-synchronously url)
- (url-retrieve-synchronously url nil nil mastodon-http--timeout))))
+ (mastodon-http--url-retrieve-synchronously url)))
;; profile update functions
@@ -218,9 +204,7 @@ Pass response buffer to CALLBACK function."
(url-request-extra-headers
`(("Authorization" . ,(concat "Bearer "
(mastodon-auth--access-token))))))
- (if (< (cdr (func-arity 'url-retrieve-synchronously)) 4)
- (url-retrieve-synchronously url)
- (url-retrieve-synchronously url nil nil mastodon-http--timeout))))
+ (mastodon-http--url-retrieve-synchronously url)))
;; Asynchronous functions