R/update_node.R

Defines functions update_node

Documented in update_node

#' update_node
#'
#' Update an existing DKAN node
#'
#' @param nid character: DKAN node ID
#' @param url character: The DKAN site URL
#' @param body json: A JSON object to be passed to the body of the request
#' @param credentials Optional list parameter. Default values are Cookie and Token generated by dkan_setup()
#' @param as character: Output format. Options are: 'json' or 'list'
#' @param ... Other optional parameters passed to the underlying GET request
#'
#' @return dkan_node object
#' @export
#'
#' @examples
#' \dontrun{
#' update_node(nid = 1, url = "http://demo.getdkan.com")
#' }

update_node <- function(nid,
                        url = get_url(),
                        body,
                        credentials = list(
                          cookie = dkanr::get_cookie(),
                          token = dkanr::get_token()
                        ),
                        as = "json",
                        ...) {
  # CHECK: input validity
  assertthat::assert_that(
    !is.null(nid),
    msg = "The Node ID (nid) argument must be specified"
  )
  res <- dkan_PUT(url = url, nid = nid, body, credentials = credentials, ...)
  switch(as, json = res, list = as_dk(jsl(res), "dkan_node"))
}
tonyfujs/dkanr documentation built on May 28, 2019, 4:03 p.m.