R/rs_list_task.R

Defines functions rs_list_task

Documented in rs_list_task

#' AppEEARS list of tasks and status
#'
#' Returns a data frame of all submitted tasks either
#' in full of when providing the di
#'
#' @param user username used to sign up
#' @param task_id task for which to list the status (if missing
#'  all tasks are listed)
#' @return returns a data frame with the AppEEARS tasks
#'
#' @export
#' @author Koen Hufkens
#' @examples
#'
#' \dontrun{
#' # get a list of datasets
#' rs_list_task()
#'}

rs_list_task <- function(
  task_id,
  user
){

  # retrieve token to list tasks
  token <- rs_login(user)

  # grab the content on a product query
  # and convert to data frame which is returned
  if(missing(task_id)){
    ct <- httr::GET(
      file.path(rs_server(),"task"),
      httr::add_headers(
        Authorization = paste("Bearer", token),
        "Content-Type" = "application/json")
      )
  } else {
    ct <- httr::GET(
      file.path(rs_server(),"task", task_id),
      httr::add_headers(
        Authorization = paste("Bearer", token),
        "Content-Type" = "application/json")
      )
  }

  # split out the content from the returned
  # API data, and clean up the JSON formatting
  ct <- jsonlite::prettify(
    jsonlite::toJSON(httr::content(ct), auto_unbox = TRUE)
  )

  # convert the json data to a data frame
  df <- jsonlite::fromJSON(ct)

  # return content
  return(df)
}

Try the appeears package in your browser

Any scripts or data that you put into this service are public.

appeears documentation built on Sept. 15, 2023, 5:06 p.m.