R/query_api.R

# TileDB Storage Platform API
#
# TileDB Storage Platform REST API
#
# The version of the OpenAPI document: 2.2.19
# 
# Generated by: https://openapi-generator.tech

#' @docType class
#' @title Query operations
#' @description tiledbcloud.Query
#' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication.
#'
#' @section Methods:
#' \describe{
#' \strong{ FinalizeQuery } \emph{  }
#' send a query to run against a specified array/URI registered to a group/project
#'
#' \itemize{
#' \item \emph{ @param } namespace character
#' \item \emph{ @param } array character
#' \item \emph{ @param } type character
#' \item \emph{ @param } content.type character
#' \item \emph{ @param } query \link{Query}
#' \item \emph{ @param } x.payer character
#' \item \emph{ @param } open.at integer
#' \item \emph{ @returnType } \link{Query} \cr
#'
#'
#' \item status code : 200 | query completed and results are returned in query object
#'
#' \item return type : Query 
#' \item response headers :
#'
#' \tabular{ll}{
#' X-TILEDB-CLOUD-TASK-ID \tab Task ID for just completed request \cr
#' }
#' \item status code : 204 | query completed successfully with no return
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 0 | error response
#'
#' \item return type : Error 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ GetEstResultSizes } \emph{  }
#' send a query to run against a specified array/URI registered to a group/project
#'
#' \itemize{
#' \item \emph{ @param } namespace character
#' \item \emph{ @param } array character
#' \item \emph{ @param } type character
#' \item \emph{ @param } content.type character
#' \item \emph{ @param } query \link{Query}
#' \item \emph{ @param } x.payer character
#' \item \emph{ @param } open.at integer
#' \item \emph{ @returnType } \link{Query} \cr
#'
#'
#' \item status code : 200 | query est result size computed and results are returned in query object
#'
#' \item return type : Query 
#' \item response headers :
#'
#' \tabular{ll}{
#' X-TILEDB-CLOUD-TASK-ID \tab Task ID for just completed request \cr
#' }
#' \item status code : 204 | query completed successfully with no return
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 0 | error response
#'
#' \item return type : Error 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ GetFile } \emph{  }
#' send a query to run against a specified array/URI registered to a group/project, returns file bytes
#'
#' \itemize{
#' \item \emph{ @param } namespace character
#' \item \emph{ @param } array character
#' \item \emph{ @param } content.type character
#' \item \emph{ @param } x.payer character
#'
#'
#' \item status code : 200 | query completed and result bytes are returned
#'
#' \item return type : data.frame 
#' \item response headers :
#'
#' \tabular{ll}{
#' X-TILEDB-CLOUD-TASK-ID \tab Task ID for just completed request \cr
#' }
#' \item status code : 0 | error response
#'
#' \item return type : Error 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ SubmitQuery } \emph{  }
#' send a query to run against a specified array/URI registered to a group/project
#'
#' \itemize{
#' \item \emph{ @param } namespace character
#' \item \emph{ @param } array character
#' \item \emph{ @param } type character
#' \item \emph{ @param } content.type character
#' \item \emph{ @param } query \link{Query}
#' \item \emph{ @param } x.payer character
#' \item \emph{ @param } open.at integer
#' \item \emph{ @returnType } \link{Query} \cr
#'
#'
#' \item status code : 200 | query completed and results are returned in query object
#'
#' \item return type : Query 
#' \item response headers :
#'
#' \tabular{ll}{
#' X-TILEDB-CLOUD-TASK-ID \tab Task ID for just completed request \cr
#' }
#' \item status code : 204 | query completed successfully with no return
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 0 | error response
#'
#' \item return type : Error 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ SubmitQueryJson } \emph{  }
#' send a query to run against a specified array/URI registered to a group/project, returns JSON results
#'
#' \itemize{
#' \item \emph{ @param } namespace character
#' \item \emph{ @param } array character
#' \item \emph{ @param } content.type character
#' \item \emph{ @param } query.json \link{QueryJson}
#' \item \emph{ @param } x.payer character
#'
#'
#' \item status code : 200 | query completed and results are returned in JSON format
#'
#' \item return type : object 
#' \item response headers :
#'
#' \tabular{ll}{
#' X-TILEDB-CLOUD-TASK-ID \tab Task ID for just completed request \cr
#' }
#' \item status code : 0 | error response
#'
#' \item return type : Error 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' }
#'
#'
#' @examples
#' \dontrun{
#' ####################  FinalizeQuery  ####################
#'
#' library(tiledbcloud)
#' var.namespace <- 'namespace_example' # character | namespace array is in (an organization name or user's username)
#' var.array <- 'array_example' # character | name/uri of array that is url-encoded
#' var.type <- 'type_example' # character | type of query
#' var.content.type <- 'application/json' # character | Content Type of input and return mime
#' var.query <- Query$new() # Query | query to run
#' var.x.payer <- 'x.payer_example' # character | Name of organization or user who should be charged for this request
#' var.open.at <- 56 # integer | open_at for array in unix epoch
#'
#' api.instance <- QueryApi$new()
#'
#' #Configure API key authorization: ApiKeyAuth
#' api.instance$apiClient$apiKeys['X-TILEDB-REST-API-KEY'] <- 'TODO_YOUR_API_KEY';
#'
#' #Configure HTTP basic authorization: BasicAuth
#' # provide your username in the user-serial format
#' api.instance$apiClient$username <- '<user-serial>'; 
#' # provide your api key generated using the developer portal
#' api.instance$apiClient$password <- '<api_key>';
#'
#' result <- api.instance$FinalizeQuery(var.namespace, var.array, var.type, var.content.type, var.query, x.payer=var.x.payer, open.at=var.open.at)
#'
#'
#' ####################  GetEstResultSizes  ####################
#'
#' library(tiledbcloud)
#' var.namespace <- 'namespace_example' # character | namespace array is in (an organization name or user's username)
#' var.array <- 'array_example' # character | name/uri of array that is url-encoded
#' var.type <- 'type_example' # character | type of query
#' var.content.type <- 'application/json' # character | Content Type of input and return mime
#' var.query <- Query$new() # Query | query to run
#' var.x.payer <- 'x.payer_example' # character | Name of organization or user who should be charged for this request
#' var.open.at <- 56 # integer | open_at for array in unix epoch
#'
#' api.instance <- QueryApi$new()
#'
#' #Configure API key authorization: ApiKeyAuth
#' api.instance$apiClient$apiKeys['X-TILEDB-REST-API-KEY'] <- 'TODO_YOUR_API_KEY';
#'
#' #Configure HTTP basic authorization: BasicAuth
#' # provide your username in the user-serial format
#' api.instance$apiClient$username <- '<user-serial>'; 
#' # provide your api key generated using the developer portal
#' api.instance$apiClient$password <- '<api_key>';
#'
#' result <- api.instance$GetEstResultSizes(var.namespace, var.array, var.type, var.content.type, var.query, x.payer=var.x.payer, open.at=var.open.at)
#'
#'
#' ####################  GetFile  ####################
#'
#' library(tiledbcloud)
#' var.namespace <- 'namespace_example' # character | namespace array is in (an organization name or user's username)
#' var.array <- 'array_example' # character | name/uri of array that is url-encoded
#' var.content.type <- 'application/json' # character | Content Type of input and return mime
#' var.x.payer <- 'x.payer_example' # character | Name of organization or user who should be charged for this request
#'
#' api.instance <- QueryApi$new()
#'
#' #Configure API key authorization: ApiKeyAuth
#' api.instance$apiClient$apiKeys['X-TILEDB-REST-API-KEY'] <- 'TODO_YOUR_API_KEY';
#'
#' #Configure HTTP basic authorization: BasicAuth
#' # provide your username in the user-serial format
#' api.instance$apiClient$username <- '<user-serial>'; 
#' # provide your api key generated using the developer portal
#' api.instance$apiClient$password <- '<api_key>';
#'
#' result <- api.instance$GetFile(var.namespace, var.array, var.content.type, x.payer=var.x.payer)
#'
#'
#' ####################  SubmitQuery  ####################
#'
#' library(tiledbcloud)
#' var.namespace <- 'namespace_example' # character | namespace array is in (an organization name or user's username)
#' var.array <- 'array_example' # character | name/uri of array that is url-encoded
#' var.type <- 'type_example' # character | type of query
#' var.content.type <- 'application/json' # character | Content Type of input and return mime
#' var.query <- Query$new() # Query | query to run
#' var.x.payer <- 'x.payer_example' # character | Name of organization or user who should be charged for this request
#' var.open.at <- 56 # integer | open_at for array in unix epoch
#'
#' api.instance <- QueryApi$new()
#'
#' #Configure API key authorization: ApiKeyAuth
#' api.instance$apiClient$apiKeys['X-TILEDB-REST-API-KEY'] <- 'TODO_YOUR_API_KEY';
#'
#' #Configure HTTP basic authorization: BasicAuth
#' # provide your username in the user-serial format
#' api.instance$apiClient$username <- '<user-serial>'; 
#' # provide your api key generated using the developer portal
#' api.instance$apiClient$password <- '<api_key>';
#'
#' result <- api.instance$SubmitQuery(var.namespace, var.array, var.type, var.content.type, var.query, x.payer=var.x.payer, open.at=var.open.at)
#'
#'
#' ####################  SubmitQueryJson  ####################
#'
#' library(tiledbcloud)
#' var.namespace <- 'namespace_example' # character | namespace array is in (an organization name or user's username)
#' var.array <- 'array_example' # character | name/uri of array that is url-encoded
#' var.content.type <- 'application/json' # character | Content Type of input and return mime
#' var.query.json <- QueryJson$new() # QueryJson | query to run
#' var.x.payer <- 'x.payer_example' # character | Name of organization or user who should be charged for this request
#'
#' api.instance <- QueryApi$new()
#'
#' #Configure API key authorization: ApiKeyAuth
#' api.instance$apiClient$apiKeys['X-TILEDB-REST-API-KEY'] <- 'TODO_YOUR_API_KEY';
#'
#' #Configure HTTP basic authorization: BasicAuth
#' # provide your username in the user-serial format
#' api.instance$apiClient$username <- '<user-serial>'; 
#' # provide your api key generated using the developer portal
#' api.instance$apiClient$password <- '<api_key>';
#'
#' result <- api.instance$SubmitQueryJson(var.namespace, var.array, var.content.type, var.query.json, x.payer=var.x.payer)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom base64enc base64encode
#' @export
QueryApi <- R6::R6Class(
  'QueryApi',
  public = list(
    apiClient = NULL,
    initialize = function(apiClient){
      if (!missing(apiClient)) {
        self$apiClient <- apiClient
      }
      else {
        self$apiClient <- ApiClient$new()
      }
    },
    FinalizeQuery = function(namespace, array, type, content.type, query, x.payer=NULL, open.at=NULL, ...){
      apiResponse <- self$FinalizeQueryWithHttpInfo(namespace, array, type, content.type, query, x.payer, open.at, ...)
      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
      }
    },

    FinalizeQueryWithHttpInfo = function(namespace, array, type, content.type, query, x.payer=NULL, open.at=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

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

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

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

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

      headerParams['Content-Type'] <- `content.type`

      headerParams['X-Payer'] <- `x.payer`

      queryParams['type'] <- type

      queryParams['open_at'] <- open.at

      if (!missing(`query`)) {
        body <- `query`$toJSONString()
      } else {
        body <- NULL
      }

      urlPath <- "/arrays/{namespace}/{array}/query/finalize"
      if (!missing(`namespace`)) {
        urlPath <- gsub(paste0("\\{", "namespace", "\\}"), URLencode(as.character(`namespace`), reserved = TRUE), urlPath)
      }

      if (!missing(`array`)) {
        urlPath <- gsub(paste0("\\{", "array", "\\}"), URLencode(as.character(`array`), reserved = TRUE), urlPath)
      }

      # API key authentication
      if ("X-TILEDB-REST-API-KEY" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["X-TILEDB-REST-API-KEY"]) > 0) {
        headerParams['X-TILEDB-REST-API-KEY'] <- paste(unlist(self$apiClient$apiKeys["X-TILEDB-REST-API-KEY"]), collapse='')
      }
      # HTTP basic auth
      headerParams['Authorization'] <- paste("Basic", base64enc::base64encode(charToRaw(paste(self$apiClient$username, self$apiClient$password, 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, "Query", loadNamespace("tiledbcloud")),
          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)
      }
    },
    GetEstResultSizes = function(namespace, array, type, content.type, query, x.payer=NULL, open.at=NULL, ...){
      apiResponse <- self$GetEstResultSizesWithHttpInfo(namespace, array, type, content.type, query, x.payer, open.at, ...)
      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
      }
    },

    GetEstResultSizesWithHttpInfo = function(namespace, array, type, content.type, query, x.payer=NULL, open.at=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

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

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

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

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

      headerParams['Content-Type'] <- `content.type`

      headerParams['X-Payer'] <- `x.payer`

      queryParams['type'] <- type

      queryParams['open_at'] <- open.at

      if (!missing(`query`)) {
        body <- `query`$toJSONString()
      } else {
        body <- NULL
      }

      urlPath <- "/arrays/{namespace}/{array}/query/est_result_sizes"
      if (!missing(`namespace`)) {
        urlPath <- gsub(paste0("\\{", "namespace", "\\}"), URLencode(as.character(`namespace`), reserved = TRUE), urlPath)
      }

      if (!missing(`array`)) {
        urlPath <- gsub(paste0("\\{", "array", "\\}"), URLencode(as.character(`array`), reserved = TRUE), urlPath)
      }

      # API key authentication
      if ("X-TILEDB-REST-API-KEY" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["X-TILEDB-REST-API-KEY"]) > 0) {
        headerParams['X-TILEDB-REST-API-KEY'] <- paste(unlist(self$apiClient$apiKeys["X-TILEDB-REST-API-KEY"]), collapse='')
      }
      # HTTP basic auth
      headerParams['Authorization'] <- paste("Basic", base64enc::base64encode(charToRaw(paste(self$apiClient$username, self$apiClient$password, 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, "Query", loadNamespace("tiledbcloud")),
          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)
      }
    },
    GetFile = function(namespace, array, content.type, x.payer=NULL, ...){
      apiResponse <- self$GetFileWithHttpInfo(namespace, array, content.type, x.payer, ...)
      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
      }
    },

    GetFileWithHttpInfo = function(namespace, array, content.type, x.payer=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

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

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

      headerParams['Content-Type'] <- `content.type`

      headerParams['X-Payer'] <- `x.payer`

      body <- NULL
      urlPath <- "/arrays/{namespace}/{array}/query/get_file"
      if (!missing(`namespace`)) {
        urlPath <- gsub(paste0("\\{", "namespace", "\\}"), URLencode(as.character(`namespace`), reserved = TRUE), urlPath)
      }

      if (!missing(`array`)) {
        urlPath <- gsub(paste0("\\{", "array", "\\}"), URLencode(as.character(`array`), reserved = TRUE), urlPath)
      }

      # API key authentication
      if ("X-TILEDB-REST-API-KEY" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["X-TILEDB-REST-API-KEY"]) > 0) {
        headerParams['X-TILEDB-REST-API-KEY'] <- paste(unlist(self$apiClient$apiKeys["X-TILEDB-REST-API-KEY"]), collapse='')
      }
      # HTTP basic auth
      headerParams['Authorization'] <- paste("Basic", base64enc::base64encode(charToRaw(paste(self$apiClient$username, self$apiClient$password, sep=":"))))

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

      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        deserializedRespObj <- tryCatch(
          self$apiClient$deserialize(resp, "data.frame", loadNamespace("tiledbcloud")),
          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)
      }
    },
    SubmitQuery = function(namespace, array, type, content.type, query, x.payer=NULL, open.at=NULL, ...){
      apiResponse <- self$SubmitQueryWithHttpInfo(namespace, array, type, content.type, query, x.payer, open.at, ...)
      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
      }
    },

    SubmitQueryWithHttpInfo = function(namespace, array, type, content.type, query, x.payer=NULL, open.at=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

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

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

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

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

      headerParams['Content-Type'] <- `content.type`

      headerParams['X-Payer'] <- `x.payer`

      queryParams['type'] <- type

      queryParams['open_at'] <- open.at

      if (!missing(`query`)) {
        body <- `query`$toJSONString()
      } else {
        body <- NULL
      }

      urlPath <- "/arrays/{namespace}/{array}/query/submit"
      if (!missing(`namespace`)) {
        urlPath <- gsub(paste0("\\{", "namespace", "\\}"), URLencode(as.character(`namespace`), reserved = TRUE), urlPath)
      }

      if (!missing(`array`)) {
        urlPath <- gsub(paste0("\\{", "array", "\\}"), URLencode(as.character(`array`), reserved = TRUE), urlPath)
      }

      # API key authentication
      if ("X-TILEDB-REST-API-KEY" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["X-TILEDB-REST-API-KEY"]) > 0) {
        headerParams['X-TILEDB-REST-API-KEY'] <- paste(unlist(self$apiClient$apiKeys["X-TILEDB-REST-API-KEY"]), collapse='')
      }
      # HTTP basic auth
      headerParams['Authorization'] <- paste("Basic", base64enc::base64encode(charToRaw(paste(self$apiClient$username, self$apiClient$password, 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, "Query", loadNamespace("tiledbcloud")),
          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)
      }
    },
    SubmitQueryJson = function(namespace, array, content.type, query.json, x.payer=NULL, ...){
      apiResponse <- self$SubmitQueryJsonWithHttpInfo(namespace, array, content.type, query.json, x.payer, ...)
      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
      }
    },

    SubmitQueryJsonWithHttpInfo = function(namespace, array, content.type, query.json, x.payer=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

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

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

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

      headerParams['Content-Type'] <- `content.type`

      headerParams['X-Payer'] <- `x.payer`

      if (!missing(`query.json`)) {
        body <- `query.json`$toJSONString()
      } else {
        body <- NULL
      }

      urlPath <- "/arrays/{namespace}/{array}/query/submit_query_json"
      if (!missing(`namespace`)) {
        urlPath <- gsub(paste0("\\{", "namespace", "\\}"), URLencode(as.character(`namespace`), reserved = TRUE), urlPath)
      }

      if (!missing(`array`)) {
        urlPath <- gsub(paste0("\\{", "array", "\\}"), URLencode(as.character(`array`), reserved = TRUE), urlPath)
      }

      # API key authentication
      if ("X-TILEDB-REST-API-KEY" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["X-TILEDB-REST-API-KEY"]) > 0) {
        headerParams['X-TILEDB-REST-API-KEY'] <- paste(unlist(self$apiClient$apiKeys["X-TILEDB-REST-API-KEY"]), collapse='')
      }
      # HTTP basic auth
      headerParams['Authorization'] <- paste("Basic", base64enc::base64encode(charToRaw(paste(self$apiClient$username, self$apiClient$password, 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, "object", loadNamespace("tiledbcloud")),
          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)
      }
    }
  )
)
eddelbuettel/tldbclr documentation built on Sept. 25, 2022, 12:46 p.m.