Add raw option to avandu--send-command-sync

This is useful for functions that need to check something outside of
the "content" list of the result.  Probably all of them should though.

* avandu.el (avandu--send-command-sync): New parameter: raw.  Return
  the content part of the results if RAW is nil, otherwise return the
  results onmodified.

  (avandu-login): Pass a RAW argument to `avandu--send-command-sync'.
This commit is contained in:
Tom Willemsen 2012-08-23 09:21:47 +02:00
parent bc17d87497
commit e8a8a700a4

View file

@ -368,7 +368,7 @@ FUNC should be a callback function as defined by
(unless (url-retrieve avandu-tt-rss-api-url func) (unless (url-retrieve avandu-tt-rss-api-url func)
(message "Complete.")))) (message "Complete."))))
(defun avandu--send-command-sync (data) (defun avandu--send-command-sync (data &optional raw)
"Send a command with parameters DATA to tt-rss. The current "Send a command with parameters DATA to tt-rss. The current
session-id is added to the request and then DATA is passed on to session-id is added to the request and then DATA is passed on to
`json-encode'. `json-encode'.
@ -378,8 +378,9 @@ For example:
(avandu--send-command-sync '((op . \"isLoggedIn\"))) (avandu--send-command-sync '((op . \"isLoggedIn\")))
This function returns the result of `json-read' passed over the This function returns the content part of the result of
returned json." `json-read' passed over the returned json, unless RAW is non-nil,
in which case the result is returned as-is."
(let* ((url-request-data (avandu--prep-params data)) (let* ((url-request-data (avandu--prep-params data))
(url-request-method "POST") (url-request-method "POST")
(buffer (url-retrieve-synchronously avandu-tt-rss-api-url)) (buffer (url-retrieve-synchronously avandu-tt-rss-api-url))
@ -389,7 +390,9 @@ returned json."
(search-forward "\n\n") (search-forward "\n\n")
(setq result (json-read))) (setq result (json-read)))
(kill-buffer buffer) (kill-buffer buffer)
(avu-prop result content))) (if (not raw)
(avu-prop result content)
result)))
(defun avandu-categories (&optional unread) (defun avandu-categories (&optional unread)
"Get the created categories. If UNREAD is non-nil only get "Get the created categories. If UNREAD is non-nil only get
@ -554,7 +557,7 @@ otherwise."
(let ((result (avandu--send-command-sync (let ((result (avandu--send-command-sync
`((op . "login") `((op . "login")
(user . ,avandu-user) (user . ,avandu-user)
(password . ,(avandu--password)))))) (password . ,(avandu--password))) t)))
(if (eq (avandu--get-status-id result) 0) (if (eq (avandu--get-status-id result) 0)
(progn (progn
(setq avandu--session-id (avandu--get-session-id result)) (setq avandu--session-id (avandu--get-session-id result))