diff options
-rw-r--r-- | stack-core.el | 8 | ||||
-rw-r--r-- | stack-filter.el | 15 | ||||
-rw-r--r-- | stack-question.el | 24 | ||||
-rw-r--r-- | tests.el | 11 |
4 files changed, 32 insertions, 26 deletions
diff --git a/stack-core.el b/stack-core.el index 8badc3a..93eafda 100644 --- a/stack-core.el +++ b/stack-core.el @@ -142,7 +142,7 @@ with the given KEYWORD-ARGUMENTS." base (concat base "?" args)))) -(defun stack-core-make-request (method &optional keyword-arguments) +(defun stack-core-make-request (method &optional keyword-arguments filter) "Make a request to the StackExchange API using METHOD and optional KEYWORD-ARGUMENTS. If no KEYWORD-ARGUMENTS are given, `stack-core-default-keyword-arguments-alist' is used. Return the @@ -151,8 +151,10 @@ entire response as a complex alist." (json-read-from-string (let ((call (stack-core-build-request method - (cons `(filter . ,(if (boundp 'stack-core-filter) - stack-core-filter)) + (cons `(filter . ,(cond + (filter filter) + ((boundp 'stack-filter) + stack-filter))) (if keyword-arguments keyword-arguments (stack-core-get-default-keyword-arguments method))))) diff --git a/stack-filter.el b/stack-filter.el index e5d49d3..a406054 100644 --- a/stack-filter.el +++ b/stack-filter.el @@ -27,20 +27,13 @@ ;;; Dependencies -(if (boundp 'production) - (require 'stack-core) - (setq load-path (cons "." load-path)) - (load "stack-core.el")) +(require 'stack-core) ;;; Customizations -(defcustom stack-core-filter - (stack-core-compile-filter - nil ;don't include anything extra - '(user.profile_image ;don't include pictures (yet) - shallow_user.profile_image) ; - 'withbody) ;we want the body! +(defcustom stack-filter + 'default "The current filter. To customize the filter for the next call to `stack-core-make-request', let-bind this variable to the output of a call to `stack-core-compile-filter'. Be careful! If @@ -51,7 +44,7 @@ for it. Creation requests count against ;;; Filter compilation -(defun stack-core-compile-filter (&optional include exclude base) +(defun stack-filter-compile (&optional include exclude base) "Compile a StackExchange filter including fields from INCLUDE, excluding those from EXCLUDE, using BASE as a base filter. diff --git a/stack-question.el b/stack-question.el index 83247d8..13cc5e8 100644 --- a/stack-question.el +++ b/stack-question.el @@ -24,15 +24,21 @@ ;;; Code: -(if (boundp 'production) - (require 'stack-core) - (setq load-path (cons "." load-path)) - (load "stack-core.el")) - -(defun stack-question-parse (data) - "Parse and return the questions from DATA as returned by -`stack-core-make-request'" - (cdr (assoc 'items data))) +(require 'stack-core) +(require 'stack-filter) + +(defvar stack-question-browse-filter + (stack-filter-compile nil + '(user.profile_image shallow_user.profile_image))) + +(defun stack-question-get-questions (site &optional page) + "Get the page PAGE of questions from SITE." + (cdr (assoc 'items + (stack-core-make-request + "questions" + `((site . ,site) + (page . ,page)) + stack-question-browse-filter)))) (provide 'stack-question) ;;; stack-question.el ends here @@ -1,12 +1,17 @@ ;;; Tests (add-to-list 'load-path ".") + (require 'stack-core) +(require 'stack-question) -(setq *t (stack-core-make-request "questions")) +(setq + stack-tmp (stack-question-get-questions 'emacs) + stack-tmp-2 (stack-question-get-questions 'emacs 2)) -(prog1 t (prin1 (elt (stack-core-parse-questions *t) 0) - #'insert)) +(prog1 nil + (stack-message "%S" stack-tmp) + (stack-message "%S" stack-tmp-2)) (defun -stack--nuke () (interactive) |