aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-http.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/mastodon-http.el')
-rw-r--r--lisp/mastodon-http.el69
1 files changed, 8 insertions, 61 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el
index 3727e45..b41fccc 100644
--- a/lisp/mastodon-http.el
+++ b/lisp/mastodon-http.el
@@ -38,81 +38,28 @@
"Return Mastondon API URL for ENDPOINT."
(concat mastodon-instance-url "/api/" mastodon--api-version "/" endpoint))
-(defun mastodon--http-post (url callback args &optional headers)
- "This function should be phased out in favor of `mastodon-http--post'.
-
-Make POST request to URL.
-
-Response buffer is passed to CALLBACK function.
-ARGS and HEADERS alist arguments are part of the POST request."
- (let ((url-request-method "POST")
- (url-request-extra-headers
- (append '(("Content-Type" . "application/x-www-form-urlencoded")) headers))
- (url-request-data
- (mapconcat (lambda (arg)
- (concat (url-hexify-string (car arg))
- "="
- (url-hexify-string (cdr arg))))
- args
- "&")))
- (url-retrieve url callback)))
-
-(defun mastodon--response-buffer ()
+(defun mastodon-http--response ()
"Capture response buffer content as string."
(with-current-buffer (current-buffer)
(buffer-substring-no-properties (point-min) (point-max))))
-(defun mastodon--response-body-substring (pattern)
- "Return substring matching PATTERN from `mastodon--response-buffer'."
- (let ((resp (mastodon--response-buffer)))
+(defun mastodon-http--response-body (pattern)
+ "Return substring matching PATTERN from `mastodon-http--response'."
+ (let ((resp (mastodon-http--response)))
(progn
(string-match pattern resp)
(match-string 0 resp))))
-(defun mastodon--response-match-p (pattern)
- "Return non-nil if `mastodon--response-buffer' matches PATTERN."
- (let ((resp (mastodon--response-buffer)))
- (string-match-p pattern resp)))
-
-(defun mastodon--response-status-p ()
- "Return non-nil if `mastodon--response-buffer' has an HTTP Response Status-Line."
- (when (mastodon--response-match-p "^HTTP/1.*$") t))
-
-(defun mastodon--response-json ()
- "Return string of JSON response body from `mastodon--response-buffer'."
- (mastodon--response-body-substring "\{.*\}"))
-
-(defun mastodon--response-code ()
- "Return HTTP Response Status Code from `mastodon--response-buffer'."
- (let* ((status-line (mastodon--response-body-substring "^HTTP/1.*$")))
+(defun mastdon-http--status ()
+ "Return HTTP Response Status Code from `mastodon-http--response'."
+ (let* ((status-line (mastodon-http--response-body "^HTTP/1.*$")))
(progn
(string-match "[0-9][0-9][0-9]" status-line)
(match-string 0 status-line))))
-(defun mastodon--json-hash-table ()
- "Read JSON from `mastodon--response-json' into a hash table."
- (let ((json-object-type 'hash-table)
- (json-array-type 'list)
- (json-key-type 'string))
- (json-read-from-string (mastodon--response-json))))
-
-(defun mastodon--http-response-triage (status success)
- "Callback function to triage an HTTP response.
-
-Recursively waits for `mastodon--response-buffer' to contain a Status-Line.
-
-STATUS is passed by `url-retrieve'.
-SUCCESS is a function called on a 2XX level response code.
-If response code is not 2XX, switches to the response buffer created by `url-retrieve'."
- (when (not (mastodon--response-status-p))
- (mastodon--http-response-triage status))
- (if (string-prefix-p "2" (mastodon--response-code))
- (funcall success)
- (switch-to-buffer (current-buffer))))
-
(defun mastodon-http--triage (response success)
(let ((status (with-current-buffer response
- (mastodon--response-code))))
+ (mastdon-http--status))))
(if (string-prefix-p "2" status)
(funcall success)
(switch-to-buffer response))))