R/headers.R

Defines functions getheads api_headers_ api_headers

Documented in api_headers api_headers_

#' Headers
#'
#' @export
#' @param .data Result of a call to \code{api}
#' @param ...	Key value pairs of headers
#' @param .dots	Used to work around non-standard evaluation
#' @examples \dontrun{
#' api('https://api.github.com/') %>%
#'    api_config(verbose()) %>%
#'    api_headers(`X-FARGO-SEASON` = 3) %>%
#'    peep
#'
#' api('http://httpbin.org/headers') %>%
#'    api_config(verbose()) %>%
#'    api_headers(`X-FARGO-SEASON` = 3, `X-NARCOS-SEASON` = 5)
#' }
api_headers <- function(.data, ..., .dots) {
  api_headers_(.data, .dots = lazyeval::lazy_dots(...))
}

#' @export
#' @rdname api_headers
api_headers_ <- function(.data, ..., .dots) {
  pipe_autoexec(toggle = TRUE)
  tmp <- lazyeval::all_dots(.dots, ...)
  .data <- as.req(.data)
  tmp <- getheads(tmp)
  .data$config <- combconfig(list(.data$config, tmp))
  return(.data)
}

getheads <- function(x) {
  tmp <- as.list(sapply(x, function(z) as.character(z$expr)))
  do.call(add_headers, tmp)
}
sckott/request documentation built on Aug. 11, 2018, 6:11 p.m.