R/openapi/feature_api.R

#' Jaqpot API
#'
#' A modern RESTful API for model management and prediction services, built using Spring Boot and Kotlin. Supports seamless integration with machine learning workflows.
#'
#' The version of the OpenAPI document: 1.0.0
#' Contact: upci.ntua@gmail.com
#' Generated by: https://openapi-generator.tech
#'
#' @docType class
#' @title Feature operations
#' @description FeatureApi
#' @format An \code{R6Class} generator object
#' @field api_client Handles the client-server communication.
#'
#' @examples
#' \dontrun{
#' ####################  PartiallyUpdateModelFeature  ####################
#'
#' library(openapi)
#' var_model_id <- 56 # integer | The ID of the model containing the feature
#' var_feature_id <- 56 # integer | The ID of the feature to update
#' var_partially_update_model_feature_request <- partiallyUpdateModelFeature_request$new("name_example", FeatureType$new(), "units_example", "range_example", "description_example", c(FeaturePossibleValue$new("key_example", "value_example"))) # PartiallyUpdateModelFeatureRequest | 
#'
#' #Update a feature for a specific model
#' api_instance <- FeatureApi$new()
#'
#' # Configure HTTP bearer authorization: bearerAuth
#' api_instance$api_client$bearer_token <- Sys.getenv("BEARER_TOKEN")
#'
#' # to save the result into a file, simply add the optional `data_file` parameter, e.g.
#' # result <- api_instance$PartiallyUpdateModelFeature(var_model_id, var_feature_id, var_partially_update_model_feature_requestdata_file = "result.txt")
#' result <- api_instance$PartiallyUpdateModelFeature(var_model_id, var_feature_id, var_partially_update_model_feature_request)
#' dput(result)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom base64enc base64encode
#' @keywords internal
FeatureApi <- R6::R6Class(
  "FeatureApi",
  public = list(
    api_client = NULL,

    #' @description
    #' Initialize a new FeatureApi.
    #'
    #' @param api_client An instance of API client.
    initialize = function(api_client) {
      if (!missing(api_client)) {
        self$api_client <- api_client
      } else {
        self$api_client <- ApiClient$new()
      }
    },

    #' @description
    #' Update a feature for a specific model
    #'
    #' @param model_id The ID of the model containing the feature
    #' @param feature_id The ID of the feature to update
    #' @param partially_update_model_feature_request 
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #'
    #' @return Feature
    PartiallyUpdateModelFeature = function(model_id, feature_id, partially_update_model_feature_request, data_file = NULL, ...) {
      local_var_response <- self$PartiallyUpdateModelFeatureWithHttpInfo(model_id, feature_id, partially_update_model_feature_request, data_file = data_file, ...)
      if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) {
        local_var_response$content
      } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) {
        local_var_response
      } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) {
        local_var_response
      } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) {
        local_var_response
      }
    },

    #' @description
    #' Update a feature for a specific model
    #'
    #' @param model_id The ID of the model containing the feature
    #' @param feature_id The ID of the feature to update
    #' @param partially_update_model_feature_request 
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #'
    #' @return API response (Feature) with additional information such as HTTP status code, headers
    PartiallyUpdateModelFeatureWithHttpInfo = function(model_id, feature_id, partially_update_model_feature_request, data_file = NULL, ...) {
      args <- list(...)
      query_params <- list()
      header_params <- c()
      form_params <- list()
      file_params <- list()
      local_var_body <- NULL
      oauth_scopes <- NULL
      is_oauth <- FALSE

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

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

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




      if (!is.null(`partially_update_model_feature_request`)) {
        local_var_body <- `partially_update_model_feature_request`$toJSONString()
      } else {
        body <- NULL
      }

      local_var_url_path <- "/v1/models/{modelId}/features/{featureId}"
      if (!missing(`model_id`)) {
        local_var_url_path <- gsub("\\{modelId\\}", URLencode(as.character(`model_id`), reserved = TRUE), local_var_url_path)
      }

      if (!missing(`feature_id`)) {
        local_var_url_path <- gsub("\\{featureId\\}", URLencode(as.character(`feature_id`), reserved = TRUE), local_var_url_path)
      }

      # Bearer token
      if (!is.null(self$api_client$bearer_token)) {
        header_params["Authorization"] <- paste("Bearer", self$api_client$bearer_token, sep = " ")
      }

      # The Accept request HTTP header
      local_var_accepts <- list("application/json")

      # The Content-Type representation header
      local_var_content_types <- list("application/json")

      local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path),
                                 method = "PATCH",
                                 query_params = query_params,
                                 header_params = header_params,
                                 form_params = form_params,
                                 file_params = file_params,
                                 accepts = local_var_accepts,
                                 content_types = local_var_content_types,
                                 body = local_var_body,
                                 is_oauth = is_oauth,
                                 oauth_scopes = oauth_scopes,
                                 ...)

      if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) {
        # save response in a file
        if (!is.null(data_file)) {
          write(local_var_resp$response, data_file)
        }

        deserialized_resp_obj <- tryCatch(
          self$api_client$deserialize(local_var_resp$response_as_text(), "Feature", loadNamespace("openapi")),
          error = function(e) {
            stop("Failed to deserialize response")
          }
        )
        local_var_resp$content <- deserialized_resp_obj
        local_var_resp
      } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
        ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
      } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
        ApiResponse$new("API client error", local_var_resp)
      } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) {
        if (is.null(local_var_resp$response) || local_var_resp$response == "") {
          local_var_resp$response <- "API server error"
        }
        local_var_resp
      }
    }
  )
)
KinkyDesign/jaqpotr documentation built on Nov. 27, 2024, 1:20 a.m.