blob: 69a4d7f0323f10295c824dbdd7d76de52378839a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
;;; sx-question.el --- question logic for stack-mode -*- lexical-binding: t; -*-
;; Copyright (C) 2014 Sean Allred
;; Author: Sean Allred <code@seanallred.com>
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'sx)
(require 'sx-filter)
(require 'sx-lto)
(require 'sx-method)
(defvar sx-question-browse-filter
'((question.body_markdown
question.comments
question.answers
question.last_editor
user.display_name
comment.owner
comment.body_markdown
comment.body
answer.last_editor
answer.owner
answer.body_markdown
answer.comments)
(user.profile_image shallow_user.profile_image)))
(defun sx-question-get-questions (site &optional page)
"Get the page PAGE of questions from SITE."
(sx-method-call
"questions"
`((site . ,site)
(page . ,page))
sx-question-browse-filter))
(defun sx-question-get-question (site id)
"Get the question ID from SITE."
(let ((res (sx-request-make
(format "questions/%s" id)
`((site . ,site))
sx-question-browse-filter)))
(if (vectorp res)
(elt res 0)
(error "Couldn't find question %s in %s" id site))))
;;; Question Properties
(defun sx-question--read-p (question)
"Non-nil if QUESTION has been read since last updated."
;; @TODO:
(cl-evenp (random)))
(defun sx-question--accepted-answer (question)
"Return accepted answer in QUESTION, or nil if none."
;; @TODO:
(cl-evenp (random)))
(defun sx-question--mark-read (question)
"Mark QUESTION as being read, until it is updated again."
nil)
(defun sx-question--< (property x y &optional pred)
"Non-nil if PROPERTY attribute of question X is less than that of Y.
With optional argument predicate, use it instead of `<'."
(funcall (or pred #'<)
(cdr (assoc property x))
(cdr (assoc property y))))
(defun sx-question--tag-format (tag)
"Formats TAG for display"
(concat "[" tag "]"))
(provide 'sx-question)
;;; sx-question.el ends here
;; Local Variables:
;; indent-tabs-mode: nil
;; End:
|