forked from loafle/openapi-generator-original
update samples
This commit is contained in:
@@ -45,6 +45,23 @@ ApiResponse <- R6::R6Class(
|
||||
self$status_code <- status_code
|
||||
self$status_code_desc <- status_code_desc
|
||||
self$headers <- headers
|
||||
},
|
||||
|
||||
#' Return the response as text
|
||||
#'
|
||||
#' @description
|
||||
#' The response is stored as a raw vector. Use this to access the response after
|
||||
#' converting it to text. If the response is not coercible to text NA is returned.
|
||||
#'
|
||||
#' @param from_encoding The encoding of the raw response.
|
||||
#' @param to_encoding The target encoding of the return value.
|
||||
#' @export
|
||||
response_as_text = function(from_encoding = NULL, to_encoding = "UTF-8") {
|
||||
text_response <- iconv(readBin(self$response, character()), from = from_encoding, to = to_encoding)
|
||||
if (is.na(text_response)) {
|
||||
warning("The response is binary and will not be converted to text.")
|
||||
}
|
||||
return(text_response)
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user