R/womtool_api.R

# FireCloud
#
# FireCloud API 
#
# The version of the OpenAPI document: 0.1
# 
# Generated by: https://openapi-generator.tech

#' @docType class
#' @title Womtool operations
#' @description openapi.Womtool
#' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication.
#'
#' @section Methods:
#' \describe{
#' \strong{ Describe } \emph{ Machine-readable description of a workflow, including inputs and outputs }
#' 
#'
#' \itemize{
#' \item \emph{ @param } version character
#' \item \emph{ @param } workflow.source data.frame
#' \item \emph{ @param } workflow.url character
#' \item \emph{ @param } workflow.inputs data.frame
#' \item \emph{ @param } workflow.type Enum < [WDL, CWL] > 
#' \item \emph{ @param } workflow.type.version Enum < [draft-2, 1.0, v1.0] > 
#' \item \emph{ @returnType } \link{WorkflowDescription} \cr
#'
#'
#' \item status code : 200 | Workflow description.
#'
#' \item return type : WorkflowDescription 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' }
#'
#'
#' @examples
#' \dontrun{
#' ####################  Describe  ####################
#'
#' library(openapi)
#' var.version <- 'v1' # character | Cromwell API Version
#' var.workflow.source <- File.new('/path/to/file') # data.frame | The workflow source file to submit for execution. Either workflow source or workflow url is required.
#' var.workflow.url <- 'workflow.url_example' # character | URL which points to the workflow. Either workflow source or workflow url is required.
#' var.workflow.inputs <- File.new('/path/to/file') # data.frame | JSON or YAML file containing the inputs as an object.
#' var.workflow.type <- 'workflow.type_example' # character | The workflow language for the file you submitted. Cromwell currently supports WDL and CWL.
#' var.workflow.type.version <- 'workflow.type.version_example' # character | The specification version for the workflow language being used. For WDL, Cromwell currently supports draft-2 and 1.0. For CWL, Cromwell currently supports v1.0.
#'
#' #Machine-readable description of a workflow, including inputs and outputs
#' api.instance <- WomtoolApi$new()
#'
#' # Configure OAuth2 access token for authorization: googleoauth
#' api.instance$apiClient$accessToken <- 'TODO_YOUR_ACCESS_TOKEN';
#'
#' result <- api.instance$Describe(var.version, workflow.source=var.workflow.source, workflow.url=var.workflow.url, workflow.inputs=var.workflow.inputs, workflow.type=var.workflow.type, workflow.type.version=var.workflow.type.version)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom base64enc base64encode
#' @export
WomtoolApi <- R6::R6Class(
  'WomtoolApi',
  public = list(
    apiClient = NULL,
    initialize = function(apiClient){
      if (!missing(apiClient)) {
        self$apiClient <- apiClient
      }
      else {
        self$apiClient <- ApiClient$new()
      }
    },
    Describe = function(version, workflow.source=NULL, workflow.url=NULL, workflow.inputs=NULL, workflow.type=NULL, workflow.type.version=NULL, ...){
      apiResponse <- self$DescribeWithHttpInfo(version, workflow.source, workflow.url, workflow.inputs, workflow.type, workflow.type.version, ...)
      resp <- apiResponse$response
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        apiResponse$content
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        apiResponse
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        apiResponse
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        apiResponse
      }
    },

    DescribeWithHttpInfo = function(version, workflow.source=NULL, workflow.url=NULL, workflow.inputs=NULL, workflow.type=NULL, workflow.type.version=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

      if (missing(`version`)) {
        stop("Missing required parameter `version`.")
      }

      body <- list(
        "workflowSource" = httr::upload_file(workflow.source),
        "workflowUrl" = workflow.url,
        "workflowInputs" = httr::upload_file(workflow.inputs),
        "workflowType" = workflow.type,
        "workflowTypeVersion" = workflow.type.version
      )

      urlPath <- "/api/womtool/{version}/describe"
      if (!missing(`version`)) {
        urlPath <- gsub(paste0("\\{", "version", "\\}"), URLencode(as.character(`version`), reserved = TRUE), urlPath)
      }

      # OAuth token
      headerParams['Authorization'] <- paste("Bearer", self$apiClient$accessToken, sep=" ")

      resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
                                 method = "POST",
                                 queryParams = queryParams,
                                 headerParams = headerParams,
                                 body = body,
                                 ...)

      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        deserializedRespObj <- tryCatch(
          self$apiClient$deserialize(resp, "WorkflowDescription", loadNamespace("openapi")),
          error = function(e){
             stop("Failed to deserialize response")
          }
        )
        ApiResponse$new(deserializedRespObj, resp)
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp)
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        ApiResponse$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        ApiResponse$new("API server error", resp)
      }
    }
  )
)
vjcitn/terraClientR documentation built on Dec. 23, 2021, 4:07 p.m.