R/files_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 Files operations
#' @description tiledbcloud.Files
#' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication.
#'
#' @section Methods:
#' \describe{
#' \strong{ HandleCreateFile } \emph{  }
#' Create a tiledb file at the specified location
#'
#' \itemize{
#' \item \emph{ @param } namespace character
#' \item \emph{ @param } file.create \link{FileCreate}
#' \item \emph{ @param } X_TILEDB_CLOUD_ACCESS_CREDENTIALS_NAME character
#' \item \emph{ @returnType } \link{FileCreated} \cr
#'
#'
#' \item status code : 201 | File created
#'
#' \item return type : FileCreated 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 0 | error response
#'
#' \item return type : Error 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ HandleExportFile } \emph{  }
#' Export a TileDB File back to its original file format
#'
#' \itemize{
#' \item \emph{ @param } namespace character
#' \item \emph{ @param } file character
#' \item \emph{ @param } file.export \link{FileExport}
#' \item \emph{ @returnType } \link{FileExported} \cr
#'
#'
#' \item status code : 201 | File exported
#'
#' \item return type : FileExported 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 0 | error response
#'
#' \item return type : Error 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' }
#'
#'
#' @examples
#' \dontrun{
#' ####################  HandleCreateFile  ####################
#'
#' library(tiledbcloud)
#' var.namespace <- 'namespace_example' # character | The namespace of the file
#' var.file.create <- FileCreate$new() # FileCreate | Input/Output information to create a new TileDB file
#' var.X_TILEDB_CLOUD_ACCESS_CREDENTIALS_NAME <- 'X_TILEDB_CLOUD_ACCESS_CREDENTIALS_NAME_example' # character | Optional registered access credentials to use for creation
#'
#' api.instance <- FilesApi$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$HandleCreateFile(var.namespace, var.file.create, X_TILEDB_CLOUD_ACCESS_CREDENTIALS_NAME=var.X_TILEDB_CLOUD_ACCESS_CREDENTIALS_NAME)
#'
#'
#' ####################  HandleExportFile  ####################
#'
#' library(tiledbcloud)
#' var.namespace <- 'namespace_example' # character | The namespace of the file
#' var.file <- 'file_example' # character | The file identifier
#' var.file.export <- FileExport$new() # FileExport | Export configuration information
#'
#' api.instance <- FilesApi$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$HandleExportFile(var.namespace, var.file, var.file.export)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom base64enc base64encode
#' @export
FilesApi <- R6::R6Class(
  'FilesApi',
  public = list(
    apiClient = NULL,
    initialize = function(apiClient){
      if (!missing(apiClient)) {
        self$apiClient <- apiClient
      }
      else {
        self$apiClient <- ApiClient$new()
      }
    },
    HandleCreateFile = function(namespace, file.create, X_TILEDB_CLOUD_ACCESS_CREDENTIALS_NAME=NULL, ...){
      apiResponse <- self$HandleCreateFileWithHttpInfo(namespace, file.create, X_TILEDB_CLOUD_ACCESS_CREDENTIALS_NAME, ...)
      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
      }
    },

    HandleCreateFileWithHttpInfo = function(namespace, file.create, X_TILEDB_CLOUD_ACCESS_CREDENTIALS_NAME=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

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

      headerParams['X-TILEDB-CLOUD-ACCESS-CREDENTIALS-NAME'] <- `X_TILEDB_CLOUD_ACCESS_CREDENTIALS_NAME`

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

      urlPath <- "/files/{namespace}"
      if (!missing(`namespace`)) {
        urlPath <- gsub(paste0("\\{", "namespace", "\\}"), URLencode(as.character(`namespace`), 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, "FileCreated", 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)
      }
    },
    HandleExportFile = function(namespace, file, file.export, ...){
      apiResponse <- self$HandleExportFileWithHttpInfo(namespace, file, file.export, ...)
      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
      }
    },

    HandleExportFileWithHttpInfo = function(namespace, file, file.export, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

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

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

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

      urlPath <- "/files/{namespace}/{file}/export"
      if (!missing(`namespace`)) {
        urlPath <- gsub(paste0("\\{", "namespace", "\\}"), URLencode(as.character(`namespace`), reserved = TRUE), urlPath)
      }

      if (!missing(`file`)) {
        urlPath <- gsub(paste0("\\{", "file", "\\}"), URLencode(as.character(`file`), 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, "FileExported", 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.