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.el38
1 files changed, 29 insertions, 9 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el
index f8cb60d..9dbad6f 100644
--- a/lisp/mastodon-http.el
+++ b/lisp/mastodon-http.el
@@ -1,13 +1,32 @@
+;;; mastodon-http.el --- HTTP request/response functions for mastodon.el
+
+;;; Commentary:
+
+;; mastodon.el is an Emacs client for Mastodon, the federated microblogging
+;; social network. It is very much a work-in-progress, but it is a labor of
+;; love.
+
+;; mastodon-http.el provides HTTP request/response functions.
+
+;;; Code:
+
(require 'mastodon)
+(require 'json)
+
+(defgroup mastodon-http nil
+ "HTTP requests and responses for Mastodon."
+ :prefix "mastodon-http-"
+ :group 'mastodon)
(defun mastodon--api-for (endpoint)
- "Returns Mastondon API URL for ENDPOINT."
+ "Return Mastondon API URL for ENDPOINT."
(concat mastodon-instance-url "/api/" mastodon--api-version "/" endpoint))
(defun mastodon--http-post (url callback args &optional headers)
- "Sends ARGS to URL as a POST request.
+ "Make POST request to URL.
-Response buffer is passed to the CALLBACK function."
+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))
@@ -26,34 +45,34 @@ Response buffer is passed to the CALLBACK function."
(buffer-substring-no-properties (point-min) (point-max))))
(defun mastodon--response-body-substring (pattern)
- "Returns substring matching PATTERN from `mastodon--response-buffer'."
+ "Return 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."
+ "Return 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."
+ "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 ()
- "Returns string of JSON response body from `mastodon--response-buffer'."
+ "Return 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'."
+ "Return 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))))
(defun mastodon--json-hash-table ()
- "Reads JSON from `mastodon--response-json' into a 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))
@@ -74,3 +93,4 @@ If response code is not 2XX, switches to the response buffer created by `url-ret
(switch-to-buffer (current-buffer))))
(provide 'mastodon-http)
+;;; mastodon-http.el ends here