aboutsummaryrefslogtreecommitdiff
path: root/sx-request.el
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2015-02-26 22:26:42 -0300
committerArtur Malabarba <bruce.connor.am@gmail.com>2015-02-26 22:26:42 -0300
commita603180449f9d17f5f7230638f43e3b2c6ecc363 (patch)
tree5f921eded79a1b1a068a1558d355ca9c9fe783a2 /sx-request.el
parentd8968604c6d2e11e5365031759069fb5a671f688 (diff)
parentee4e74f25fdb97faf4cb92952072a42b7b507e2a (diff)
Merge branch 'generate-header-line-from-keymap' into delete-command
Diffstat (limited to 'sx-request.el')
-rw-r--r--sx-request.el23
1 files changed, 14 insertions, 9 deletions
diff --git a/sx-request.el b/sx-request.el
index 8f672ec..d7fd058 100644
--- a/sx-request.el
+++ b/sx-request.el
@@ -221,29 +221,34 @@ Currently returns nil."
"https://raw.githubusercontent.com/vermiculus/sx.el/data/data/%s.el"
"Url of the \"data\" directory inside the SX `data' branch.")
-(defun sx-request-get-data (file)
- "Fetch and return data stored online by SX.
-FILE is a string or symbol, the name of the file which holds the
-desired data, relative to `sx-request--data-url-format'. For
-instance, `tags/emacs' returns the list of tags on Emacs.SE."
+(defun sx-request-get-url (url)
+ "Fetch and return data stored online at URL."
(let* ((url-automatic-caching t)
(url-inhibit-uncompression t)
- (request-url (format sx-request--data-url-format file))
(url-request-method "GET")
(url-request-extra-headers
'(("Content-Type" . "application/x-www-form-urlencoded")))
- (response-buffer (url-retrieve-synchronously request-url)))
+ (response-buffer (url-retrieve-synchronously url)))
(if (not response-buffer)
(error "Something went wrong in `url-retrieve-synchronously'")
(with-current-buffer response-buffer
(progn
(goto-char (point-min))
+ (unless (string-match "200" (thing-at-point 'line))
+ (error "Page not found."))
(if (not (search-forward "\n\n" nil t))
(error "Headers missing; response corrupt")
- (when (looking-at-p "Not Found") (error "Page not found."))
- (prog1 (read (current-buffer))
+ (prog1 (buffer-substring (point) (point-max))
(kill-buffer (current-buffer)))))))))
+(defun sx-request-get-data (file)
+ "Fetch and return data stored online by SX.
+FILE is a string or symbol, the name of the file which holds the
+desired data, relative to `sx-request--data-url-format'. For
+instance, `tags/emacs' returns the list of tags on Emacs.SE."
+ (read (sx-request-get-url
+ (format sx-request--data-url-format file))))
+
;;; Support Functions
(defun sx-request--build-keyword-arguments (alist &optional kv-sep)