@@ -239,11 +239,11 @@ BodyApi <- R6::R6Class(
239239 if (local_var_resp $ status_code > = 200 && local_var_resp $ status_code < = 299 ) {
240240 # save response in a file
241241 if (! is.null(data_file )) {
242- private $ WriteFile(local_var_resp $ response , data_file , local_var_accepts )
242+ private $ WriteFile(local_var_resp , data_file )
243243 }
244244
245245 deserialized_resp_obj <- tryCatch(
246- private $ Deserialize(local_var_resp ),
246+ private $ Deserialize(local_var_resp , " data.frame " ),
247247 error = function (e ) {
248248 stop(" Failed to deserialize response" )
249249 }
@@ -336,11 +336,11 @@ BodyApi <- R6::R6Class(
336336 if (local_var_resp $ status_code > = 200 && local_var_resp $ status_code < = 299 ) {
337337 # save response in a file
338338 if (! is.null(data_file )) {
339- private $ WriteFile(local_var_resp $ response , data_file , local_var_accepts )
339+ private $ WriteFile(local_var_resp , data_file )
340340 }
341341
342342 deserialized_resp_obj <- tryCatch(
343- private $ Deserialize(local_var_resp ),
343+ private $ Deserialize(local_var_resp , " character " ),
344344 error = function (e ) {
345345 stop(" Failed to deserialize response" )
346346 }
@@ -432,11 +432,11 @@ BodyApi <- R6::R6Class(
432432 if (local_var_resp $ status_code > = 200 && local_var_resp $ status_code < = 299 ) {
433433 # save response in a file
434434 if (! is.null(data_file )) {
435- private $ WriteFile(local_var_resp $ response , data_file , local_var_accepts )
435+ private $ WriteFile(local_var_resp , data_file )
436436 }
437437
438438 deserialized_resp_obj <- tryCatch(
439- private $ Deserialize(local_var_resp ),
439+ private $ Deserialize(local_var_resp , " character " ),
440440 error = function (e ) {
441441 stop(" Failed to deserialize response" )
442442 }
@@ -524,11 +524,11 @@ BodyApi <- R6::R6Class(
524524 if (local_var_resp $ status_code > = 200 && local_var_resp $ status_code < = 299 ) {
525525 # save response in a file
526526 if (! is.null(data_file )) {
527- private $ WriteFile(local_var_resp $ response , data_file , local_var_accepts )
527+ private $ WriteFile(local_var_resp , data_file )
528528 }
529529
530530 deserialized_resp_obj <- tryCatch(
531- private $ Deserialize(local_var_resp ),
531+ private $ Deserialize(local_var_resp , " character " ),
532532 error = function (e ) {
533533 stop(" Failed to deserialize response" )
534534 }
@@ -621,11 +621,11 @@ BodyApi <- R6::R6Class(
621621 if (local_var_resp $ status_code > = 200 && local_var_resp $ status_code < = 299 ) {
622622 # save response in a file
623623 if (! is.null(data_file )) {
624- private $ WriteFile(local_var_resp $ response , data_file , local_var_accepts )
624+ private $ WriteFile(local_var_resp , data_file )
625625 }
626626
627627 deserialized_resp_obj <- tryCatch(
628- private $ Deserialize(local_var_resp ),
628+ private $ Deserialize(local_var_resp , " Pet " ),
629629 error = function (e ) {
630630 stop(" Failed to deserialize response" )
631631 }
@@ -718,11 +718,11 @@ BodyApi <- R6::R6Class(
718718 if (local_var_resp $ status_code > = 200 && local_var_resp $ status_code < = 299 ) {
719719 # save response in a file
720720 if (! is.null(data_file )) {
721- private $ WriteFile(local_var_resp $ response , data_file , local_var_accepts )
721+ private $ WriteFile(local_var_resp , data_file )
722722 }
723723
724724 deserialized_resp_obj <- tryCatch(
725- private $ Deserialize(local_var_resp ),
725+ private $ Deserialize(local_var_resp , " character " ),
726726 error = function (e ) {
727727 stop(" Failed to deserialize response" )
728728 }
@@ -815,11 +815,11 @@ BodyApi <- R6::R6Class(
815815 if (local_var_resp $ status_code > = 200 && local_var_resp $ status_code < = 299 ) {
816816 # save response in a file
817817 if (! is.null(data_file )) {
818- private $ WriteFile(local_var_resp $ response , data_file , local_var_accepts )
818+ private $ WriteFile(local_var_resp , data_file )
819819 }
820820
821821 deserialized_resp_obj <- tryCatch(
822- private $ Deserialize(local_var_resp ),
822+ private $ Deserialize(local_var_resp , " Pet " ),
823823 error = function (e ) {
824824 stop(" Failed to deserialize response" )
825825 }
@@ -912,11 +912,11 @@ BodyApi <- R6::R6Class(
912912 if (local_var_resp $ status_code > = 200 && local_var_resp $ status_code < = 299 ) {
913913 # save response in a file
914914 if (! is.null(data_file )) {
915- private $ WriteFile(local_var_resp $ response , data_file , local_var_accepts )
915+ private $ WriteFile(local_var_resp , data_file )
916916 }
917917
918918 deserialized_resp_obj <- tryCatch(
919- private $ Deserialize(local_var_resp ),
919+ private $ Deserialize(local_var_resp , " character " ),
920920 error = function (e ) {
921921 stop(" Failed to deserialize response" )
922922 }
@@ -1009,11 +1009,11 @@ BodyApi <- R6::R6Class(
10091009 if (local_var_resp $ status_code > = 200 && local_var_resp $ status_code < = 299 ) {
10101010 # save response in a file
10111011 if (! is.null(data_file )) {
1012- private $ WriteFile(local_var_resp $ response , data_file , local_var_accepts )
1012+ private $ WriteFile(local_var_resp , data_file )
10131013 }
10141014
10151015 deserialized_resp_obj <- tryCatch(
1016- private $ Deserialize(local_var_resp ),
1016+ private $ Deserialize(local_var_resp , " StringEnumRef " ),
10171017 error = function (e ) {
10181018 stop(" Failed to deserialize response" )
10191019 }
@@ -1106,11 +1106,11 @@ BodyApi <- R6::R6Class(
11061106 if (local_var_resp $ status_code > = 200 && local_var_resp $ status_code < = 299 ) {
11071107 # save response in a file
11081108 if (! is.null(data_file )) {
1109- private $ WriteFile(local_var_resp $ response , data_file , local_var_accepts )
1109+ private $ WriteFile(local_var_resp , data_file )
11101110 }
11111111
11121112 deserialized_resp_obj <- tryCatch(
1113- private $ Deserialize(local_var_resp ),
1113+ private $ Deserialize(local_var_resp , " character " ),
11141114 error = function (e ) {
11151115 stop(" Failed to deserialize response" )
11161116 }
@@ -1130,24 +1130,50 @@ BodyApi <- R6::R6Class(
11301130 }
11311131 ),
11321132 private = list (
1133- WriteFile = function (x , file , accepts ) {
1134- if (private $ IsBinary(accepts )) {
1135- writeBin(x , file )
1133+ # ' @description
1134+ # ' Write response to a file
1135+ # '
1136+ # ' The function will write out data.
1137+ # '
1138+ # ' 1. If binary data is detected it will use `writeBin`
1139+ # ' 2. If the raw response is coercable to text, the text will be written to a file
1140+ # ' 3. If the raw response is not coercable to text, the raw response will be written
1141+ # '
1142+ # ' @param local_var_resp The API response
1143+ # ' @param file The name of the data file to save the result
1144+ WriteFile = function (local_var_resp , file ) {
1145+ if (private $ IsBinary(local_var_resp $ response )) {
1146+ writeBin(local_var_resp $ response , file )
11361147 } else {
1137- base :: write(x , file )
1148+ response <- private $ Deserialize(local_var_resp )
1149+ base :: write(response , file )
11381150 }
11391151 },
11401152
1141- IsBinary = function (accepts ) {
1142- return (any(grepl(" gzip" , as.character(accepts ))))
1153+ # ' @description
1154+ # ' Check response for binary content
1155+ # '
1156+ # ' @param local_var_resp The API response
1157+ IsBinary = function (x ) {
1158+ # ref: https://stackoverflow.com/a/17098690/1785752
1159+ b <- readBin(x , " int" , n = 1000 , size = 1 , signed = FALSE )
1160+ return (max(b ) > 128 )
11431161 },
11441162
1145- Deserialize = function (local_var_resp ) {
1163+ # ' @description
1164+ # ' Deserialize the response
1165+ # '
1166+ # ' @param local_var_resp The API response
1167+ # ' @param return_type The target return type for the endpoint (e.g., `"object"`). If `NULL` text will be left as-is.
1168+ # ' @return If the raw response is corecable to text, return the text. Otherwise return the raw resposne.
1169+ Deserialize = function (local_var_resp , return_type = NULL ) {
11461170 text <- local_var_resp $ response_as_text()
11471171 if (is.na(text )) {
11481172 return (local_var_resp $ response )
1173+ } else if (is.null(return_type )) {
1174+ return (text )
11491175 }
1150- return (self $ api_client $ deserialize(text , " object " , loadNamespace(" k8s.client " )))
1176+ return (self $ api_client $ deserialize(text , return_type , loadNamespace(" openapi " )))
11511177 }
11521178 )
11531179)
0 commit comments