R/ApiClient.r

# Agave Platform Science API
#
# Power your digital lab and reduce the time from theory to discovery using the Agave Science-as-a-Service API Platform. Agave provides hosted services that allow researchers to manage data, conduct experiments, and publish and share results from anywhere at any time.
#
# Agave Platform version: 2.2.14
# 
# Generated by: https://github.com/swagger-api/swagger-codegen.git


#' ApiClient Class
#'
#' Generic API client for Swagger client library builds.
#' Swagger generic API client. This client handles the client-
#' server communication, and is invariant across implementations. Specifics of
#' the methods and models for each application are generated from the Swagger
#' templates.
#'
#' NOTE: This class is auto generated by the swagger code generator program.
#' Ref: https://github.com/swagger-api/swagger-codegen
#' Do not edit the class manually.
#'
#' @export
ApiClient  <- R6::R6Class(
  'ApiClient',
  public = list(
    basePath = "https://public.agaveapi.co",
    configuration = NULL,
    userAgent = NULL,
    defaultHeaders = NULL,
    initialize = function(basePath, configuration, defaultHeaders){
        if (!missing(basePath)) {
            self$basePath <- basePath
        }

        if (!missing(configuration)) {
            self$configuration <- configuration
        }

        if (!missing(defaultHeaders)) {
            self$defaultHeaders <- defaultHeaders
        }

        self$`userAgent` <- 'Swagger-Codegen/0.2.0/r'
    },
    callApi = function(url, method, queryParams, headerParams, body, ...){
        if (!missing(headerParams) && length(headerParams) > 0) {
          headers <- httr::add_headers(headerParams)
        }
        else {
          headers <- httr::add_headers(.headers = self$defaultHeaders)
        }

        # force naked responses to
        if (missing(queryParams)) {
          queryParams <- list(naked = "true")
        }
        else if (!("naked" %in% names(queryParams))){
          queryParams['naked'] = "true"
        }

        logger.info(paste0(c(url, paste0(lapply(names(queryParams), function(x) paste0(c(x,queryParams[x]), collapse = '=')), collapse = '&')), collapse = '?'))

        if (method == "GET") {
            httr::GET(url, query = queryParams, headers, ...)
        }
        else if (method == "POST") {
            httr::POST(url, query = queryParams, headers, body = body, ...)
        }
        else if (method == "PUT") {
            httr::PUT(url, query = queryParams, headers, body = body, ...)
        }
        else if (method == "PATCH") {
            httr::PATCH(url, query = queryParams, headers, body = body, ...)
        }
        else if (method == "HEAD") {
            httr::HEAD(url, query = queryParams, headers, ...)
        }
        else if (method == "DELETE") {
            httr::DELETE(url, query = queryParams, headers, ...)
        }
        else {
            stop("http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`.")
        }
    }
  )
)
deardooley/agave-rlang-sdk documentation built on May 17, 2019, 10:12 p.m.