Summary
As an API-wrapping package developer, in order to reuse tidy policies, I would like to define tidy policies independent of a request.
This is very similar to #81. The changes made in PR #83 should inform this work.
Propose signature
tidy_policy_prepare(tidy_fn, ...)
Also export version of this corresponding to these functions:
resp_tidy_json()
resp_tidy_unknown()
resp_body_auto()
tidy_policy_json(spec = NULL, unspecified = "list", subset_path = NULL)
tidy_policy_unknown(call = rlang::caller_env())
tidy_policy_body_auto(call = rlang::caller_env())
Arguments
tidy_fn (function) A function that will be invoked by [resp_tidy()] to tidy a response.
... (any) Arguments to pass to tidy_fn.
Value
A list with class "nectar_tidy_policy" and elements tidy_fn and tidy_args.
Behavior
This function is really just a nectar_tidy_policy constructor. The function itself will be very simple, but it has a number of downstream effects.
Details
I've never liked the tidy_fn + tidy_args pattern in req_prepare(). Instead, update req_prepare (in R/req_prepare.R) to take tidy_policy as an argument (instead of tidy_fn + tidy_args). Also add tidy_policy_json() in R/resp_tidy_json.R, which calls tidy_policy_prepare() with tidy_fn= resp_tidy_json and the arguments passed into tidy_policy_json(). Do equivalents in R/resp_tidy_unknown.R and R/resp_body_auto.R. Then update vignettes/nectar.Rmd to show this updated pattern (instead of tidy_fn + tidy_args). We'll also need to update parameter definitions in R/aaa-shared_params.R (since tidy_args won't be used anymore), and make sure any examples that reference the old pattern are updated.
This will be a breaking change, but that is ok since this will be implemented before the initial CRAN release.
Note: We may still change aspects of resp_tidy() and resp_prepare() since they have a number of overlaps, but this fix should focus on the changes noted above; we'll deal with changes to resp_tidy() and/or resp_parse() in a future issue.
Summary
This is very similar to #81. The changes made in PR #83 should inform this work.
Propose signature
Also export version of this corresponding to these functions:
resp_tidy_json()resp_tidy_unknown()resp_body_auto()Arguments
tidy_fn(function) A function that will be invoked by [resp_tidy()] to tidy a response....(any) Arguments to pass totidy_fn.Value
A list with class
"nectar_tidy_policy"and elementstidy_fnandtidy_args.Behavior
This function is really just a
nectar_tidy_policyconstructor. The function itself will be very simple, but it has a number of downstream effects.Details
I've never liked the
tidy_fn+tidy_argspattern inreq_prepare(). Instead, updatereq_prepare(inR/req_prepare.R) to taketidy_policyas an argument (instead oftidy_fn+tidy_args). Also addtidy_policy_json()inR/resp_tidy_json.R, which callstidy_policy_prepare()withtidy_fn= resp_tidy_jsonand the arguments passed intotidy_policy_json(). Do equivalents inR/resp_tidy_unknown.RandR/resp_body_auto.R. Then updatevignettes/nectar.Rmdto show this updated pattern (instead oftidy_fn+tidy_args). We'll also need to update parameter definitions inR/aaa-shared_params.R(sincetidy_argswon't be used anymore), and make sure any examples that reference the old pattern are updated.This will be a breaking change, but that is ok since this will be implemented before the initial CRAN release.
Note: We may still change aspects of
resp_tidy()andresp_prepare()since they have a number of overlaps, but this fix should focus on the changes noted above; we'll deal with changes toresp_tidy()and/orresp_parse()in a future issue.