R/user_api.R

# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# The version of the OpenAPI document: 1.0.0
# Generated by: https://openapi-generator.tech

#' @docType class
#' @title User operations
#' @description petstore.User
#' @format An \code{R6Class} generator object
#' @field api_client Handles the client-server communication.
#'
#' @section Methods:
#' \describe{
#' \strong{ CreateUser } \emph{ Create user }
#' This can only be done by the logged in user.
#'
#' \itemize{
#' \item \emph{ @param } body \link{User}
#'
#'
#' \item status code : 0 | successful operation
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ CreateUsersWithArrayInput } \emph{ Creates list of users with given input array }
#' 
#'
#' \itemize{
#' \item \emph{ @param } body list( \link{User} )
#'
#'
#' \item status code : 0 | successful operation
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ CreateUsersWithListInput } \emph{ Creates list of users with given input array }
#' 
#'
#' \itemize{
#' \item \emph{ @param } body list( \link{User} )
#'
#'
#' \item status code : 0 | successful operation
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ DeleteUser } \emph{ Delete user }
#' This can only be done by the logged in user.
#'
#' \itemize{
#' \item \emph{ @param } username character
#'
#'
#' \item status code : 400 | Invalid username supplied
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | User not found
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ GetUserByName } \emph{ Get user by user name }
#' 
#'
#' \itemize{
#' \item \emph{ @param } username character
#' \item \emph{ @returnType } \link{User} \cr
#'
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : User 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Invalid username supplied
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | User not found
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ LoginUser } \emph{ Logs user into the system }
#' 
#'
#' \itemize{
#' \item \emph{ @param } username character
#' \item \emph{ @param } password character
#'
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : character 
#' \item response headers :
#'
#' \tabular{ll}{
#' X-Rate-Limit \tab calls per hour allowed by the user \cr
#' X-Expires-After \tab date in UTC when token expires \cr
#' }
#' \item status code : 400 | Invalid username/password supplied
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ LogoutUser } \emph{ Logs out current logged in user session }
#' 
#'
#' \itemize{
#'
#'
#' \item status code : 0 | successful operation
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ UpdateUser } \emph{ Updated user }
#' This can only be done by the logged in user.
#'
#' \itemize{
#' \item \emph{ @param } username character
#' \item \emph{ @param } body \link{User}
#'
#'
#' \item status code : 400 | Invalid user supplied
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | User not found
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' }
#'
#'
#' @examples
#' \dontrun{
#' ####################  CreateUser  ####################
#'
#' library(petstore)
#' var.body <- User$new() # User | Created user object
#'
#' #Create user
#' api.instance <- UserApi$new()
#'
#' result <- api.instance$CreateUser(var.body)
#'
#'
#' ####################  CreateUsersWithArrayInput  ####################
#'
#' library(petstore)
#' var.body <- [User$new()] # array[User] | List of user object
#'
#' #Creates list of users with given input array
#' api.instance <- UserApi$new()
#'
#' result <- api.instance$CreateUsersWithArrayInput(var.body)
#'
#'
#' ####################  CreateUsersWithListInput  ####################
#'
#' library(petstore)
#' var.body <- [User$new()] # array[User] | List of user object
#'
#' #Creates list of users with given input array
#' api.instance <- UserApi$new()
#'
#' result <- api.instance$CreateUsersWithListInput(var.body)
#'
#'
#' ####################  DeleteUser  ####################
#'
#' library(petstore)
#' var.username <- 'username_example' # character | The name that needs to be deleted
#'
#' #Delete user
#' api.instance <- UserApi$new()
#'
#' result <- api.instance$DeleteUser(var.username)
#'
#'
#' ####################  GetUserByName  ####################
#'
#' library(petstore)
#' var.username <- 'username_example' # character | The name that needs to be fetched. Use user1 for testing.
#'
#' #Get user by user name
#' api.instance <- UserApi$new()
#'
#' result <- api.instance$GetUserByName(var.username)
#'
#'
#' ####################  LoginUser  ####################
#'
#' library(petstore)
#' var.username <- 'username_example' # character | The user name for login
#' var.password <- 'password_example' # character | The password for login in clear text
#'
#' #Logs user into the system
#' api.instance <- UserApi$new()
#'
#' result <- api.instance$LoginUser(var.username, var.password)
#'
#'
#' ####################  LogoutUser  ####################
#'
#' library(petstore)
#'
#' #Logs out current logged in user session
#' api.instance <- UserApi$new()
#'
#' result <- api.instance$LogoutUser()
#'
#'
#' ####################  UpdateUser  ####################
#'
#' library(petstore)
#' var.username <- 'username_example' # character | name that need to be deleted
#' var.body <- User$new() # User | Updated user object
#'
#' #Updated user
#' api.instance <- UserApi$new()
#'
#' result <- api.instance$UpdateUser(var.username, var.body)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom base64enc base64encode
#' @export
UserApi <- R6::R6Class(
  'UserApi',
  public = list(
    api_client = NULL,
    initialize = function(api_client) {
      if (!missing(api_client)) {
        self$api_client <- api_client
      }
      else {
        self$api_client <- ApiClient$new()
      }
    },
    CreateUser = function(body, ...) {
      api_response <- self$CreateUserWithHttpInfo(body, ...)
      resp <- api_response$response
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        api_response$content
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        api_response
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        api_response
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        api_response
      }
    },

    CreateUserWithHttpInfo = function(body, ...) {
      args <- list(...)
      query_params <- list()
      header_params <- c()

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

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

      url_path <- "/user"

      resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
                                 method = "POST",
                                 query_params = query_params,
                                 header_params = header_params,
                                 body = body,
                                 ...)

      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        ApiResponse$new(NULL, 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)
      }
    },
    CreateUsersWithArrayInput = function(body, ...) {
      api_response <- self$CreateUsersWithArrayInputWithHttpInfo(body, ...)
      resp <- api_response$response
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        api_response$content
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        api_response
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        api_response
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        api_response
      }
    },

    CreateUsersWithArrayInputWithHttpInfo = function(body, ...) {
      args <- list(...)
      query_params <- list()
      header_params <- c()

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

      if (!missing(`body`)) {
        body.items = paste(unlist(lapply(body, function(param) {param$toJSONString()})), collapse = ",")
        body <- paste0('[', body.items, ']')
      } else {
        body <- NULL
      }

      url_path <- "/user/createWithArray"

      resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
                                 method = "POST",
                                 query_params = query_params,
                                 header_params = header_params,
                                 body = body,
                                 ...)

      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        ApiResponse$new(NULL, 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)
      }
    },
    CreateUsersWithListInput = function(body, ...) {
      api_response <- self$CreateUsersWithListInputWithHttpInfo(body, ...)
      resp <- api_response$response
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        api_response$content
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        api_response
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        api_response
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        api_response
      }
    },

    CreateUsersWithListInputWithHttpInfo = function(body, ...) {
      args <- list(...)
      query_params <- list()
      header_params <- c()

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

      if (!missing(`body`)) {
        body.items = paste(unlist(lapply(body, function(param) {param$toJSONString()})), collapse = ",")
        body <- paste0('[', body.items, ']')
      } else {
        body <- NULL
      }

      url_path <- "/user/createWithList"

      resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
                                 method = "POST",
                                 query_params = query_params,
                                 header_params = header_params,
                                 body = body,
                                 ...)

      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        ApiResponse$new(NULL, 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)
      }
    },
    DeleteUser = function(username, ...) {
      api_response <- self$DeleteUserWithHttpInfo(username, ...)
      resp <- api_response$response
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        api_response$content
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        api_response
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        api_response
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        api_response
      }
    },

    DeleteUserWithHttpInfo = function(username, ...) {
      args <- list(...)
      query_params <- list()
      header_params <- c()

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

      body <- NULL
      url_path <- "/user/{username}"
      if (!missing(`username`)) {
        url_path <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), url_path)
      }


      resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
                                 method = "DELETE",
                                 query_params = query_params,
                                 header_params = header_params,
                                 body = body,
                                 ...)

      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        ApiResponse$new(NULL, 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)
      }
    },
    GetUserByName = function(username, data_file=NULL, ...) {
      api_response <- self$GetUserByNameWithHttpInfo(username, data_file=data_file, ...)
      resp <- api_response$response
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        api_response$content
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        api_response
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        api_response
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        api_response
      }
    },

    GetUserByNameWithHttpInfo = function(username, data_file=NULL, ...) {
      args <- list(...)
      query_params <- list()
      header_params <- c()

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

      body <- NULL
      url_path <- "/user/{username}"
      if (!missing(`username`)) {
        url_path <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), url_path)
      }


      resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
                                 method = "GET",
                                 query_params = query_params,
                                 header_params = header_params,
                                 body = body,
                                 ...)

      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        # save response in a file
        if (!is.null(data_file)) {
            write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file)
        }

        deserializedRespObj <- tryCatch(
          self$api_client$deserialize(resp, "User", loadNamespace("petstore")),
          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)
      }
    },
    LoginUser = function(username, password, data_file=NULL, ...) {
      api_response <- self$LoginUserWithHttpInfo(username, password, data_file=data_file, ...)
      resp <- api_response$response
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        api_response$content
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        api_response
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        api_response
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        api_response
      }
    },

    LoginUserWithHttpInfo = function(username, password, data_file=NULL, ...) {
      args <- list(...)
      query_params <- list()
      header_params <- c()

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

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

      body <- NULL
      url_path <- "/user/login"

      resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
                                 method = "GET",
                                 query_params = query_params,
                                 header_params = header_params,
                                 body = body,
                                 ...)

      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        # save response in a file
        if (!is.null(data_file)) {
            write(httr::content(resp, "text", encoding = "UTF-8", simplifyVector = FALSE), data_file)
        }

        deserializedRespObj <- tryCatch(
          self$api_client$deserialize(resp, "character", loadNamespace("petstore")),
          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)
      }
    },
    LogoutUser = function(...) {
      api_response <- self$LogoutUserWithHttpInfo(...)
      resp <- api_response$response
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        api_response$content
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        api_response
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        api_response
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        api_response
      }
    },

    LogoutUserWithHttpInfo = function(...) {
      args <- list(...)
      query_params <- list()
      header_params <- c()

      body <- NULL
      url_path <- "/user/logout"

      resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
                                 method = "GET",
                                 query_params = query_params,
                                 header_params = header_params,
                                 body = body,
                                 ...)

      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        ApiResponse$new(NULL, 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)
      }
    },
    UpdateUser = function(username, body, ...) {
      api_response <- self$UpdateUserWithHttpInfo(username, body, ...)
      resp <- api_response$response
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        api_response$content
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        api_response
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        api_response
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        api_response
      }
    },

    UpdateUserWithHttpInfo = function(username, body, ...) {
      args <- list(...)
      query_params <- list()
      header_params <- c()

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

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

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

      url_path <- "/user/{username}"
      if (!missing(`username`)) {
        url_path <- gsub(paste0("\\{", "username", "\\}"), URLencode(as.character(`username`), reserved = TRUE), url_path)
      }


      resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, url_path),
                                 method = "PUT",
                                 query_params = query_params,
                                 header_params = header_params,
                                 body = body,
                                 ...)

      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        ApiResponse$new(NULL, 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)
      }
    }
  )
)
wing328/petstore-r-client documentation built on June 2, 2022, 10:24 a.m.