diff options
-rw-r--r-- | nnttrss.el | 35 |
1 files changed, 22 insertions, 13 deletions
@@ -21,11 +21,15 @@ "Current session id, if any, set after successful login.") +;;; Session management -(defun nnttrss-post-request (content address) +(defun nnttrss-post-request (content address &optional property) "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." +JSON object. + +Returns the JSON response as a plist or, optionally, the PROPERTY +in the plist if the response status is 0, nil otherwise." (let ((url-request-method "POST") (url-request-data (json-encode content)) (json-object-type 'plist) @@ -36,31 +40,36 @@ JSON object. Returns the JSON response as a plist or nil." (let* ((response (json-read)) (status (plist-get response :status)) (content (plist-get response :content))) - (if (= status 0) content + (if (= status 0) + (if (plist-member content property) + (plist-get content property) + content) (nnheader-report 'nnttrss (plist-get content :error))))))) (defun nnttrss-login (address user password) "Login to the server at ADDRESS using USER and PASSWORD credentials. Returns a session id string or nil." - (let ((response (nnttrss-post-request `(:op "login" - :user ,user - :password ,password) - address))) - (plist-get response :session_id))) + (nnttrss-post-request `(:op "login" + :user ,user + :password ,password) + address + :session_id)) (defun nnttrss-logout (address session-id) "Logout of the server at ADDRESS using SESSION-ID credentials." (nnttrss-post-request `(:op "logout" :sid ,session-id) - address)) + address) + nil) (defun nnttrss-logged-in-p (address session-id) "Return t if there is a valid session at ADDRESS with SESSION-ID, false otherwise." - (let ((response (nnttrss-post-request `(:op "isLoggedIn" - :sid ,session-id) - address))) - (plist-get response :status))) + (nnttrss-post-request `(:op "isLoggedIn" + :sid ,session-id) + address + :status)) + |