Skip to content

tidy_policy_prepare() function #86

@jonthegeek

Description

@jonthegeek

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.

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions