rdrop2 icon indicating copy to clipboard operation
rdrop2 copied to clipboard

create request wrapper

Open ClaytonJY opened this issue 7 years ago • 0 comments

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.

ClaytonJY avatar Sep 23 '17 00:09 ClaytonJY