diff options
-rw-r--r-- | sx-interaction.el | 23 | ||||
-rw-r--r-- | sx-method.el | 28 |
2 files changed, 31 insertions, 20 deletions
diff --git a/sx-interaction.el b/sx-interaction.el index 3d60cbe..e534984 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -230,14 +230,7 @@ Interactively, it is guessed from context at point. With the UNDO prefix argument, unfavorite the question instead." (interactive (list (sx--error-if-unread (sx--data-here 'question)) current-prefix-arg)) - (sx-assoc-let data - (sx-method-call 'questions - :id .question_id - :submethod (if undo 'favorite/undo 'favorite) - :auth 'warn - :site .site_par - :url-method 'post - :filter sx-browse-filter))) + (sx-method-post-from-data data (if undo 'favorite/undo 'favorite))) (defalias 'sx-star #'sx-favorite) @@ -268,18 +261,8 @@ DATA can be a question, answer, or comment. TYPE can be Besides posting to the api, DATA is also altered to reflect the changes." (let ((result - (sx-assoc-let data - (sx-method-call - (cond - (.comment_id "comments") - (.answer_id "answers") - (.question_id "questions")) - :id (or .comment_id .answer_id .question_id) - :submethod (concat type (unless status "/undo")) - :auth 'warn - :url-method 'post - :filter sx-browse-filter - :site .site_par)))) + (sx-method-post-from-data + data (concat type (unless status "/undo"))))) ;; The api returns the new DATA. (when (> (length result) 0) (sx--copy-data (elt result 0) data) diff --git a/sx-method.el b/sx-method.el index 9d61e60..f2e68b3 100644 --- a/sx-method.el +++ b/sx-method.el @@ -142,6 +142,34 @@ Return the entire response as a complex alist." url-method (or get-all process-function)))) +(defun sx-method-post-from-data (data &rest keys) + "Make a POST `sx-method-call', deriving parameters from DATA. +KEYS are [KEYWORD VALUE] pairs passed to `sx-method-call', except +the following which are decided by this function: + + METHOD :site and :id are derived from DATA, where METHOD is + either \"answers\", \"comments\", or \"questions\". + :url-method is post. + :filter is `sx-browse-filter'. + :auth is warn. + +As a special exception, if KEYS is a single argument, it is +assumed to be the :submethod argument." + (declare (indent 1)) + (sx-assoc-let data + (apply #'sx-method-call + (cond (.comment_id "comments") + (.answer_id "answers") + (.question_id "questions")) + :id (or .comment_id .answer_id .question_id) + :auth 'warn + :url-method 'post + :filter sx-browse-filter + :site .site_par + (if (= 1 (length keys)) + (cons :submethod keys) + keys)))) + (provide 'sx-method) ;;; sx-method.el ends here |