# 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 Store operations
#' @description petstore.Store
#' @format An \code{R6Class} generator object
#' @field api_client Handles the client-server communication.
#'
#' @section Methods:
#' \describe{
#' \strong{ DeleteOrder } \emph{ Delete purchase order by ID }
#' For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
#'
#' \itemize{
#' \item \emph{ @param } order.id character
#'
#'
#' \item status code : 400 | Invalid ID supplied
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | Order not found
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ GetInventory } \emph{ Returns pet inventories by status }
#' Returns a map of status codes to quantities
#'
#' \itemize{
#'
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : map(integer)
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ GetOrderById } \emph{ Find purchase order by ID }
#' For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
#'
#' \itemize{
#' \item \emph{ @param } order.id integer
#' \item \emph{ @returnType } \link{Order} \cr
#'
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : Order
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Invalid ID supplied
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | Order not found
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ PlaceOrder } \emph{ Place an order for a pet }
#'
#'
#' \itemize{
#' \item \emph{ @param } body \link{Order}
#' \item \emph{ @returnType } \link{Order} \cr
#'
#'
#' \item status code : 200 | successful operation
#'
#' \item return type : Order
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Invalid Order
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' }
#'
#'
#' @examples
#' \dontrun{
#' #################### DeleteOrder ####################
#'
#' library(petstore)
#' var.order.id <- 'order.id_example' # character | ID of the order that needs to be deleted
#'
#' #Delete purchase order by ID
#' api.instance <- StoreApi$new()
#'
#' result <- api.instance$DeleteOrder(var.order.id)
#'
#'
#' #################### GetInventory ####################
#'
#' library(petstore)
#'
#' #Returns pet inventories by status
#' api.instance <- StoreApi$new()
#'
#' #Configure API key authorization: api_key
#' api.instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY';
#'
#' result <- api.instance$GetInventory()
#'
#'
#' #################### GetOrderById ####################
#'
#' library(petstore)
#' var.order.id <- 56 # integer | ID of pet that needs to be fetched
#'
#' #Find purchase order by ID
#' api.instance <- StoreApi$new()
#'
#' result <- api.instance$GetOrderById(var.order.id)
#'
#'
#' #################### PlaceOrder ####################
#'
#' library(petstore)
#' var.body <- Order$new() # Order | order placed for purchasing the pet
#'
#' #Place an order for a pet
#' api.instance <- StoreApi$new()
#'
#' result <- api.instance$PlaceOrder(var.body)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom base64enc base64encode
#' @export
StoreApi <- R6::R6Class(
'StoreApi',
public = list(
api_client = NULL,
initialize = function(api_client) {
if (!missing(api_client)) {
self$api_client <- api_client
}
else {
self$api_client <- ApiClient$new()
}
},
DeleteOrder = function(order.id, ...) {
api_response <- self$DeleteOrderWithHttpInfo(order.id, ...)
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
}
},
DeleteOrderWithHttpInfo = function(order.id, ...) {
args <- list(...)
query_params <- list()
header_params <- c()
if (missing(`order.id`)) {
stop("Missing required parameter `order.id`.")
}
body <- NULL
url_path <- "/store/order/{orderId}"
if (!missing(`order.id`)) {
url_path <- gsub(paste0("\\{", "orderId", "\\}"), URLencode(as.character(`order.id`), 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)
}
},
GetInventory = function(data_file=NULL, ...) {
api_response <- self$GetInventoryWithHttpInfo(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
}
},
GetInventoryWithHttpInfo = function(data_file=NULL, ...) {
args <- list(...)
query_params <- list()
header_params <- c()
body <- NULL
url_path <- "/store/inventory"
# API key authentication
if ("api_key" %in% names(self$api_client$api_keys) && nchar(self$api_client$api_keys["api_key"]) > 0) {
header_params['api_key'] <- paste(unlist(self$api_client$api_keys["api_key"]), collapse='')
}
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, "map(integer)", 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)
}
},
GetOrderById = function(order.id, data_file=NULL, ...) {
api_response <- self$GetOrderByIdWithHttpInfo(order.id, 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
}
},
GetOrderByIdWithHttpInfo = function(order.id, data_file=NULL, ...) {
args <- list(...)
query_params <- list()
header_params <- c()
if (missing(`order.id`)) {
stop("Missing required parameter `order.id`.")
}
body <- NULL
url_path <- "/store/order/{orderId}"
if (!missing(`order.id`)) {
url_path <- gsub(paste0("\\{", "orderId", "\\}"), URLencode(as.character(`order.id`), 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, "Order", 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)
}
},
PlaceOrder = function(body, data_file=NULL, ...) {
api_response <- self$PlaceOrderWithHttpInfo(body, 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
}
},
PlaceOrderWithHttpInfo = function(body, data_file=NULL, ...) {
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 <- "/store/order"
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) {
# 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, "Order", 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)
}
}
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.