aboutsummaryrefslogtreecommitdiff
path: root/sx-request.el
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2015-01-02 00:15:09 -0500
committerSean Allred <code@seanallred.com>2015-01-02 00:15:09 -0500
commit5babd59dfd51b5dd33cfd411fc2c2754adf63381 (patch)
tree8c0b7127f535547c210bdc08ff8f589f58ab31af /sx-request.el
parente05f937910bb4ca0e7ea1c9f1273fbafac523921 (diff)
Add process-function to sx-request-make
Diffstat (limited to 'sx-request.el')
-rw-r--r--sx-request.el16
1 files changed, 12 insertions, 4 deletions
diff --git a/sx-request.el b/sx-request.el
index bc34f9c..f1d20af 100644
--- a/sx-request.el
+++ b/sx-request.el
@@ -95,13 +95,13 @@ number of requests left every time it finishes a call."
;;; Making Requests
-(defun sx-request-make (method &optional args request-method)
+(defun sx-request-make (method &optional args request-method process-function)
"Make a request to the API, executing METHOD with ARGS.
You should almost certainly be using `sx-method-call' instead of
this function. REQUEST-METHOD is one of `GET' (default) or `POST'.
-Returns cleaned response content.
-See (`sx-encoding-clean-content-deep').
+Returns the entire response as processed by PROCESS-FUNCTION.
+This defaults to `sx-request-response-get-items'.
The full set of arguments is built with
`sx-request--build-keyword-arguments', prepending
@@ -164,7 +164,8 @@ the main content of the response is returned."
sx-request-remaining-api-requests-message-threshold)
(sx-message "%d API requests remaining"
sx-request-remaining-api-requests))
- (sx-encoding-clean-content-deep .items)))))))
+ (funcall (or process-function #'sx-request-response-get-items)
+ response)))))))
(defun sx-request-fallback (_method &optional _args _request-method)
"Fallback method when authentication is not available.
@@ -205,6 +206,13 @@ false, use the symbol `false'. Each element is processed with
alist))
"&")))
+
+;;; Response Processors
+(defun sx-request-response-get-items (response)
+ "Returns the items from RESPONSE."
+ (sx-assoc-let response
+ (sx-encoding-clean-content-deep .items)))
+
(provide 'sx-request)
;;; sx-request.el ends here