update samples

This commit is contained in:
William Cheng
2024-01-23 16:52:00 +08:00
parent 0357a1b1dd
commit 90bd1f361b
8 changed files with 41 additions and 24 deletions

View File

@@ -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)
}
)
)