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

    add coerce arg to fedi-arg-when-expr, coerce to str if number
---
 fedi.el | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/fedi.el b/fedi.el
index ba26f2c1aad..87044aa1796 100644
--- a/fedi.el
+++ b/fedi.el
@@ -130,7 +130,7 @@ Used to construct function names in `fedi-request'.")
 ;; to define functions, so must be called with all possible arguments, rather
 ;; than only those of a given function call.
 ;; Still, it solves the problem of the server rejecting nil param values.
-(defun fedi-arg-when-expr (arg)
+(defun fedi-arg-when-expr (arg &optional coerce)
   "Return a cons of a string and a symbol type of ARG.
 Also replace _ with - (for Lemmy's type_ param)."
   (let ((str
@@ -138,15 +138,20 @@ Also replace _ with - (for Lemmy's type_ param)."
                          (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 ,arg))))
+    (if coerce
+        `(when ,arg
+           (cons ,str (if (numberp ,arg)
+                          (number-to-string ,arg)
+                        ,arg)))
+      `(when ,arg
+         (cons ,str ,arg)))))
 
 ;; (fedi-arg-when-expr 'sort)
 
-(defun fedi-make-params-alist (args fun)
+(defun fedi-make-params-alist (args fun &optional coerce)
   "Call FUN on each of ARGS."
   (cl-loop while args
-           collecting (funcall fun (pop args))))
+           collecting (funcall fun (pop args) coerce)))
 
 ;; (fedi-make-params-alist '(sort type))
 

Reply via email to