aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-http.el
diff options
context:
space:
mode:
authorJohnson Denen <johnson.denen@gmail.com>2017-04-13 08:59:34 -0400
committerJohnson Denen <johnson.denen@gmail.com>2017-04-14 13:18:14 -0400
commitf42d5e2666022c891f8561c24489bc52e9f4f642 (patch)
tree573e5e5913a356d38436dea2b2abccf4345bf2d6 /lisp/mastodon-http.el
parent523bf47c32d52d9bc99912d901ec5e6708f21fa5 (diff)
Use synchronous calls for simpler JSON parsing
Diffstat (limited to 'lisp/mastodon-http.el')
-rw-r--r--lisp/mastodon-http.el19
1 files changed, 16 insertions, 3 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el
index 91036be..b6cc879 100644
--- a/lisp/mastodon-http.el
+++ b/lisp/mastodon-http.el
@@ -109,12 +109,25 @@ If response code is not 2XX, switches to the response buffer created by `url-ret
(funcall success)
(switch-to-buffer (current-buffer))))
-(defun mastodon-http--get (url callback)
+(defun mastodon-http--get (url)
"Make GET request to URL.
Pass response buffer to CALLBACK function."
- (let ((url-request-method "GET"))
- (url-retrieve url callback)))
+ (let ((url-request-method "GET")
+ (url-request-extra-headers
+ `(("Authorization" . ,(concat "Bearer "
+ (mastodon--access-token))))))
+ (url-retrieve-synchronously url)))
+
+(defun mastodon-http--get-json (url)
+ "Make GET request to URL. Return JSON response vector."
+ (let ((json-vector
+ (with-current-buffer (mastodon-http--get url)
+ (goto-char (point-min))
+ (re-search-forward "^$" nil 'move)
+ (let ((json-string (buffer-substring-no-properties (point) (point-max))))
+ (json-read-from-string json-string)))))
+ json-vector))
(provide 'mastodon-http)
;;; mastodon-http.el ends here