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.el34
1 files changed, 28 insertions, 6 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el
index 66707b7..843afc1 100644
--- a/lisp/mastodon-http.el
+++ b/lisp/mastodon-http.el
@@ -89,8 +89,11 @@ Message status and JSON error from RESPONSE if unsuccessful."
(if (string-prefix-p "2" status)
(funcall success)
(switch-to-buffer response)
- (let ((json-response (mastodon-http--process-json)))
- (message "Error %s: %s" status (alist-get 'error json-response))))))
+ ;; 404 returns http response not JSON:
+ (if (string-prefix-p "404" status)
+ (message "Error %s: page not found" status)
+ (let ((json-response (mastodon-http--process-json)))
+ (message "Error %s: %s" status (alist-get 'error json-response)))))))
(defun mastodon-http--read-file-as-string (filename)
"Read a file FILENAME as a string. Used to generate image preview."
@@ -203,12 +206,31 @@ Callback to `mastodon-http--get-response-async', usually
(cons (car list) (cadr list))))
head-list)))
-(defun mastodon-http--delete (url)
+(defun mastodon-http--delete (url &optional args)
"Make DELETE request to URL."
+ (let ((url-request-data
+ (when args
+ (mastodon-http--build-query-string args))))
+ (mastodon-http--authorized-request
+ "DELETE"
+ (with-temp-buffer
+ (mastodon-http--url-retrieve-synchronously url)))))
+
+(defun mastodon-http--put (url &optional args headers)
+ "Make PUT request to URL."
(mastodon-http--authorized-request
- "DELETE"
- (with-temp-buffer
- (mastodon-http--url-retrieve-synchronously url))))
+ "PUT"
+ (let ((url-request-data
+ (when args
+ (mastodon-http--build-query-string args)))
+ (url-request-extra-headers
+ (append url-request-extra-headers ; auth set in macro
+ ;; pleroma compat:
+ (unless (assoc "Content-Type" headers)
+ '(("Content-Type" . "application/x-www-form-urlencoded")))
+ headers)))
+ (with-temp-buffer
+ (mastodon-http--url-retrieve-synchronously url)))))
(defun mastodon-http--append-query-string (url params)
"Append PARAMS to URL as query strings and return it.