psolymos / clickrup

Interacting with the ClickUp v2 API from R
https://peter.solymos.org/clickrup/
MIT License
18 stars 3 forks source link

Tibble output via tibblify #5

Open krlmlr opened 3 years ago

krlmlr commented 3 years ago

The tibblify package allows for a much more robust approach than jsonlite::fromJSON(simplifyVector = TRUE) . We can infer a schema from the data (as R code) and then use that schema when coercing the data to a tibble. This gives type stability at the highest level possible, while automating the generation of boilerplate code.

I used the following workflow:

This PR is not how PRs should be done. Unfortunately, the commits build one upon another. Can you please review the commits individually and let me know which you don't agree with?

How do we proceed? Would you like to pick up from here, do you need more help?

@mgirlich: I'm not sure why I had to do 7a93fc7 manually, why this wasn't inferred from the data.

psolymos commented 3 years ago

Thank you @krlmlr this looks like a nice way of tibblifying the responses. Let me check your additions and try to do the same for a few more endpoints to see if anything unexpected comes up with the approach.

I also like the testing to be based on the mock Apiary server. This can be added to the cu_ functions too.

I am also wondering if adding the cuf_ functions can be automated using your workflow to add new functions and tests. I would like to either (1) keep related functions in the same file, or (2) be able to sort them to see those next to each other (cu-xxx.R and cu-xxx-tb.R for alphabetical sorting).

krlmlr commented 3 years ago

Thanks.

I added a few tests for cu_*() .

I only have a semi-automatic way of adding the cuf_*() wrappers -- see script/tibblify.R. Most likely we need to refine what tibblify::get_spec() returns; we also want to e.g. convert ClickUp times to proper times. I kept related functions in the same file.

psolymos commented 3 years ago

The date handling can be done as lcol_dat("dob", .parser = ~ cu_date_from(.x)) [not tested, just inferred from docs].

Do you think the inverse-tibblify could work for POST requests? Or should we restrict the scope here to GET requests?

krlmlr commented 3 years ago

Let's focus on GET first, need to understand the best structure for POST and friends.

krlmlr commented 3 years ago

One more thing: It might be useful to export the step that converts a cu_*() list to a tibble in a separate function, to aid debugging and reprexing.

mgirlich commented 3 years ago

@krlmlr Probably it was actually inferred from the data but just not printed as there was a bug in the printing :-/ Can you try out with the dev version?

krlmlr commented 2 years ago

I think the following getters would be most important in the beginning:

krlmlr commented 2 years ago

I'll take another stab here.

krlmlr commented 2 years ago

I added https://github.com/krlmlr/clickrup/blob/f-data-frame/script/README.md that describes the process and the next steps.

krlmlr commented 2 years ago

It looks like a few more days of work to complete this, including a test workspace and automated tests.

krlmlr commented 2 years ago

It looks like the mock API is still available, via https://private-anon-bcbe6af027-clickup20.apiary-mock.com/api . Need to double-check the access token.