R/query.R

Defines functions query

Documented in query

#' Query workflows
#'
#' Query for workflows which match various criteria. When a combination of
#' criteria are applied the endpoint will return.
#'
#' @param x Cromwell API endpoint.
#' @param start Returns only workflows with an equal or later start datetime.
#' Can be specified at most once. If both start and end date are specified,
#' start date must be before or equal to end date.
#' @param end Returns only workflows with an equal or earlier end datetime.
#' Can be specified at most once. If both start and end date are specified,
#' start date must be before or equal to end date.
#' @param status Returns only workflows with the specified status. If specified
#' multiple times, returns workflows in any of the specified statuses.
#' @param name Returns only workflows with the specified name. If specified
#' multiple times, returns workflows with any of the specified names.
#' @param id ReturnsReturns only workflows with the specified workflow id.
#' If specified multiple times, returns workflows with any of the specified
#' workflow ids.
#' @param label Returns workflows with the specified label keys. If specified
#' multiple times, returns workflows with all of the specified label keys.
#' Specify the label key and label value pair as separated with
#' "label-key:label-value".
#' @param labelor Returns workflows with the specified label keys. If specified
#' multiple times, returns workflows with any of the specified label keys.
#' Specify the label key and label value pair as separated with
#' "label-key:label-value".
#' @param additionalQueryResultFields Includes the specified keys in the
#' metadata for the returned workflows.
#' @param version Cromwell API Version.
#'
#' @return A \code{data.frame}.
#'
#' @examples
#' \dontrun{
#' host <- "http://localhost:8000"
#' query(host)
#' }
#'
#' @export
query <- function(x, start = NULL, end = NULL, status = NULL, name = NULL,
	id = NULL, label = NULL, labelor = NULL, additionalQueryResultFields = NULL,
	version = "v1")
{
	url <- file.path(x, "api/workflows", version, "query")

	query <- list(start = start, end = end, status = status, name = name,
		id = id, label = label, labelor = labelor,
		additionalQueryResultFields = additionalQueryResultFields)
	query <- query[!sapply(query, is.null)]

	response <- httr::GET(url, query = query, cromwellAgent())

	if (httr::http_error(response)) {
		stop(paste0("Cromwell API request failed.
			Code: ", httr::status_code(response), "
			Message: ", jsonlite::fromJSON(httr::content(response, "text"))$message), call. = FALSE)
	}

	if (httr::http_type(response) != "application/json") {
		stop("API did not return json", call. = FALSE)
	}

	jsonlite::fromJSON(httr::content(response, "text"))$results
}
labbcb/CromwellClient documentation built on Aug. 16, 2020, 9:11 p.m.