;;; Requests
(autoload 'auth-source-search "auth-source")
(cl-defmacro api--with-server-buffer (method url &rest body &key async unwind-form
- extra-headers &allow-other-keys)
+ auth extra-headers &allow-other-keys)
"Run BODY in a Server request buffer.
UNWIND-FORM is run no matter what, and doesn't affect the return
value."
(secret (make-symbol "secret")))
(while (keywordp (car body))
(setq body (cdr (cdr body))))
- `(let ((,call-name (lambda (status)
+ `(let ((,secret (when ,auth
+ (if (listp ,auth)
+ (or (car-safe (apply #'auth-source-search
+ :require '(:secret) :max 1
+ ,auth))
+ (user-error "This request requires authentication"))
+ (lambda () ,auth))))
+ (,call-name (lambda (status)
(unwind-protect
(progn (when-let ((er (plist-get status :error)))
(error "Error retrieving: %s %S" ,url er))
about the request \(next-page, quota, etc).
If ASYNC is non-nil, run the request asynchronously.
+AUTH is a list of arguments to pass to `auth-source-search'.
This function can also handle the pagination used in server
results by appending together the contents of each page. Use
`api-page-does-not-exist', and `api-infinite-redirection-loop',
all of which inherit from `api-error'.
-\(fn ACTION &key (METHOD :get) (READER #'json-read) CALLBACK ASYNC (MAX-PAGES 1) NEXT-PAGE-RULE EXTRA-HEADERS RETURN)"
- (declare (indent 1)
- (advertised-calling-convention
- ))
+\(fn ACTION &key AUTH (METHOD :get) (READER #'json-read) CALLBACK ASYNC (MAX-PAGES 1) NEXT-PAGE-RULE EXTRA-HEADERS RETURN)"
+ (declare (indent 1))
(unless (string-match "\\`https?://" action)
(setq action (concat api-root action)))
(when (member action -url-history)
(api--with-server-buffer method action
:extra-headers extra-headers
:-url-depth (cons action -url-history)
+ :auth auth
:async async
- (pcase (api-parse-response-code nil)
+ (pcase (api-parse-response-code auth)
(`nil nil)
((and (pred stringp) link)
(message "Redirected to %s" link)
(next-page . ,next-page)
,@(api--headers-alist))))
(api-action next-page
+ :auth auth
:method method
:reader reader
:next-page-rule next-page-rule