Function: ghub-request
ghub-request is a byte-compiled function defined in ghub.el.
Signature
(ghub-request METHOD RESOURCE &optional PARAMS &key QUERY PAYLOAD HEADERS SILENT UNPAGINATE NOERROR READER USERNAME AUTH HOST FORGE CALLBACK ERRORBACK VALUE EXTRA)
Documentation
Make a request for RESOURCE and return the response body.
Also place the response headers in ghub-response-headers.
METHOD is the HTTP method, given as a string.
RESOURCE is the resource to access, given as a string beginning
with a slash.
PARAMS, QUERY, PAYLOAD and HEADERS are alists used to specify
data. The Github API documentation is vague on how data has
to be transmitted and for a particular resource usually just
talks about "parameters". Generally speaking when the METHOD
is "HEAD" or "GET", then they have to be transmitted as a
query, otherwise as a payload.
Use PARAMS to automatically transmit like QUERY or PAYLOAD would
depending on METHOD.
Use QUERY to explicitly transmit data as a query.
Use PAYLOAD to explicitly transmit data as a payload.
Instead of an alist, PAYLOAD may also be a string, in which
case it gets encoded as UTF-8 but is otherwise transmitted as-is.
Use HEADERS for those rare resources that require that the data
is transmitted as headers instead of as a query or payload.
When that is the case, then the API documentation usually
mentions it explicitly.
If SILENT is non-nil, then don't message progress reports and
the like.
If UNPAGINATE is t, then make as many requests as necessary to
get all values. If UNPAGINATE is a natural number, then get
at most that many pages. For any other non-nil value raise
an error.
If NOERROR is non-nil, then do not raise an error if the request
fails and return nil instead. If NOERROR is return, then
return the error payload instead of nil.
If READER is non-nil, then it is used to read and return from the
response buffer. The default is ghub--read-json-payload.
For the very few resources that do not return JSON, you might
want to use ghub--decode-payload.
If USERNAME is non-nil, then make a request on behalf of that
user. It is better to specify the user using the Git variable
github.user for "api.github.com", or github.HOST.user if
connecting to a Github Enterprise instance.
Each package that uses ghub should use its own token. If AUTH
is nil, then the generic ghub token is used instead. This
is only acceptable for personal utilities. A packages that
is distributed to other users should always use this argument
to identify itself, using a symbol matching its name.
Package authors who find this inconvenient should write a
wrapper around this function and possibly for the
method-specific functions as well.
Some symbols have a special meaning. none means to make an
unauthorized request. basic means to make a password based
request. If the value is a string, then it is assumed to be
a valid token. basic and an explicit token string are only
intended for internal and debugging uses.
If HOST is non-nil, then connect to that Github instance. This
defaults to "api.github.com". When a repository is connected
to a Github Enterprise instance, then it is better to specify
that using the Git variable github.host instead of using this
argument.
If optional FORGE is nil, then it is assumed that HOST is a
Github host. When connecting to another forge type, then
FORGE must be one of gitlab, gitea, gogs or bitbucket.
If CALLBACK and/or ERRORBACK is non-nil, then make one or more
asynchronous requests and call CALLBACK or ERRORBACK when
finished. If no error occurred, then call CALLBACK, unless
that is nil.
If an error occurred, then call ERRORBACK, or if that is nil,
then CALLBACK. ERRORBACK can also be t, in which case an error
is signaled instead. NOERROR is ignored for all asynchronous
requests.
Both callbacks are called with four arguments.
1. For CALLBACK, the combined value of the retrieved pages.
For ERRORBACK, the error that occurred when retrieving the
last page.
2. The headers of the last page as an alist.
3. Status information provided by url-retrieve. Its :error
property holds the same information as ERRORBACK's first
argument.
4. A ghub--req struct, which can be passed to ghub-continue
(which see) to retrieve the next page, if any.
Source Code
;; Defined in ~/.emacs.d/elpa/ghub-20260401.1239/ghub.el
(cl-defun ghub-request ( method resource
&optional params
&key query payload headers
silent unpaginate noerror reader
username auth host forge
callback errorback value extra)
"Make a request for RESOURCE and return the response body.
Also place the response headers in `ghub-response-headers'.
METHOD is the HTTP method, given as a string.
RESOURCE is the resource to access, given as a string beginning
with a slash.
PARAMS, QUERY, PAYLOAD and HEADERS are alists used to specify
data. The Github API documentation is vague on how data has
to be transmitted and for a particular resource usually just
talks about \"parameters\". Generally speaking when the METHOD
is \"HEAD\" or \"GET\", then they have to be transmitted as a
query, otherwise as a payload.
Use PARAMS to automatically transmit like QUERY or PAYLOAD would
depending on METHOD.
Use QUERY to explicitly transmit data as a query.
Use PAYLOAD to explicitly transmit data as a payload.
Instead of an alist, PAYLOAD may also be a string, in which
case it gets encoded as UTF-8 but is otherwise transmitted as-is.
Use HEADERS for those rare resources that require that the data
is transmitted as headers instead of as a query or payload.
When that is the case, then the API documentation usually
mentions it explicitly.
If SILENT is non-nil, then don't message progress reports and
the like.
If UNPAGINATE is t, then make as many requests as necessary to
get all values. If UNPAGINATE is a natural number, then get
at most that many pages. For any other non-nil value raise
an error.
If NOERROR is non-nil, then do not raise an error if the request
fails and return nil instead. If NOERROR is `return', then
return the error payload instead of nil.
If READER is non-nil, then it is used to read and return from the
response buffer. The default is `ghub--read-json-payload'.
For the very few resources that do not return JSON, you might
want to use `ghub--decode-payload'.
If USERNAME is non-nil, then make a request on behalf of that
user. It is better to specify the user using the Git variable
`github.user' for \"api.github.com\", or `github.HOST.user' if
connecting to a Github Enterprise instance.
Each package that uses `ghub' should use its own token. If AUTH
is nil, then the generic `ghub' token is used instead. This
is only acceptable for personal utilities. A packages that
is distributed to other users should always use this argument
to identify itself, using a symbol matching its name.
Package authors who find this inconvenient should write a
wrapper around this function and possibly for the
method-specific functions as well.
Some symbols have a special meaning. `none' means to make an
unauthorized request. `basic' means to make a password based
request. If the value is a string, then it is assumed to be
a valid token. `basic' and an explicit token string are only
intended for internal and debugging uses.
If HOST is non-nil, then connect to that Github instance. This
defaults to \"api.github.com\". When a repository is connected
to a Github Enterprise instance, then it is better to specify
that using the Git variable `github.host' instead of using this
argument.
If optional FORGE is nil, then it is assumed that HOST is a
Github host. When connecting to another forge type, then
FORGE must be one of `gitlab', `gitea', `gogs' or `bitbucket'.
If CALLBACK and/or ERRORBACK is non-nil, then make one or more
asynchronous requests and call CALLBACK or ERRORBACK when
finished. If no error occurred, then call CALLBACK, unless
that is nil.
If an error occurred, then call ERRORBACK, or if that is nil,
then CALLBACK. ERRORBACK can also be t, in which case an error
is signaled instead. NOERROR is ignored for all asynchronous
requests.
Both callbacks are called with four arguments.
1. For CALLBACK, the combined value of the retrieved pages.
For ERRORBACK, the error that occurred when retrieving the
last page.
2. The headers of the last page as an alist.
3. Status information provided by `url-retrieve'. Its `:error'
property holds the same information as ERRORBACK's first
argument.
4. A `ghub--req' struct, which can be passed to `ghub-continue'
(which see) to retrieve the next page, if any."
(declare (indent defun))
(cl-assert (or (booleanp unpaginate) (natnump unpaginate)))
(unless (string-prefix-p "/" resource)
(setq resource (concat "/" resource)))
(unless host
(setq host (ghub--host forge)))
(unless (or username (stringp auth) (eq auth 'none))
(setq username (ghub--username host forge)))
(cond ((not params))
((member method '("GET" "HEAD"))
(when query
(error "PARAMS and QUERY are mutually exclusive for METHOD %S"
method))
(setq query params))
(t
(when payload
(error "PARAMS and PAYLOAD are mutually exclusive for METHOD %S"
method))
(setq payload params)))
(when (or callback errorback)
(setq noerror t))
(ghub--retrieve
(ghub--encode-payload payload)
(ghub--make-req
:url (ghub--encode-url host resource query)
:forge forge
:silent silent
:method (encode-coding-string method 'utf-8) ;#35
:headers (ghub--headers headers host auth username forge)
:handler #'ghub--handle-response
:unpaginate unpaginate
:noerror noerror
:reader reader
:buffer (current-buffer)
:synchronous (not (or callback errorback))
:callback callback
:errorback errorback
:value value
:extra extra)))