diff options
author | Johnson Denen <johnson.denen@gmail.com> | 2017-04-07 09:33:39 -0400 |
---|---|---|
committer | jdenen <Johnson.Denen@ascenaretail.com> | 2017-04-09 08:53:21 -0400 |
commit | 54263c53842c8d68e587e5b5d79e14681698b00b (patch) | |
tree | 2765a64deea20520744f82735dc24d2070845f54 /lisp/mastodon-http.el | |
parent | e91facdb643a6a340207c51f648565fcfcb029d3 (diff) |
Restructure under lisp directory
Diffstat (limited to 'lisp/mastodon-http.el')
-rw-r--r-- | lisp/mastodon-http.el | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el new file mode 100644 index 0000000..22c8c3f --- /dev/null +++ b/lisp/mastodon-http.el @@ -0,0 +1,34 @@ +(defun mastodon--api-for (endpoint) + "Returns 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. + +Response buffer is passed to the CALLBACK function." + (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-json (status) + "Returns JSON string from `mastodon--http-post' response buffer." + (let ((resp (with-current-buffer (current-buffer) + (buffer-substring-no-properties (point-min) (point-max))))) + (progn + (string-match "\{.*\}" resp) + (match-string 0 resp)))) + +(defun mastodon--json-hash-table (status) + "Reads JSON string 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 status)))) |