From 94096714aef5088cce1a1c75aadf925e82d82a40 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 15 Jan 2015 16:26:36 -0200 Subject: Implement question-get-from-comment --- sx-question.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sx-question.el b/sx-question.el index 1adbc24..35eabc8 100644 --- a/sx-question.el +++ b/sx-question.el @@ -72,6 +72,26 @@ If ANSWER-ID doesn't exist on SITE, raise an error." (error "Couldn't find answer %S in %S" answer-id site)))) +(defun sx-question-get-from-comment (site comment-id) + "Get question from SITE to which COMMENT-ID belongs. +If COMMENT-ID doesn't exist on SITE, raise an error. + +Note this requires two API requests. One for the comment and one +for the post." + (let ((res (sx-method-call 'comments + :id comment-id + :site site + :auth t + :filter sx-browse-filter))) + (unless (vectorp res) + (error "Couldn't find comment %S in %S" comment-id site)) + (sx-assoc-let (elt res 0) + (funcall (if (string= .post_type "answer") + #'sx-question-get-from-answer + #'sx-question-get-question) + .site_par + .post_id)))) + ;;; Question Properties -- cgit v1.2.3