rdrop2
rdrop2 copied to clipboard
create request wrapper
There's a pattern we keep repeating, particularly for the functions that are super-simple wrappers of the underlying API:
drop_foobar <- function(
arg1,
arg2 = TRUE,
arg3 = FALSE,
dtoken = get_dropbox_token
) {
url <- "https://api.dropbox.com/2/foobar"
req <- httr::POST(
url = url,
httr::config(token = dtoken),
body = list(
arg1 = arg1,
arg2 = arg2,
arg3 = arg2
),
encode = "json"
)
httr::stop_for_status(req
httr::content(req)
}
I think centralizing this as an internal function would make refactoring different things much easier, esp. if we want to do anything fancier across the board. Could import or replicate purrr::lst
to auto-name body
components, and have some kind of additional or elipsis args for customizing in the stranger cases.
This should also allow us to wrap many more endpoints with a bit less effort.
Not worth the effort for 0.8, but wanted to make note of it for 0.9.