branch: elpa/fedi
commit cd80e502c1d0ceab1e5bd5d3884a17a9acbe2abc
Author: marty hiatt <martianhiatus [a t] riseup [d o t] net>
Commit: marty hiatt <martianhiatus [a t] riseup [d o t] net>

    handle params and manual-params in fedi-request
---
 fedi.el | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/fedi.el b/fedi.el
index 7fe6343b5cb..a1201eecdb7 100644
--- a/fedi.el
+++ b/fedi.el
@@ -51,13 +51,13 @@
 Used to construct function names in `fedi-request'.")
 
 (defmacro fedi-request
-    (method name endpoint &optional args docstring params auth-param json 
headers)
+    (method name endpoint
+            &optional args docstring params man-params json headers)
   "Create a http request function NAME, using http METHOD, for ENDPOINT.
 ARGS are for the function.
-PARAMS is an alist of form parameters to send with the request.
-AUTH-PARAM is a single-item alist, to append to params. It is a
-separate arg so that this macro can be wrapped with another one
-handling auth for all functions that need it.
+PARAMS is an list of elements from which to build an alist of
+form parameters to send with the request.
+MAN-PARAMS is an alist, to append to the one created from PARAMS.
 JSON means to encode params as a JSON payload.
 HEADERS is an alist that will be bound as `url-request-extra-headers'.
 
@@ -84,16 +84,17 @@ This macro doesn't handle authenticated requests, as these 
differ
 between services. But you can easily wrap it in another macro
 that handles auth by providing info using HEADERS or AUTH-PARAM."
   (declare (debug t)
-           (indent 2))
+           (indent 3))
   (let ((req-fun (intern (concat "fedi-http--" method))))
     `(defun ,(intern (concat fedi-package-prefix "-" name)) ,args
        ,docstring
        (let* ((req-url (fedi-http--api ,endpoint))
               (url-request-method ,(upcase method))
               (url-request-extra-headers ,headers)
-              (params-alist (list ,@(fedi-make-params-alist params)))
-              (params (if ,auth-param
-                          (append ,auth-param params-alist)
+              (params-alist (remove nil
+                                    (list ,@(fedi-make-params-alist params))))
+              (params (if ',man-params
+                          (append ,man-params params-alist)
                         params-alist))
               (response
                (cond ((or (equal ,method "post")
@@ -111,6 +112,8 @@ that handles auth by providing info using HEADERS or 
AUTH-PARAM."
   (let ((str
          (string-replace "-" "_" ; for "type_"
                          (symbol-name arg))))
+    ;; FIXME: when the when test fails, it adds nil to the list in the 
expansion.
+    ;; so we have to call (remove nil) on the result.
     `(when ,arg
        (cons ,str
              ;;(symbol-name arg)

Reply via email to