aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-http.el
diff options
context:
space:
mode:
authorJohnson Denen <johnson.denen@gmail.com>2017-04-08 13:34:45 -0400
committerjdenen <Johnson.Denen@ascenaretail.com>2017-04-09 08:55:37 -0400
commitcce134294df7021e94b414ced616741ee6a4ffcb (patch)
tree61452cf06f031e6a3cab3f06dfa96ff3ff4c3c34 /lisp/mastodon-http.el
parentb3faec5e80687b1c944e39dc2290922d133b5e65 (diff)
Update DOCSTRINGs
Diffstat (limited to 'lisp/mastodon-http.el')
-rw-r--r--lisp/mastodon-http.el23
1 files changed, 18 insertions, 5 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el
index acfda8f..f8cb60d 100644
--- a/lisp/mastodon-http.el
+++ b/lisp/mastodon-http.el
@@ -21,39 +21,52 @@ Response buffer is passed to the CALLBACK function."
(url-retrieve url callback)))
(defun mastodon--response-buffer ()
+ "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)
+ "Returns substring matching PATTERN from `mastodon--response-buffer'."
(let ((resp (mastodon--response-buffer)))
(progn
(string-match pattern resp)
(match-string 0 resp))))
(defun mastodon--response-match-p (pattern)
+ "Returns non-nil if `mastodon--response-buffer' matches PATTERN."
(let ((resp (mastodon--response-buffer)))
(string-match-p pattern resp)))
(defun mastodon--response-status-p ()
+ "Returns non-nil if `mastodon--response-buffer' has an HTTP Response Status-Line."
(when (mastodon--response-match-p "^HTTP/1.*$") t))
(defun mastodon--response-json ()
- (mastodon--response-body-substring "\{.*\}"))
+ "Returns string of JSON response body from `mastodon--response-buffer'."
+ (mastodon--response-body-substring "\{.*\}"))
(defun mastodon--response-code ()
+ "Returns HTTP Response Status Code from `mastodon--response-buffer'."
(let* ((status-line (mastodon--response-body-substring "^HTTP/1.*$")))
- (progn
- (string-match "[0-9][0-9][0-9]" status-line)
- (match-string 0 status-line))))
+ (progn
+ (string-match "[0-9][0-9][0-9]" status-line)
+ (match-string 0 status-line))))
(defun mastodon--json-hash-table ()
- "Reads JSON string from `mastodon--response-json' into a hash table."
+ "Reads 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))