From ea0ae945fa4168e01669973e1cb31c2834db9377 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Tue, 2 Apr 2013 11:56:33 +0100 Subject: Implement helper function for POSTING plists as JSON Returns JSON response content as a plist --- nnttrss.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/nnttrss.el b/nnttrss.el index 06eab1a..41a217d 100644 --- a/nnttrss.el +++ b/nnttrss.el @@ -20,6 +20,27 @@ (defvar nnttrss-session-id nil "Current session id, if any, set after successful login.") + + +(defun nnttrss-post-request (content address) + "POST CONTENT to ADDRESS as urlencoded form data. CONTENT must +be a data structure that `json-encode' knows how to encode as a +JSON object. Returns the JSON response as a plist or nil." + (let ((url-request-method "POST") + (url-request-data (json-encode content)) + (json-object-type 'plist) + (json-false nil)) + (with-current-buffer (url-retrieve-synchronously address) + (goto-char (point-min)) + (search-forward-regexp "\n\n") + (let* ((response (json-read)) + (status (plist-get response :status)) + (content (plist-get response :content))) + (if (= status 0) content + (nnheader-report 'nnttrss (plist-get content :error))))))) + + + (gnus-declare-backend "nnttrss" 'address 'prompt-address) (provide 'nnttrss) -- cgit v1.2.3