federicotdn / verb

Organize and send HTTP requests from Emacs
https://melpa.org/#/verb
GNU General Public License v3.0
540 stars 20 forks source link

Allow users to apply functions to response object #60

Open bigodel opened 11 months ago

bigodel commented 11 months ago

As discussed in !59, this PR adds the ability for users to define a VERB-MAP-RESPONSE (respecting verb--metadata-prefix) property to apply a function to the response object.

It also adds:

  1. The function verb--fn-form that takes care of returning a function object from a form, or signaling errors if it couldn't parse it as a function object (previously this was done in verb--request-spec-post-process, but now we need the same behaviour in two different places). It also checks for if the arglist for the parsed function object expects exactly one argument. This could be tweaked in the future, but for now since this function is internal to the library and we're only using it to map requests and responses I guess it makes sens to keep this check.

  2. The variable verb--response-original-buffer (I'm accpeting naming suggestions) to store the buffer from where the request was made. It's a permanent local variable. It could either be the current-buffer when the request was made with Org babel and the response goes into the same buffer, or the response buffer generated by verb--generate-response-buffer.

    I'm using it to allow users to call verb-set-var (and change other buffer local values) in the VERB-MAP-RESPONSE callback and have the variables set to the right buffer, without having to resort to getting the buffer from other window like in my personal solution, since users might tweak their display-buffer-alist among other things.